initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / cellShape / cellShapeI.H
blob8ecabf826192d556d8889d1c1ca15a0ad27d5162
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "Istream.H"
28 #include "cell.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 inline Foam::cellShape::cellShape()
34     m(NULL)
38 inline Foam::cellShape::cellShape
40     const cellModel& M,
41     const labelList& l,
42     const bool doCollapse
45     labelList(l),
46     m(&M)
48     if (doCollapse)
49     {
50         collapse();
51     }
55 inline Foam::cellShape::cellShape(Istream& is)
57     is >> *this;
61 inline Foam::autoPtr<Foam::cellShape> Foam::cellShape::clone() const
63     return autoPtr<cellShape>(new cellShape(*this));
67 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
69 inline Foam::pointField Foam::cellShape::points
71     const pointField& meshPoints
72 ) const
74     // There are as many points as there labels for them
75     pointField p(size());
77     // For each point in list, set it to the point in 'pnts' addressed
78     // by 'labs'
79     forAll(p, i)
80     {
81         p[i] = meshPoints[operator[](i)];
82     }
84     // Return list
85     return p;
89 inline const Foam::cellModel& Foam::cellShape::model() const
91     return *m;
95 inline Foam::labelList Foam::cellShape::meshFaces
97     const faceList& allFaces,
98     const cell& cFaces
99 ) const
101     // Faces in model order
102     faceList localFaces(faces());
104     // Do linear match (usually cell shape is low complexity)
106     labelList modelToMesh(localFaces.size(), -1);
108     forAll(localFaces, i)
109     {
110         const face& localF = localFaces[i];
112         forAll(cFaces, j)
113         {
114             label meshFaceI = cFaces[j];
116             if (allFaces[meshFaceI] == localF)
117             {
118                 modelToMesh[i] = meshFaceI;
120                 break;
121             }
122         }
123     }
125     return modelToMesh;
129 inline Foam::labelList Foam::cellShape::meshEdges
131     const edgeList& allEdges,
132     const labelList& cEdges
133 ) const
135     // Edges in model order
136     edgeList localEdges(edges());
138     // Do linear match (usually cell shape is low complexity)
140     labelList modelToMesh(localEdges.size(), -1);
142     forAll(localEdges, i)
143     {
144         const edge& e = localEdges[i];
146         forAll(cEdges, j)
147         {
148             label edgeI = cEdges[j];
150             if (allEdges[edgeI] == e)
151             {
152                 modelToMesh[i] = edgeI;
154                 break;
155             }
156         }
157     }
159     return modelToMesh;
163 inline Foam::faceList Foam::cellShape::faces() const
165     return m->faces(*this);
169 inline Foam::faceList Foam::cellShape::collapsedFaces() const
171     faceList oldFaces(faces());
173     faceList newFaces(oldFaces.size());
174     label newFaceI = 0;
176     forAll(oldFaces, oldFaceI)
177     {
178         const face& f = oldFaces[oldFaceI];
180         face& newF = newFaces[newFaceI];
182         newF.setSize(f.size());
184         label newFp = 0;
185         label prevVertI = -1;
187         forAll(f, fp)
188         {
189             label vertI = f[fp];
191             if (vertI != prevVertI)
192             {
193                 newF[newFp++] = vertI;
195                 prevVertI = vertI;
196             }
197         }
199         if ((newFp > 1) && (newF[newFp-1] == newF[0]))
200         {
201             --newFp;
202         }
204         if (newFp > 2)
205         {
206             // Size face and go to next one
207             newF.setSize(newFp);
209             newFaceI++;
210         }
211     }
212     newFaces.setSize(newFaceI);
214     return newFaces;    
218 inline Foam::label Foam::cellShape::nFaces() const
220     return m->nFaces();
224 inline Foam::edgeList Foam::cellShape::edges() const
226     return m->edges(*this);
230 inline Foam::label Foam::cellShape::nEdges() const
232     return m->nEdges();
236 inline Foam::label Foam::cellShape::nPoints() const
238     return size();
242 inline Foam::point Foam::cellShape::centre(const pointField& points) const
244     return m->centre(*this, points);
248 inline Foam::scalar Foam::cellShape::mag(const pointField& points) const
250     return m->mag(*this, points);
254 // ************************************************************************* //