OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "Istream.H"
00028 #include "cell.H"
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 inline Foam::cellShape::cellShape()
00033 :
00034     m(NULL)
00035 {}
00036 
00037 
00038 inline Foam::cellShape::cellShape
00039 (
00040     const cellModel& M,
00041     const labelList& l,
00042     const bool doCollapse
00043 )
00044 :
00045     labelList(l),
00046     m(&M)
00047 {
00048     if (doCollapse)
00049     {
00050         collapse();
00051     }
00052 }
00053 
00054 
00055 inline Foam::cellShape::cellShape(Istream& is)
00056 {
00057     is >> *this;
00058 }
00059 
00060 
00061 inline Foam::autoPtr<Foam::cellShape> Foam::cellShape::clone() const
00062 {
00063     return autoPtr<cellShape>(new cellShape(*this));
00064 }
00065 
00066 
00067 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00068 
00069 inline Foam::pointField Foam::cellShape::points
00070 (
00071     const pointField& meshPoints
00072 ) const
00073 {
00074     // There are as many points as there labels for them
00075     pointField p(size());
00076 
00077     // For each point in list, set it to the point in 'pnts' addressed
00078     // by 'labs'
00079     forAll(p, i)
00080     {
00081         p[i] = meshPoints[operator[](i)];
00082     }
00083 
00084     // Return list
00085     return p;
00086 }
00087 
00088 
00089 inline const Foam::cellModel& Foam::cellShape::model() const
00090 {
00091     return *m;
00092 }
00093 
00094 
00095 inline Foam::labelList Foam::cellShape::meshFaces
00096 (
00097     const faceList& allFaces,
00098     const cell& cFaces
00099 ) const
00100 {
00101     // Faces in model order
00102     faceList localFaces(faces());
00103 
00104     // Do linear match (usually cell shape is low complexity)
00105 
00106     labelList modelToMesh(localFaces.size(), -1);
00107 
00108     forAll(localFaces, i)
00109     {
00110         const face& localF = localFaces[i];
00111 
00112         forAll(cFaces, j)
00113         {
00114             label meshFaceI = cFaces[j];
00115 
00116             if (allFaces[meshFaceI] == localF)
00117             {
00118                 modelToMesh[i] = meshFaceI;
00119 
00120                 break;
00121             }
00122         }
00123     }
00124 
00125     return modelToMesh;
00126 }
00127 
00128 
00129 inline Foam::labelList Foam::cellShape::meshEdges
00130 (
00131     const edgeList& allEdges,
00132     const labelList& cEdges
00133 ) const
00134 {
00135     // Edges in model order
00136     edgeList localEdges(edges());
00137 
00138     // Do linear match (usually cell shape is low complexity)
00139 
00140     labelList modelToMesh(localEdges.size(), -1);
00141 
00142     forAll(localEdges, i)
00143     {
00144         const edge& e = localEdges[i];
00145 
00146         forAll(cEdges, j)
00147         {
00148             label edgeI = cEdges[j];
00149 
00150             if (allEdges[edgeI] == e)
00151             {
00152                 modelToMesh[i] = edgeI;
00153 
00154                 break;
00155             }
00156         }
00157     }
00158 
00159     return modelToMesh;
00160 }
00161 
00162 
00163 inline Foam::faceList Foam::cellShape::faces() const
00164 {
00165     return m->faces(*this);
00166 }
00167 
00168 
00169 inline Foam::faceList Foam::cellShape::collapsedFaces() const
00170 {
00171     faceList oldFaces(faces());
00172 
00173     faceList newFaces(oldFaces.size());
00174     label newFaceI = 0;
00175 
00176     forAll(oldFaces, oldFaceI)
00177     {
00178         const face& f = oldFaces[oldFaceI];
00179 
00180         face& newF = newFaces[newFaceI];
00181 
00182         newF.setSize(f.size());
00183 
00184         label newFp = 0;
00185         label prevVertI = -1;
00186 
00187         forAll(f, fp)
00188         {
00189             label vertI = f[fp];
00190 
00191             if (vertI != prevVertI)
00192             {
00193                 newF[newFp++] = vertI;
00194 
00195                 prevVertI = vertI;
00196             }
00197         }
00198 
00199         if ((newFp > 1) && (newF[newFp-1] == newF[0]))
00200         {
00201             --newFp;
00202         }
00203 
00204         if (newFp > 2)
00205         {
00206             // Size face and go to next one
00207             newF.setSize(newFp);
00208 
00209             newFaceI++;
00210         }
00211     }
00212     newFaces.setSize(newFaceI);
00213 
00214     return newFaces;    
00215 }
00216 
00217 
00218 inline Foam::label Foam::cellShape::nFaces() const
00219 {
00220     return m->nFaces();
00221 }
00222 
00223 
00224 inline Foam::edgeList Foam::cellShape::edges() const
00225 {
00226     return m->edges(*this);
00227 }
00228 
00229 
00230 inline Foam::label Foam::cellShape::nEdges() const
00231 {
00232     return m->nEdges();
00233 }
00234 
00235 
00236 inline Foam::label Foam::cellShape::nPoints() const
00237 {
00238     return size();
00239 }
00240 
00241 
00242 inline Foam::point Foam::cellShape::centre(const pointField& points) const
00243 {
00244     return m->centre(*this, points);
00245 }
00246 
00247 
00248 inline Foam::scalar Foam::cellShape::mag(const pointField& points) const
00249 {
00250     return m->mag(*this, points);
00251 }
00252 
00253 
00254 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd