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/>.
26 Note: bug in vtk displaying wedges? Seems to display ok if we decompose
27 them. Should be thoroughly tested!
28 (they appear rarely in polyhedral meshes, do appear in some cut meshes)
30 \*---------------------------------------------------------------------------*/
34 #include "cellShape.H"
35 #include "cellModeller.H"
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 // Construct from components
40 Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
45 addPointCellLabels_(),
48 const cellModel& tet = *(cellModeller::lookup("tet"));
49 const cellModel& pyr = *(cellModeller::lookup("pyr"));
50 const cellModel& prism = *(cellModeller::lookup("prism"));
51 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
52 const cellModel& hex = *(cellModeller::lookup("hex"));
55 const cellShapeList& cellShapes = mesh_.cellShapes();
58 // Number of additional points needed by the decomposition of polyhedra
61 // Number of additional cells generated by the decomposition of polyhedra
64 // Scan for cells which need to be decomposed and count additional points
67 forAll(cellShapes, cellI)
69 const cellModel& model = cellShapes[cellI].model();
74 // && model != wedge // See above.
81 const cell& cFaces = mesh_.cells()[cellI];
83 forAll(cFaces, cFaceI)
85 const face& f = mesh_.faces()[cFaces[cFaceI]];
89 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
91 nAddCells += nQuads + nTris;
99 // Set size of additional point addressing array
100 // (from added point to original cell)
101 addPointCellLabels_.setSize(nAddPoints);
103 // Set size of additional cells mapping array
104 // (from added cell to original cell)
105 superCells_.setSize(nAddCells);
107 // List of vertex labels in VTK ordering
108 vertLabels_.setSize(cellShapes.size() + nAddCells);
111 cellTypes_.setSize(cellShapes.size() + nAddCells);
113 // Set counters for additional points and additional cells
114 label api = 0, aci = 0;
116 forAll(cellShapes, cellI)
118 const cellShape& cellShape = cellShapes[cellI];
119 const cellModel& cellModel = cellShape.model();
121 labelList& vtkVerts = vertLabels_[cellI];
123 if (cellModel == tet)
125 vtkVerts = cellShape;
127 cellTypes_[cellI] = VTK_TETRA;
129 else if (cellModel == pyr)
131 vtkVerts = cellShape;
133 cellTypes_[cellI] = VTK_PYRAMID;
135 else if (cellModel == prism)
138 vtkVerts[0] = cellShape[0];
139 vtkVerts[1] = cellShape[2];
140 vtkVerts[2] = cellShape[1];
141 vtkVerts[3] = cellShape[3];
142 vtkVerts[4] = cellShape[5];
143 vtkVerts[5] = cellShape[4];
145 // VTK calls this a wedge.
146 cellTypes_[cellI] = VTK_WEDGE;
148 else if (cellModel == tetWedge)
150 // Treat as squeezed prism
152 vtkVerts[0] = cellShape[0];
153 vtkVerts[1] = cellShape[2];
154 vtkVerts[2] = cellShape[1];
155 vtkVerts[3] = cellShape[3];
156 vtkVerts[4] = cellShape[4];
157 vtkVerts[5] = cellShape[4];
159 cellTypes_[cellI] = VTK_WEDGE;
161 // else if (cellModel == wedge)
163 // // Treat as squeezed hex
164 // vtkVerts.setSize(8);
165 // vtkVerts[0] = cellShape[0];
166 // vtkVerts[1] = cellShape[1];
167 // vtkVerts[2] = cellShape[2];
168 // vtkVerts[3] = cellShape[0];
169 // vtkVerts[4] = cellShape[3];
170 // vtkVerts[5] = cellShape[4];
171 // vtkVerts[6] = cellShape[5];
172 // vtkVerts[7] = cellShape[6];
174 // cellTypes_[cellI] = VTK_HEXAHEDRON;
176 else if (cellModel == hex)
179 vtkVerts[0] = cellShape[0];
180 vtkVerts[1] = cellShape[1];
181 vtkVerts[2] = cellShape[2];
182 vtkVerts[3] = cellShape[3];
183 vtkVerts[4] = cellShape[4];
184 vtkVerts[5] = cellShape[5];
185 vtkVerts[6] = cellShape[6];
186 vtkVerts[7] = cellShape[7];
188 cellTypes_[cellI] = VTK_HEXAHEDRON;
192 // Polyhedral cell. Decompose into tets + prisms.
193 // (see dxFoamExec/createDxConnections.C)
195 // Mapping from additional point to cell
196 addPointCellLabels_[api] = cellI;
198 // Whether to insert cell in place of original or not.
199 bool substituteCell = true;
201 const labelList& cFaces = mesh_.cells()[cellI];
203 forAll(cFaces, cFaceI)
205 const face& f = mesh_.faces()[cFaces[cFaceI]];
207 // Number of triangles and quads in decomposition
210 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
212 // Do actual decomposition into triFcs and quadFcs.
213 faceList triFcs(nTris);
214 faceList quadFcs(nQuads);
217 f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
219 forAll(quadFcs, quadi)
221 label thisCellI = -1;
227 substituteCell = false;
231 thisCellI = mesh_.nCells() + aci;
233 superCells_[aci] = cellI;
238 labelList& addVtkVerts = vertLabels_[thisCellI];
240 addVtkVerts.setSize(5);
242 const face& quad = quadFcs[quadi];
244 addVtkVerts[0] = quad[0];
245 addVtkVerts[1] = quad[1];
246 addVtkVerts[2] = quad[2];
247 addVtkVerts[3] = quad[3];
248 addVtkVerts[4] = mesh_.nPoints() + api;
250 cellTypes_[thisCellI] = VTK_PYRAMID;
255 label thisCellI = -1;
261 substituteCell = false;
265 thisCellI = mesh_.nCells() + aci;
267 superCells_[aci] = cellI;
273 labelList& addVtkVerts = vertLabels_[thisCellI];
275 const face& tri = triFcs[trii];
277 addVtkVerts.setSize(4);
278 addVtkVerts[0] = tri[0];
279 addVtkVerts[1] = tri[1];
280 addVtkVerts[2] = tri[2];
281 addVtkVerts[3] = mesh_.nPoints() + api;
283 cellTypes_[thisCellI] = VTK_TETRA;
291 Pout<< " Original cells:" << mesh_.nCells()
292 << " points:" << mesh_.nPoints()
293 << " Additional cells:" << superCells_.size()
294 << " additional points:" << addPointCellLabels_.size()
298 // ************************************************************************* //