FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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