1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "ensightPartFaces.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "IOstreams.H"
29 #include "IStringStream.H"
30 #include "dictionary.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(ensightPartFaces, 0);
37 addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
41 Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_
45 "(tria3 quad4 nsided)"
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 Foam::ensightPartFaces::ensightPartFaces
55 const string& partDescription
58 ensightPart(partNumber, partDescription)
64 Foam::ensightPartFaces::ensightPartFaces
67 const polyMesh& pMesh,
68 const polyPatch& pPatch
71 ensightPart(partNumber, pPatch.name(), pMesh)
74 offset_ = pPatch.start();
75 size_ = pPatch.size();
82 forAll (pPatch, patchfaceI)
84 const face& f = pMesh.faces()[patchfaceI + offset_];
90 else if (f.size() == 4)
100 // we can avoid double looping, but at the cost of allocation
102 labelList triCells(nTri);
103 labelList quadCells(nQuad);
104 labelList polygonCells(nPoly);
110 // classify the shapes
111 forAll(pPatch, patchfaceI)
113 const face& f = pMesh.faces()[patchfaceI + offset_];
117 triCells[nTri++] = patchfaceI;
119 else if (f.size() == 4)
121 quadCells[nQuad++] = patchfaceI;
125 polygonCells[nPoly++] = patchfaceI;
130 // MUST match with elementTypes
131 elemLists_.setSize(elementTypes().size());
133 elemLists_[tria3Elements].transfer( triCells );
134 elemLists_[quad4Elements].transfer( quadCells );
135 elemLists_[nsidedElements].transfer( polygonCells );
139 Foam::ensightPartFaces::ensightPartFaces(const ensightPartFaces &part)
145 Foam::ensightPartFaces::ensightPartFaces(Istream& is)
154 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 Foam::ensightPartFaces::~ensightPartFaces()
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
164 const polyMesh& mesh = *meshPtr_;
166 localPoints ptList(mesh);
167 labelList& usedPoints = ptList.list;
170 forAll(elemLists_, typeI)
172 const labelList& idList = elemLists_[typeI];
174 // add all points from faces
177 label id = idList[i] + offset_;
178 const face& f = mesh.faces()[id];
182 if (usedPoints[f[fp]] == -1)
184 usedPoints[f[fp]] = nPoints++;
190 // this is not absolutely necessary, but renumber anyhow
192 forAll(usedPoints, ptI)
194 if (usedPoints[ptI] > -1)
196 usedPoints[ptI] = nPoints++;
200 ptList.nPoints = nPoints;
205 void Foam::ensightPartFaces::writeConnectivity
209 const labelList& idList,
210 const labelList& pointMap
213 os.writeKeyword(key);
214 os.write(idList.size());
217 const faceList& meshFaces = meshPtr_->faces();
219 // write (polygon) face sizes
220 if (word(key) == "nsided")
222 // write the number of points per face
225 label id = idList[i] + offset_;
226 const face& f = meshFaces[id];
228 os.write( f.size() );
233 // write the points describing the face
236 label id = idList[i] + offset_;
237 const face& f = meshFaces[id];
239 // convert global -> local index
240 // (note: Ensight indices start with 1)
243 os.write( pointMap[f[fp]] + 1 );
250 // ************************************************************************* //