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 "ensightPartCells.H"
28 #include "IStringStream.H"
29 #include "dictionary.H"
30 #include "cellModeller.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(ensightPartCells, 0);
38 addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream);
41 const Foam::List<Foam::word> Foam::ensightPartCells::elemTypes_
45 "(tetra4 pyramid5 penta6 hexa8 nfaced)"
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 void Foam::ensightPartCells::classify
55 const labelUList& idList
58 // References to cell shape models
59 const cellModel& tet = *(cellModeller::lookup("tet"));
60 const cellModel& pyr = *(cellModeller::lookup("pyr"));
61 const cellModel& prism = *(cellModeller::lookup("prism"));
62 const cellModel& hex = *(cellModeller::lookup("hex"));
64 const cellShapeList& cellShapes = mesh.cellShapes();
67 size_ = mesh.nCells();
73 size_ = idList.size();
83 for (label listI = 0; listI < size_; ++listI)
88 cellId = idList[listI];
91 const cellShape& cellShape = cellShapes[cellId];
92 const cellModel& cellModel = cellShape.model();
98 else if (cellModel == pyr)
102 else if (cellModel == prism)
106 else if (cellModel == hex)
117 // we can avoid double looping, but at the cost of allocation
118 labelList tetCells(nTet);
119 labelList pyramidCells(nPyr);
120 labelList prismCells(nPrism);
121 labelList hexCells(nHex);
122 labelList polyCells(nPoly);
130 // classify the shapes
131 for (label listI = 0; listI < size_; ++listI)
133 label cellId = listI;
136 cellId = idList[listI];
139 const cellShape& cellShape = cellShapes[cellId];
140 const cellModel& cellModel = cellShape.model();
142 if (cellModel == tet)
144 tetCells[nTet++] = cellId;
146 else if (cellModel == pyr)
148 pyramidCells[nPyr++] = cellId;
150 else if (cellModel == prism)
152 prismCells[nPrism++] = cellId;
154 else if (cellModel == hex)
156 hexCells[nHex++] = cellId;
160 polyCells[nPoly++] = cellId;
165 // MUST match with elementTypes
166 elemLists_.setSize(elementTypes().size());
168 elemLists_[tetra4Elements].transfer(tetCells);
169 elemLists_[pyramid5Elements].transfer(pyramidCells);
170 elemLists_[penta6Elements].transfer(prismCells);
171 elemLists_[hexa8Elements].transfer(hexCells);
172 elemLists_[nfacedElements].transfer(polyCells);
176 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 Foam::ensightPartCells::ensightPartCells
181 const string& partDescription
184 ensightPart(partNumber, partDescription),
185 mesh_(*reinterpret_cast<polyMesh*>(0))
189 Foam::ensightPartCells::ensightPartCells
195 ensightPart(partNumber, "cells", mesh.points()),
202 Foam::ensightPartCells::ensightPartCells
205 const polyMesh& mesh,
206 const labelUList& idList
209 ensightPart(partNumber, "cells", mesh.points()),
212 classify(mesh, idList);
216 Foam::ensightPartCells::ensightPartCells
219 const polyMesh& mesh,
220 const cellZone& cZone
223 ensightPart(partNumber, cZone.name(), mesh.points()),
226 classify(mesh, cZone);
230 Foam::ensightPartCells::ensightPartCells(const ensightPartCells& part)
237 Foam::ensightPartCells::ensightPartCells(Istream& is)
240 mesh_(*reinterpret_cast<polyMesh*>(0))
246 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
248 Foam::ensightPartCells::~ensightPartCells()
252 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
254 Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
256 localPoints ptList(points_);
257 labelList& usedPoints = ptList.list;
260 forAll(elemLists_, typeI)
262 const labelUList& idList = elemLists_[typeI];
264 // add all points from cells
267 const label id = idList[i] + offset_;
268 const labelUList& cFaces = mesh_.cells()[id];
270 forAll(cFaces, cFaceI)
272 const face& f = mesh_.faces()[cFaces[cFaceI]];
276 if (usedPoints[f[fp]] == -1)
278 usedPoints[f[fp]] = nPoints++;
285 // this is not absolutely necessary, but renumber anyhow
287 forAll(usedPoints, ptI)
289 if (usedPoints[ptI] > -1)
291 usedPoints[ptI] = nPoints++;
295 ptList.nPoints = nPoints;
300 void Foam::ensightPartCells::writeConnectivity
304 const labelUList& idList,
305 const labelUList& pointMap
308 os.writeKeyword(key);
309 os.write(idList.size());
315 const faceList& meshFaces = mesh_.faces();
317 // write the number of faces per element
320 const label id = idList[i] + offset_;
321 const labelUList& cFace = mesh_.cells()[id];
323 os.write(cFace.size());
327 // write the number of points per element face
330 const label id = idList[i] + offset_;
331 const labelUList& cFace = mesh_.cells()[id];
335 const face& cf = meshFaces[cFace[faceI]];
342 // write the points describing each element face
345 const label id = idList[i] + offset_;
346 const labelUList& cFace = mesh_.cells()[id];
350 const face& cf = meshFaces[cFace[faceI]];
354 // convert global -> local index
355 // (note: Ensight indices start with 1)
356 os.write(pointMap[cf[ptI]] + 1);
365 const cellShapeList& cellShapes = mesh_.cellShapes();
369 const label id = idList[i] + offset_;
370 const cellShape& cellPoints = cellShapes[id];
372 // convert global -> local index
373 // (note: Ensight indices start with 1)
374 forAll(cellPoints, ptI)
376 os.write(pointMap[cellPoints[ptI]] + 1);
384 void Foam::ensightPartCells::writeGeometry(ensightGeoFile& os) const
386 ensightPart::writeGeometry(os, points_);
390 // ************************************************************************* //