1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "fieldviewTopology.H"
31 #include "cellShape.H"
32 #include "cellModeller.H"
33 #include "wallPolyPatch.H"
34 #include "symmetryPolyPatch.H"
37 #include "fv_reader_tags.h"
41 unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 Foam::labelList Foam::fieldviewTopology::calcFaceAddressing
49 const faceList& allFaces, // faces given faceLabels
50 const cellShape& shape,
51 const labelList& faces, // faceLabels for given cell
56 labelList shapeToMesh(shape.nFaces(), -1);
58 const faceList modelFaces(shape.faces());
60 // Loop over all faces of cellShape
61 forAll(modelFaces, cellFaceI)
64 const face& modelFace = modelFaces[cellFaceI];
66 // Loop over all face labels
69 const face& vertLabels = allFaces[faces[faceI]];
71 if (vertLabels == modelFace)
73 shapeToMesh[cellFaceI] = faces[faceI];
78 if (shapeToMesh[cellFaceI] == -1)
80 FatalErrorIn("foamToFieldview : calcFaceAddressing")
81 << "calcFaceAddressing : can't match face to shape.\n"
82 << " shape face:" << modelFace << endl
83 << " face labels:" << faces << endl
84 << " cellI:" << cellI << endl;
86 FatalError << "Faces consist of vertices:" << endl;
90 << " face:" << faces[faceI]
91 << allFaces[faces[faceI]] << endl;
93 FatalError << exit(FatalError);
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 // Construct from components
103 Foam::fieldviewTopology::fieldviewTopology
105 const polyMesh& mesh,
106 const bool setWallInfo
109 hexLabels_((1+8)*mesh.nCells()),
110 prismLabels_((1+6)*mesh.nCells()),
111 pyrLabels_((1+5)*mesh.nCells()),
112 tetLabels_((1+4)*mesh.nCells()),
114 quadFaceLabels_(mesh.boundaryMesh().size()),
115 nPolyFaces_(mesh.boundaryMesh().size())
117 // Mark all faces that are to be seen as wall for particle
118 // tracking and all cells that use one or more of these walls
120 labelList wallFace(mesh.nFaces(), NOT_A_WALL);
121 boolList wallCell(mesh.nCells(), false);
125 forAll (mesh.boundaryMesh(), patchI)
127 const polyPatch& currPatch = mesh.boundaryMesh()[patchI];
130 isType<wallPolyPatch>(currPatch)
131 || isType<symmetryPolyPatch>(currPatch)
134 forAll(currPatch, patchFaceI)
136 label meshFaceI = currPatch.start() + patchFaceI;
138 wallFace[meshFaceI] = A_WALL;
139 wallCell[mesh.faceOwner()[meshFaceI]] = true;
147 const cellModel& tet = *(cellModeller::lookup("tet"));
148 const cellModel& pyr = *(cellModeller::lookup("pyr"));
149 const cellModel& prism = *(cellModeller::lookup("prism"));
150 const cellModel& wedge = *(cellModeller::lookup("wedge"));
151 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
152 const cellModel& hex = *(cellModeller::lookup("hex"));
154 // Pre calculate headers for cells not on walls
155 labelList notWallFlags(6, NOT_A_WALL);
156 label tetNotWall = fv_encode_elem_header
158 FV_TET_ELEM_ID, notWallFlags.begin()
160 label pyrNotWall = fv_encode_elem_header
162 FV_PYRA_ELEM_ID, notWallFlags.begin()
164 label prismNotWall = fv_encode_elem_header
166 FV_PRISM_ELEM_ID, notWallFlags.begin()
168 label hexNotWall = fv_encode_elem_header
170 FV_HEX_ELEM_ID, notWallFlags.begin()
174 const cellList& cellFaces = mesh.cells();
175 const cellShapeList& cellShapes = mesh.cellShapes();
183 const faceList& allFaces = mesh.faces();
185 labelList wallFlags(6);
186 forAll(cellShapes, celli)
188 const cellShape& cellShape = cellShapes[celli];
189 const cellModel& cellModel = cellShape.model();
191 if (cellModel == tet)
193 if (!wallCell[celli])
195 tetLabels_[teti++] = tetNotWall;
199 labelList modelToMesh = calcFaceAddressing
201 allFaces, cellShape, cellFaces[celli], celli
204 wallFlags[0] = wallFace[modelToMesh[0]];
205 wallFlags[1] = wallFace[modelToMesh[1]];
206 wallFlags[2] = wallFace[modelToMesh[2]];
207 wallFlags[3] = wallFace[modelToMesh[3]];
209 tetLabels_[teti++] = fv_encode_elem_header
211 FV_TET_ELEM_ID, wallFlags.begin()
215 tetLabels_[teti++] = cellShape[0] + 1;
216 tetLabels_[teti++] = cellShape[1] + 1;
217 tetLabels_[teti++] = cellShape[2] + 1;
218 tetLabels_[teti++] = cellShape[3] + 1;
220 else if (cellModel == pyr)
222 if (!wallCell[celli])
224 pyrLabels_[pyri++] = pyrNotWall;
228 labelList modelToMesh = calcFaceAddressing
230 allFaces, cellShape, cellFaces[celli], celli
233 wallFlags[0] = wallFace[modelToMesh[0]];
234 wallFlags[1] = wallFace[modelToMesh[3]];
235 wallFlags[2] = wallFace[modelToMesh[2]];
236 wallFlags[3] = wallFace[modelToMesh[1]];
237 wallFlags[4] = wallFace[modelToMesh[4]];
239 pyrLabels_[pyri++] = fv_encode_elem_header
241 FV_PYRA_ELEM_ID, wallFlags.begin()
245 pyrLabels_[pyri++] = cellShape[0] + 1;
246 pyrLabels_[pyri++] = cellShape[1] + 1;
247 pyrLabels_[pyri++] = cellShape[2] + 1;
248 pyrLabels_[pyri++] = cellShape[3] + 1;
249 pyrLabels_[pyri++] = cellShape[4] + 1;
251 else if (cellModel == prism)
253 if (!wallCell[celli])
255 prismLabels_[prismi++] = prismNotWall;
259 labelList modelToMesh = calcFaceAddressing
261 allFaces, cellShape, cellFaces[celli], celli
264 wallFlags[0] = wallFace[modelToMesh[4]];
265 wallFlags[1] = wallFace[modelToMesh[2]];
266 wallFlags[2] = wallFace[modelToMesh[3]];
267 wallFlags[3] = wallFace[modelToMesh[0]];
268 wallFlags[4] = wallFace[modelToMesh[1]];
270 prismLabels_[prismi++] = fv_encode_elem_header
272 FV_PRISM_ELEM_ID, wallFlags.begin()
276 prismLabels_[prismi++] = cellShape[0] + 1;
277 prismLabels_[prismi++] = cellShape[3] + 1;
278 prismLabels_[prismi++] = cellShape[4] + 1;
279 prismLabels_[prismi++] = cellShape[1] + 1;
280 prismLabels_[prismi++] = cellShape[5] + 1;
281 prismLabels_[prismi++] = cellShape[2] + 1;
283 else if (cellModel == tetWedge)
285 // Treat as prism with collapsed edge
286 if (!wallCell[celli])
288 prismLabels_[prismi++] = prismNotWall;
292 labelList modelToMesh = calcFaceAddressing
294 allFaces, cellShape, cellFaces[celli], celli
297 wallFlags[0] = wallFace[modelToMesh[1]];
298 wallFlags[1] = wallFace[modelToMesh[2]];
299 wallFlags[2] = wallFace[modelToMesh[3]];
300 wallFlags[3] = wallFace[modelToMesh[0]];
301 wallFlags[4] = wallFace[modelToMesh[3]];
303 prismLabels_[prismi++] = fv_encode_elem_header
305 FV_PRISM_ELEM_ID, wallFlags.begin()
309 prismLabels_[prismi++] = cellShape[0] + 1;
310 prismLabels_[prismi++] = cellShape[3] + 1;
311 prismLabels_[prismi++] = cellShape[4] + 1;
312 prismLabels_[prismi++] = cellShape[1] + 1;
313 prismLabels_[prismi++] = cellShape[4] + 1;
314 prismLabels_[prismi++] = cellShape[2] + 1;
316 else if (cellModel == wedge)
318 if (!wallCell[celli])
320 hexLabels_[hexi++] = hexNotWall;
324 labelList modelToMesh = calcFaceAddressing
326 allFaces, cellShape, cellFaces[celli], celli
329 wallFlags[0] = wallFace[modelToMesh[2]];
330 wallFlags[1] = wallFace[modelToMesh[3]];
331 wallFlags[2] = wallFace[modelToMesh[0]];
332 wallFlags[3] = wallFace[modelToMesh[1]];
333 wallFlags[4] = wallFace[modelToMesh[4]];
334 wallFlags[5] = wallFace[modelToMesh[5]];
336 hexLabels_[hexi++] = fv_encode_elem_header
338 FV_HEX_ELEM_ID, wallFlags.begin()
341 hexLabels_[hexi++] = cellShape[0] + 1;
342 hexLabels_[hexi++] = cellShape[1] + 1;
343 hexLabels_[hexi++] = cellShape[0] + 1;
344 hexLabels_[hexi++] = cellShape[2] + 1;
345 hexLabels_[hexi++] = cellShape[3] + 1;
346 hexLabels_[hexi++] = cellShape[4] + 1;
347 hexLabels_[hexi++] = cellShape[6] + 1;
348 hexLabels_[hexi++] = cellShape[5] + 1;
350 else if (cellModel == hex)
352 if (!wallCell[celli])
354 hexLabels_[hexi++] = hexNotWall;
358 labelList modelToMesh = calcFaceAddressing
360 allFaces, cellShape, cellFaces[celli], celli
363 wallFlags[0] = wallFace[modelToMesh[0]];
364 wallFlags[1] = wallFace[modelToMesh[1]];
365 wallFlags[2] = wallFace[modelToMesh[4]];
366 wallFlags[3] = wallFace[modelToMesh[5]];
367 wallFlags[4] = wallFace[modelToMesh[2]];
368 wallFlags[5] = wallFace[modelToMesh[3]];
370 hexLabels_[hexi++] = fv_encode_elem_header
372 FV_HEX_ELEM_ID, wallFlags.begin()
375 hexLabels_[hexi++] = cellShape[0] + 1;
376 hexLabels_[hexi++] = cellShape[1] + 1;
377 hexLabels_[hexi++] = cellShape[3] + 1;
378 hexLabels_[hexi++] = cellShape[2] + 1;
379 hexLabels_[hexi++] = cellShape[4] + 1;
380 hexLabels_[hexi++] = cellShape[5] + 1;
381 hexLabels_[hexi++] = cellShape[7] + 1;
382 hexLabels_[hexi++] = cellShape[6] + 1;
390 hexLabels_.setSize(hexi);
391 prismLabels_.setSize(prismi);
392 pyrLabels_.setSize(pyri);
393 tetLabels_.setSize(teti);
399 forAll(mesh.boundaryMesh(), patchI)
401 const polyPatch& patchFaces = mesh.boundaryMesh()[patchI];
403 labelList& faceLabels = quadFaceLabels_[patchI];
405 // Faces, each 4 labels. Size big enough
406 faceLabels.setSize(patchFaces.size()*4);
410 forAll(patchFaces, faceI)
412 const face& patchFace = patchFaces[faceI];
414 if (patchFace.size() == 3)
416 faceLabels[labelI++] = patchFace[0] + 1;
417 faceLabels[labelI++] = patchFace[1] + 1;
418 faceLabels[labelI++] = patchFace[2] + 1;
419 faceLabels[labelI++] = 0; // Fieldview:triangle definition
421 else if (patchFace.size() == 4)
423 faceLabels[labelI++] = patchFace[0] + 1;
424 faceLabels[labelI++] = patchFace[1] + 1;
425 faceLabels[labelI++] = patchFace[2] + 1;
426 faceLabels[labelI++] = patchFace[3] + 1;
430 faceLabels.setSize(labelI);
432 label nFaces = labelI/4;
434 nPolyFaces_[patchI] = patchFaces.size() - nFaces;
439 // ************************************************************************* //