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 "ensightPartCells.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "IStringStream.H"
30 #include "dictionary.H"
31 #include "cellModeller.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(ensightPartCells, 0);
39 addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream);
42 Foam::List<Foam::word> Foam::ensightPartCells::elemTypes_
46 "(tetra4 pyramid5 penta6 hexa8 nfaced)"
51 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 void Foam::ensightPartCells::classify(const labelList& idList)
55 // References to cell shape models
56 const cellModel& tet = *(cellModeller::lookup("tet"));
57 const cellModel& pyr = *(cellModeller::lookup("pyr"));
58 const cellModel& prism = *(cellModeller::lookup("prism"));
59 const cellModel& hex = *(cellModeller::lookup("hex"));
61 const polyMesh& mesh = *meshPtr_;
62 const cellShapeList& cellShapes = mesh.cellShapes();
65 size_ = mesh.nCells();
71 size_ = idList.size();
82 // TODO: allow tet-decomposition of polyhedral cells
88 for (label listI = 0; listI < size_; ++listI)
93 cellId = idList[listI];
96 const cellShape& cellShape = cellShapes[cellId];
97 const cellModel& cellModel = cellShape.model();
103 else if (cellModel == pyr)
107 else if (cellModel == prism)
111 else if (cellModel == hex)
119 // TODO: allow tet-decomposition of polyhedral cells
121 const cell& cFaces = mesh.cells()[cellI];
123 forAll(cFaces, cFaceI)
125 const face& f = mesh.faces()[cFaces[cFaceI]];
129 f.nTrianglesQuads(mesh.points(), nTris, nQuads);
132 nPyrDecomp += nQuads;
142 // we can avoid double looping, but at the cost of allocation
143 labelList tetCells(nTet);
144 labelList pyramidCells(nPyr);
145 labelList prismCells(nPrism);
146 labelList hexCells(nHex);
147 labelList polyCells(nPoly);
155 // classify the shapes
156 for (label listI = 0; listI < size_; ++listI)
158 label cellId = listI;
161 cellId = idList[listI];
164 const cellShape& cellShape = cellShapes[cellId];
165 const cellModel& cellModel = cellShape.model();
167 if (cellModel == tet)
169 tetCells[nTet++] = cellId;
171 else if (cellModel == pyr)
173 pyramidCells[nPyr++] = cellId;
175 else if (cellModel == prism)
177 prismCells[nPrism++] = cellId;
179 else if (cellModel == hex)
181 hexCells[nHex++] = cellId;
185 polyCells[nPoly++] = cellId;
187 // TODO: allow tet-decomposition of polyhedral cells
189 // Mapping from additional point to cell
190 addPointCellLabels_[api] = cellId;
192 const cell& cFaces = mesh.cells()[cellId];
194 forAll(cFaces, cFaceI)
196 const face& f = mesh.faces()[cFaces[cFaceI]];
200 f.nTrianglesQuads(mesh.points(), nTris, nQuads);
203 nPyrDecomp += nQuads;
213 // MUST match with elementTypes
214 elemLists_.setSize(elementTypes().size());
216 elemLists_[tetra4Elements].transfer( tetCells );
217 elemLists_[pyramid5Elements].transfer( pyramidCells );
218 elemLists_[penta6Elements].transfer( prismCells );
219 elemLists_[hexa8Elements].transfer( hexCells );
220 elemLists_[nfacedElements].transfer( polyCells );
224 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
226 Foam::ensightPartCells::ensightPartCells
229 const string& partDescription
232 ensightPart(partNumber, partDescription)
236 Foam::ensightPartCells::ensightPartCells
239 const polyMesh& pMesh
242 ensightPart(partNumber, "cells", pMesh)
248 Foam::ensightPartCells::ensightPartCells
251 const polyMesh& pMesh,
252 const labelList& idList
255 ensightPart(partNumber, "cells", pMesh)
261 Foam::ensightPartCells::ensightPartCells
264 const polyMesh& pMesh,
265 const cellZone& cZone
268 ensightPart(partNumber, cZone.name(), pMesh)
274 Foam::ensightPartCells::ensightPartCells(const ensightPartCells& part)
280 Foam::ensightPartCells::ensightPartCells(Istream& is)
288 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
290 Foam::ensightPartCells::~ensightPartCells()
294 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
296 Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
298 const polyMesh& mesh = *meshPtr_;
300 localPoints ptList(mesh);
301 labelList& usedPoints = ptList.list;
304 forAll(elemLists_, typeI)
306 const labelList& idList = elemLists_[typeI];
308 // add all points from cells
311 label id = idList[i] + offset_;
312 const labelList& cFaces = mesh.cells()[id];
314 forAll(cFaces, cFaceI)
316 const face& f = mesh.faces()[cFaces[cFaceI]];
320 if (usedPoints[f[fp]] == -1)
322 usedPoints[f[fp]] = nPoints++;
329 // this is not absolutely necessary, but renumber anyhow
331 forAll(usedPoints, ptI)
333 if (usedPoints[ptI] > -1)
335 usedPoints[ptI] = nPoints++;
339 ptList.nPoints = nPoints;
344 void Foam::ensightPartCells::writeConnectivity
348 const labelList& idList,
349 const labelList& pointMap
352 os.writeKeyword(key);
353 os.write(idList.size());
356 const polyMesh& mesh = *meshPtr_;
359 if (word(key) == "nfaced")
361 const faceList& meshFaces = mesh.faces();
363 // write the number of faces per element
366 label id = idList[i] + offset_;
367 const labelList& cFace = mesh.cells()[id];
369 os.write( cFace.size() );
373 // write the number of points per element face
376 label id = idList[i] + offset_;
377 const labelList& cFace = mesh.cells()[id];
381 const face& cf = meshFaces[cFace[faceI]];
383 os.write( cf.size() );
388 // write the points describing each element face
391 label id = idList[i] + offset_;
392 const labelList& cFace = mesh.cells()[id];
396 const face& cf = meshFaces[cFace[faceI]];
400 // convert global -> local index
401 // (note: Ensight indices start with 1)
402 os.write( pointMap[cf[ptI]] + 1);
411 const cellShapeList& cellShapes = mesh.cellShapes();
415 label id = idList[i] + offset_;
416 const cellShape& cellPoints = cellShapes[id];
418 // convert global -> local index
419 // (note: Ensight indices start with 1)
420 forAll(cellPoints, ptI)
422 os.write( pointMap[cellPoints[ptI]] + 1 );
430 // ************************************************************************* //