1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 Note: bug in vtk displaying wedges? Seems to display ok if we decompose
28 them. Should be thoroughly tested!
29 (they appear rarely in polyhedral meshes, do appear in some cut meshes)
31 \*---------------------------------------------------------------------------*/
35 #include "cellShape.H"
36 #include "cellModeller.H"
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 // Construct from components
41 Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
46 addPointCellLabels_(),
49 const cellModel& tet = *(cellModeller::lookup("tet"));
50 const cellModel& pyr = *(cellModeller::lookup("pyr"));
51 const cellModel& prism = *(cellModeller::lookup("prism"));
52 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
53 const cellModel& hex = *(cellModeller::lookup("hex"));
56 const cellShapeList& cellShapes = mesh_.cellShapes();
59 // Number of additional points needed by the decomposition of polyhedra
62 // Number of additional cells generated by the decomposition of polyhedra
65 // Scan for cells which need to be decomposed and count additional points
68 forAll(cellShapes, cellI)
70 const cellModel& model = cellShapes[cellI].model();
75 // && model != wedge // See above.
82 const cell& cFaces = mesh_.cells()[cellI];
84 forAll(cFaces, cFaceI)
86 const face& f = mesh_.faces()[cFaces[cFaceI]];
90 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
92 nAddCells += nQuads + nTris;
100 // Set size of additional point addressing array
101 // (from added point to original cell)
102 addPointCellLabels_.setSize(nAddPoints);
104 // Set size of additional cells mapping array
105 // (from added cell to original cell)
106 superCells_.setSize(nAddCells);
108 // List of vertex labels in VTK ordering
109 vertLabels_.setSize(cellShapes.size() + nAddCells);
112 cellTypes_.setSize(cellShapes.size() + nAddCells);
114 // Set counters for additional points and additional cells
115 label api = 0, aci = 0;
117 forAll(cellShapes, cellI)
119 const cellShape& cellShape = cellShapes[cellI];
120 const cellModel& cellModel = cellShape.model();
122 labelList& vtkVerts = vertLabels_[cellI];
124 if (cellModel == tet)
126 vtkVerts = cellShape;
128 cellTypes_[cellI] = VTK_TETRA;
130 else if (cellModel == pyr)
132 vtkVerts = cellShape;
134 cellTypes_[cellI] = VTK_PYRAMID;
136 else if (cellModel == prism)
139 vtkVerts[0] = cellShape[0];
140 vtkVerts[1] = cellShape[2];
141 vtkVerts[2] = cellShape[1];
142 vtkVerts[3] = cellShape[3];
143 vtkVerts[4] = cellShape[5];
144 vtkVerts[5] = cellShape[4];
146 // VTK calls this a wedge.
147 cellTypes_[cellI] = VTK_WEDGE;
149 else if (cellModel == tetWedge)
151 // Treat as squeezed prism
153 vtkVerts[0] = cellShape[0];
154 vtkVerts[1] = cellShape[2];
155 vtkVerts[2] = cellShape[1];
156 vtkVerts[3] = cellShape[3];
157 vtkVerts[4] = cellShape[4];
158 vtkVerts[5] = cellShape[4];
160 cellTypes_[cellI] = VTK_WEDGE;
162 // else if (cellModel == wedge)
164 // // Treat as squeezed hex
165 // vtkVerts.setSize(8);
166 // vtkVerts[0] = cellShape[0];
167 // vtkVerts[1] = cellShape[1];
168 // vtkVerts[2] = cellShape[2];
169 // vtkVerts[3] = cellShape[0];
170 // vtkVerts[4] = cellShape[3];
171 // vtkVerts[5] = cellShape[4];
172 // vtkVerts[6] = cellShape[5];
173 // vtkVerts[7] = cellShape[6];
175 // cellTypes_[cellI] = VTK_HEXAHEDRON;
177 else if (cellModel == hex)
180 vtkVerts[0] = cellShape[0];
181 vtkVerts[1] = cellShape[1];
182 vtkVerts[2] = cellShape[2];
183 vtkVerts[3] = cellShape[3];
184 vtkVerts[4] = cellShape[4];
185 vtkVerts[5] = cellShape[5];
186 vtkVerts[6] = cellShape[6];
187 vtkVerts[7] = cellShape[7];
189 cellTypes_[cellI] = VTK_HEXAHEDRON;
193 // Polyhedral cell. Decompose into tets + prisms.
194 // (see dxFoamExec/createDxConnections.C)
196 // Mapping from additional point to cell
197 addPointCellLabels_[api] = cellI;
199 // Whether to insert cell in place of original or not.
200 bool substituteCell = true;
202 const labelList& cFaces = mesh_.cells()[cellI];
204 forAll(cFaces, cFaceI)
206 const face& f = mesh_.faces()[cFaces[cFaceI]];
208 // Number of triangles and quads in decomposition
211 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
213 // Do actual decomposition into triFcs and quadFcs.
214 faceList triFcs(nTris);
215 faceList quadFcs(nQuads);
218 f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
220 forAll(quadFcs, quadi)
222 label thisCellI = -1;
228 substituteCell = false;
232 thisCellI = mesh_.nCells() + aci;
234 superCells_[aci] = cellI;
239 labelList& addVtkVerts = vertLabels_[thisCellI];
241 addVtkVerts.setSize(5);
243 const face& quad = quadFcs[quadi];
245 addVtkVerts[0] = quad[0];
246 addVtkVerts[1] = quad[1];
247 addVtkVerts[2] = quad[2];
248 addVtkVerts[3] = quad[3];
249 addVtkVerts[4] = mesh_.nPoints() + api;
251 cellTypes_[thisCellI] = VTK_PYRAMID;
256 label thisCellI = -1;
262 substituteCell = false;
266 thisCellI = mesh_.nCells() + aci;
268 superCells_[aci] = cellI;
274 labelList& addVtkVerts = vertLabels_[thisCellI];
276 const face& tri = triFcs[trii];
278 addVtkVerts.setSize(4);
279 addVtkVerts[0] = tri[0];
280 addVtkVerts[1] = tri[1];
281 addVtkVerts[2] = tri[2];
282 addVtkVerts[3] = mesh_.nPoints() + api;
284 cellTypes_[thisCellI] = VTK_TETRA;
292 Pout<< " Original cells:" << mesh_.nCells()
293 << " points:" << mesh_.nPoints()
294 << " Additional cells:" << superCells_.size()
295 << " additional points:" << addPointCellLabels_.size()
299 // ************************************************************************* //