1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(ensightPartFaces, 0);
37 addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
41 const Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_
45 "(tria3 quad4 nsided)"
50 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
52 void Foam::ensightPartFaces::classify(const faceList& faces)
61 const face& f = faces[faceI];
67 else if (f.size() == 4)
77 // we can avoid double looping, but at the cost of allocation
79 labelList triCells(nTri);
80 labelList quadCells(nQuad);
81 labelList polygonCells(nPoly);
87 // classify the shapes
90 const face& f = faces[faceI];
94 triCells[nTri++] = faceI;
96 else if (f.size() == 4)
98 quadCells[nQuad++] = faceI;
102 polygonCells[nPoly++] = faceI;
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
123 const string& partDescription
126 ensightPart(partNumber, partDescription),
127 faces_(faceList::null()),
128 contiguousPoints_(false)
136 Foam::ensightPartFaces::ensightPartFaces
139 const string& partDescription,
140 const pointField& points,
141 const faceList& faces,
142 const bool contiguousPoints
145 ensightPart(partNumber, partDescription, points),
147 contiguousPoints_(contiguousPoints)
153 // classify the face shapes
158 Foam::ensightPartFaces::ensightPartFaces
161 const polyMesh& mesh,
162 const polyPatch& patch
165 ensightPart(partNumber, patch.name(), mesh.points()),
166 faces_(mesh.faces()),
167 contiguousPoints_(false)
170 offset_ = patch.start();
172 // classify the face shapes
177 Foam::ensightPartFaces::ensightPartFaces(const ensightPartFaces& part)
181 contiguousPoints_(part.contiguousPoints_)
185 Foam::ensightPartFaces::ensightPartFaces(Istream& is)
188 faces_(faceList::null()),
189 contiguousPoints_(false)
196 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 Foam::ensightPartFaces::~ensightPartFaces()
202 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
206 if (contiguousPoints_)
209 ptList.list = identity(points_.size());
210 ptList.nPoints = points_.size();
214 localPoints ptList(points_);
215 labelList& usedPoints = ptList.list;
218 forAll(elemLists_, typeI)
220 const labelUList& idList = elemLists_[typeI];
222 // add all points from faces
225 const label id = idList[i] + offset_;
226 const face& f = faces_[id];
230 if (usedPoints[f[fp]] == -1)
232 usedPoints[f[fp]] = nPoints++;
238 // this is not absolutely necessary, but renumber anyhow
240 forAll(usedPoints, ptI)
242 if (usedPoints[ptI] > -1)
244 usedPoints[ptI] = nPoints++;
248 ptList.nPoints = nPoints;
253 void Foam::ensightPartFaces::writeConnectivity
257 const faceList& faces,
258 const labelUList& idList,
259 const labelUList& pointMap
262 os.writeKeyword(key);
263 os.write(idList.size());
266 // write (polygon) face sizes
269 // write the number of points per face
272 const label id = idList[i] + offset_;
273 const face& f = faces[id];
280 // write the points describing the face
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)
290 os.write(pointMap[f[fp]] + 1);
297 void Foam::ensightPartFaces::writeConnectivity
301 const labelUList& idList,
302 const labelUList& pointMap
316 void Foam::ensightPartFaces::writeGeometry(ensightGeoFile& os) const
318 ensightPart::writeGeometry(os, points_);
322 // ************************************************************************* //