Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / conversion / ensight / part / ensightPartFaces.C
blobc8bfaa00df39620f0c4c33c8a7ce486ef5004f43
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2011 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "ensightPartFaces.H"
27 #include "IOstreams.H"
28 #include "IStringStream.H"
29 #include "dictionary.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(ensightPartFaces, 0);
37     addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
41 const Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_
43     IStringStream
44     (
45         "(tria3 quad4 nsided)"
46     )()
50 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
52 void Foam::ensightPartFaces::classify(const faceList& faces)
54     // count the shapes
55     label nTri  = 0;
56     label nQuad = 0;
57     label nPoly = 0;
59     forAll(faces, faceI)
60     {
61         const face& f = faces[faceI];
63         if (f.size() == 3)
64         {
65             nTri++;
66         }
67         else if (f.size() == 4)
68         {
69             nQuad++;
70         }
71         else
72         {
73             nPoly++;
74         }
75     }
77     // we can avoid double looping, but at the cost of allocation
79     labelList triCells(nTri);
80     labelList quadCells(nQuad);
81     labelList polygonCells(nPoly);
83     nTri  = 0;
84     nQuad = 0;
85     nPoly = 0;
87     // classify the shapes
88     forAll(faces, faceI)
89     {
90         const face& f = faces[faceI];
92         if (f.size() == 3)
93         {
94             triCells[nTri++] = faceI;
95         }
96         else if (f.size() == 4)
97         {
98             quadCells[nQuad++] = faceI;
99         }
100         else
101         {
102             polygonCells[nPoly++] = faceI;
103         }
104     }
107     // MUST match with elementTypes
108     elemLists_.setSize(elementTypes().size());
110     elemLists_[tria3Elements].transfer(triCells);
111     elemLists_[quad4Elements].transfer(quadCells);
112     elemLists_[nsidedElements].transfer(polygonCells);
114     size_ = faces.size();
118 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
120 Foam::ensightPartFaces::ensightPartFaces
122     label partNumber,
123     const string& partDescription
126     ensightPart(partNumber, partDescription),
127     faces_(faceList::null()),
128     contiguousPoints_(false)
130     isCellData_ = false;
131     offset_ = 0;
132     size_ = 0;
136 Foam::ensightPartFaces::ensightPartFaces
138     label partNumber,
139     const string& partDescription,
140     const pointField& points,
141     const faceList& faces,
142     const bool contiguousPoints
145     ensightPart(partNumber, partDescription, points),
146     faces_(faces),
147     contiguousPoints_(contiguousPoints)
149     isCellData_ = false;
150     offset_ = 0;
151     size_ = 0;
153     // classify the face shapes
154     classify(faces);
158 Foam::ensightPartFaces::ensightPartFaces
160     label partNumber,
161     const polyMesh& mesh,
162     const polyPatch& patch
165     ensightPart(partNumber, patch.name(), mesh.points()),
166     faces_(mesh.faces()),
167     contiguousPoints_(false)
169     isCellData_ = false;
170     offset_ = patch.start();
172     // classify the face shapes
173     classify(patch);
177 Foam::ensightPartFaces::ensightPartFaces(const ensightPartFaces& part)
179     ensightPart(part),
180     faces_(part.faces_),
181     contiguousPoints_(part.contiguousPoints_)
185 Foam::ensightPartFaces::ensightPartFaces(Istream& is)
187     ensightPart(),
188     faces_(faceList::null()),
189     contiguousPoints_(false)
191     isCellData_ = false;
192     reconstruct(is);
196 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
198 Foam::ensightPartFaces::~ensightPartFaces()
202 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
204 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
206     if (contiguousPoints_)
207     {
208         localPoints ptList;
209         ptList.list = identity(points_.size());
210         ptList.nPoints = points_.size();
211         return ptList;
212     }
214     localPoints ptList(points_);
215     labelList& usedPoints = ptList.list;
216     label nPoints = 0;
218     forAll(elemLists_, typeI)
219     {
220         const labelUList& idList = elemLists_[typeI];
222         // add all points from faces
223         forAll(idList, i)
224         {
225             const label id = idList[i] + offset_;
226             const face& f = faces_[id];
228             forAll(f, fp)
229             {
230                 if (usedPoints[f[fp]] == -1)
231                 {
232                     usedPoints[f[fp]] = nPoints++;
233                 }
234             }
235         }
236     }
238     // this is not absolutely necessary, but renumber anyhow
239     nPoints = 0;
240     forAll(usedPoints, ptI)
241     {
242         if (usedPoints[ptI] > -1)
243         {
244             usedPoints[ptI] = nPoints++;
245         }
246     }
248     ptList.nPoints = nPoints;
249     return ptList;
253 void Foam::ensightPartFaces::writeConnectivity
255     ensightGeoFile& os,
256     const word& key,
257     const faceList& faces,
258     const labelUList& idList,
259     const labelUList& pointMap
260 ) const
262     os.writeKeyword(key);
263     os.write(idList.size());
264     os.newline();
266     // write (polygon) face sizes
267     if (key == "nsided")
268     {
269         // write the number of points per face
270         forAll(idList, i)
271         {
272             const label id = idList[i] + offset_;
273             const face& f = faces[id];
275             os.write(f.size());
276             os.newline();
277         }
278     }
280     // write the points describing the face
281     forAll(idList, i)
282     {
283         const label id = idList[i] + offset_;
284         const face& f = faces[id];
286         // convert global -> local index
287         // (note: Ensight indices start with 1)
288         forAll(f, fp)
289         {
290             os.write(pointMap[f[fp]] + 1);
291         }
292         os.newline();
293     }
297 void Foam::ensightPartFaces::writeConnectivity
299     ensightGeoFile& os,
300     const word& key,
301     const labelUList& idList,
302     const labelUList& pointMap
303 ) const
305     writeConnectivity
306     (
307         os,
308         key,
309         faces_,
310         idList,
311         pointMap
312     );
316 void Foam::ensightPartFaces::writeGeometry(ensightGeoFile& os) const
318     ensightPart::writeGeometry(os, points_);
322 // ************************************************************************* //