OpenFOAM logo
Open Source CFD Toolkit

cellShapeI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "cellShapeList.H"
00030 #include "IOstreams.H"
00031 #include "cell.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 // Construct null
00041 inline cellShape::cellShape()
00042 :
00043     m(NULL)
00044 {}
00045 
00046 
00047 // Construct from components
00048 inline cellShape::cellShape
00049 (
00050     const cellModel& M,
00051     const labelList& l,
00052     const bool doCollapse
00053 )
00054 :
00055     labelList(l),
00056     m(&M)
00057 {
00058     if (doCollapse)
00059     {
00060         collapse();
00061     }
00062 }
00063 
00064 
00065 // Construct from Istream
00066 inline cellShape::cellShape(Istream& is)
00067 {
00068     is >> *this;
00069 }
00070 
00071 
00072 // Clone
00073 inline autoPtr<cellShape> cellShape::clone() const
00074 {
00075     return autoPtr<cellShape>(new cellShape(*this));
00076 }
00077 
00078 
00079 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00080 
00081 // Return the points associated with this cellShape
00082 inline pointField cellShape::points(const pointField& meshPoints) const
00083 {
00084     // There are as many points as there labels for them
00085     pointField p(size());
00086 
00087     // For each point in list, set it to the point in 'pnts' addressed
00088     // by 'labs'
00089     forAll(p, i)
00090     {
00091         p[i] = meshPoints[operator[](i)];
00092     }
00093 
00094     // Return list
00095     return p;
00096 }
00097 
00098 
00099 // Return model reference
00100 inline const cellModel& cellShape::model() const
00101 {
00102     return *m;
00103 }
00104 
00105 
00106 // Mesh face labels of this cell (in order of model)
00107 inline labelList cellShape::meshFaces
00108 (
00109     const faceList& allFaces,
00110     const cell& cFaces
00111 ) const
00112 {
00113     // Faces in model order
00114     faceList localFaces(faces());
00115 
00116     // Do linear match (usually cell shape is low complexity)
00117 
00118     labelList modelToMesh(localFaces.size(), -1);
00119 
00120     forAll(localFaces, i)
00121     {
00122         const face& localF = localFaces[i];
00123 
00124         forAll(cFaces, j)
00125         {
00126             label meshFaceI = cFaces[j];
00127 
00128             if (allFaces[meshFaceI] == localF)
00129             {
00130                 modelToMesh[i] = meshFaceI;
00131 
00132                 break;
00133             }
00134         }
00135     }
00136 
00137     return modelToMesh;
00138 }
00139 
00140 
00141 // Mesh edge labels of this cell (in order of model)
00142 inline labelList cellShape::meshEdges
00143 (
00144     const edgeList& allEdges,
00145     const labelList& cEdges
00146 ) const
00147 {
00148     // Edges in model order
00149     edgeList localEdges(edges());
00150 
00151     // Do linear match (usually cell shape is low complexity)
00152 
00153     labelList modelToMesh(localEdges.size(), -1);
00154 
00155     forAll(localEdges, i)
00156     {
00157         const edge& e = localEdges[i];
00158 
00159         forAll(cEdges, j)
00160         {
00161             label edgeI = cEdges[j];
00162 
00163             if (allEdges[edgeI] == e)
00164             {
00165                 modelToMesh[i] = edgeI;
00166 
00167                 break;
00168             }
00169         }
00170     }
00171 
00172     return modelToMesh;
00173 }
00174 
00175 
00176 // Return faces of cell
00177 inline faceList cellShape::faces() const
00178 {
00179     return m->faces(*this);
00180 }
00181 
00182 
00183 inline faceList cellShape::collapsedFaces() const
00184 {
00185     faceList oldFaces(faces());
00186 
00187     faceList newFaces(oldFaces.size());
00188     label newFaceI = 0;
00189 
00190     forAll(oldFaces, oldFaceI)
00191     {
00192         const face& f = oldFaces[oldFaceI];
00193 
00194         face& newF = newFaces[newFaceI];
00195 
00196         newF.setSize(f.size());
00197 
00198         label newFp = 0;
00199         label prevVertI = -1;
00200 
00201         forAll(f, fp)
00202         {
00203             label vertI = f[fp];
00204 
00205             if (vertI != prevVertI)
00206             {
00207                 newF[newFp++] = vertI;
00208 
00209                 prevVertI = vertI;
00210             }
00211         }
00212 
00213         if ((newFp > 1) && (newF[newFp-1] == newF[0]))
00214         {
00215             --newFp;
00216         }
00217 
00218         if (newFp > 2)
00219         {
00220             // Size face and go to next one
00221             newF.setSize(newFp);
00222 
00223             newFaceI++;
00224         }
00225     }
00226     newFaces.setSize(newFaceI);
00227 
00228     return newFaces;    
00229 }
00230 
00231 
00232 // Return number of faces
00233 inline label cellShape::nFaces() const
00234 {
00235     return m->nFaces();
00236 }
00237 
00238 
00239 // Return edges of cell
00240 inline edgeList cellShape::edges() const
00241 {
00242     return m->edges(*this);
00243 }
00244 
00245 
00246 // Return number of edges
00247 inline label cellShape::nEdges() const
00248 {
00249     return m->nEdges();
00250 }
00251 
00252 
00253 // Return number of points
00254 inline label cellShape::nPoints() const
00255 {
00256     return size();
00257 }
00258 
00259 
00260 // Centre point of cellShape
00261 inline point cellShape::centre(const pointField& points) const
00262 {
00263     return m->centre(*this, points);
00264 }
00265 
00266 
00267 // Return scalar magnitude
00268 inline scalar cellShape::mag(const pointField& points) const
00269 {
00270     return m->mag(*this, points);
00271 }
00272 
00273 
00274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00275 
00276 } // End namespace Foam
00277 
00278 // ************************************************************************* //
For further information go to www.openfoam.org