OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkTopo.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027     Note: bug in vtk displaying wedges? Seems to display ok if we decompose
00028     them. Should be thoroughly tested!
00029     (they appear rarely in polyhedral meshes, do appear in some cut meshes)
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "vtkTopo.H"
00034 #include "polyMesh.H"
00035 #include "cellShape.H"
00036 #include "cellModeller.H"
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 // Construct from components
00041 Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
00042 :
00043     mesh_(mesh),
00044     vertLabels_(),
00045     cellTypes_(),
00046     addPointCellLabels_(),
00047     superCells_()
00048 {
00049     const cellModel& tet = *(cellModeller::lookup("tet"));
00050     const cellModel& pyr = *(cellModeller::lookup("pyr"));
00051     const cellModel& prism = *(cellModeller::lookup("prism"));
00052     const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
00053     const cellModel& hex = *(cellModeller::lookup("hex"));
00054 
00055 
00056     const cellShapeList& cellShapes = mesh_.cellShapes();
00057 
00058 
00059     // Number of additional points needed by the decomposition of polyhedra
00060     label nAddPoints = 0;
00061 
00062     // Number of additional cells generated by the decomposition of polyhedra
00063     label nAddCells = 0;
00064 
00065     // Scan for cells which need to be decomposed and count additional points
00066     // and cells
00067 
00068     forAll(cellShapes, cellI)
00069     {
00070         const cellModel& model = cellShapes[cellI].model();
00071 
00072         if 
00073         (
00074             model != hex
00075 //         && model != wedge            // See above.
00076          && model != prism
00077          && model != pyr
00078          && model != tet
00079          && model != tetWedge
00080         )
00081         {
00082             const cell& cFaces = mesh_.cells()[cellI];
00083 
00084             forAll(cFaces, cFaceI)
00085             {
00086                 const face& f = mesh_.faces()[cFaces[cFaceI]];
00087 
00088                 label nQuads = 0;
00089                 label nTris = 0;
00090                 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
00091 
00092                 nAddCells += nQuads + nTris;
00093             }
00094 
00095             nAddCells--;
00096             nAddPoints++;
00097         }
00098     }
00099 
00100     // Set size of additional point addressing array
00101     // (from added point to original cell)
00102     addPointCellLabels_.setSize(nAddPoints);
00103 
00104     // Set size of additional cells mapping array
00105     // (from added cell to original cell)
00106     superCells_.setSize(nAddCells);
00107 
00108     // List of vertex labels in VTK ordering
00109     vertLabels_.setSize(cellShapes.size() + nAddCells);
00110 
00111     // Label of vtk type
00112     cellTypes_.setSize(cellShapes.size() + nAddCells);
00113 
00114     // Set counters for additional points and additional cells
00115     label api = 0, aci = 0;
00116 
00117     forAll(cellShapes, cellI)
00118     {
00119         const cellShape& cellShape = cellShapes[cellI];
00120         const cellModel& cellModel = cellShape.model();
00121 
00122         labelList& vtkVerts = vertLabels_[cellI];
00123 
00124         if (cellModel == tet)
00125         {
00126             vtkVerts = cellShape;
00127 
00128             cellTypes_[cellI] = VTK_TETRA;
00129         }
00130         else if (cellModel == pyr)
00131         {
00132             vtkVerts = cellShape;
00133 
00134             cellTypes_[cellI] = VTK_PYRAMID;
00135         }
00136         else if (cellModel == prism)
00137         {
00138             vtkVerts.setSize(6);
00139             vtkVerts[0] = cellShape[0];
00140             vtkVerts[1] = cellShape[2];
00141             vtkVerts[2] = cellShape[1];
00142             vtkVerts[3] = cellShape[3];
00143             vtkVerts[4] = cellShape[5];
00144             vtkVerts[5] = cellShape[4];
00145 
00146             // VTK calls this a wedge.
00147             cellTypes_[cellI] = VTK_WEDGE;
00148         }
00149         else if (cellModel == tetWedge)
00150         {
00151             // Treat as squeezed prism
00152             vtkVerts.setSize(6);
00153             vtkVerts[0] = cellShape[0];
00154             vtkVerts[1] = cellShape[2];
00155             vtkVerts[2] = cellShape[1];
00156             vtkVerts[3] = cellShape[3];
00157             vtkVerts[4] = cellShape[4];
00158             vtkVerts[5] = cellShape[4];
00159 
00160             cellTypes_[cellI] = VTK_WEDGE;
00161         }
00162 //        else if (cellModel == wedge)
00163 //        {
00164 //            // Treat as squeezed hex
00165 //            vtkVerts.setSize(8);
00166 //            vtkVerts[0] = cellShape[0];
00167 //            vtkVerts[1] = cellShape[1];
00168 //            vtkVerts[2] = cellShape[2];
00169 //            vtkVerts[3] = cellShape[0];
00170 //            vtkVerts[4] = cellShape[3];
00171 //            vtkVerts[5] = cellShape[4];
00172 //            vtkVerts[6] = cellShape[5];
00173 //            vtkVerts[7] = cellShape[6];
00174 //
00175 //            cellTypes_[cellI] = VTK_HEXAHEDRON;
00176 //        }
00177         else if (cellModel == hex)
00178         {
00179             vtkVerts.setSize(8);
00180             vtkVerts[0] = cellShape[0];
00181             vtkVerts[1] = cellShape[1];
00182             vtkVerts[2] = cellShape[2];
00183             vtkVerts[3] = cellShape[3];
00184             vtkVerts[4] = cellShape[4];
00185             vtkVerts[5] = cellShape[5];
00186             vtkVerts[6] = cellShape[6];
00187             vtkVerts[7] = cellShape[7];
00188 
00189             cellTypes_[cellI] = VTK_HEXAHEDRON;
00190         }
00191         else
00192         {
00193             // Polyhedral cell. Decompose into tets + prisms.
00194             // (see dxFoamExec/createDxConnections.C)
00195 
00196             // Mapping from additional point to cell
00197             addPointCellLabels_[api] = cellI;
00198 
00199             // Whether to insert cell in place of original or not.
00200             bool substituteCell = true;
00201 
00202             const labelList& cFaces = mesh_.cells()[cellI];
00203 
00204             forAll(cFaces, cFaceI)
00205             {
00206                 const face& f = mesh_.faces()[cFaces[cFaceI]];
00207 
00208                 // Number of triangles and quads in decomposition
00209                 label nTris = 0;
00210                 label nQuads = 0;
00211                 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
00212 
00213                 // Do actual decomposition into triFcs and quadFcs.
00214                 faceList triFcs(nTris);
00215                 faceList quadFcs(nQuads);
00216                 label trii = 0;
00217                 label quadi = 0;
00218                 f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
00219 
00220                 forAll(quadFcs, quadi)
00221                 {
00222                     label thisCellI = -1;
00223 
00224                     if (substituteCell)
00225                     {
00226                         thisCellI = cellI;
00227 
00228                         substituteCell = false;
00229                     }
00230                     else
00231                     {
00232                         thisCellI = mesh_.nCells() + aci;
00233 
00234                         superCells_[aci] = cellI;
00235 
00236                         aci++;
00237                     }
00238 
00239                     labelList& addVtkVerts = vertLabels_[thisCellI];
00240 
00241                     addVtkVerts.setSize(5);
00242 
00243                     const face& quad = quadFcs[quadi];
00244 
00245                     addVtkVerts[0] = quad[0];
00246                     addVtkVerts[1] = quad[1];
00247                     addVtkVerts[2] = quad[2];
00248                     addVtkVerts[3] = quad[3];
00249                     addVtkVerts[4] = mesh_.nPoints() + api;
00250 
00251                     cellTypes_[thisCellI] = VTK_PYRAMID;
00252                 }
00253 
00254                 forAll(triFcs, trii)
00255                 {
00256                     label thisCellI = -1;
00257 
00258                     if (substituteCell)
00259                     {
00260                         thisCellI = cellI;
00261 
00262                         substituteCell = false;
00263                     }
00264                     else
00265                     {
00266                         thisCellI = mesh_.nCells() + aci;
00267 
00268                         superCells_[aci] = cellI;
00269 
00270                         aci++;
00271                     }
00272 
00273 
00274                     labelList& addVtkVerts = vertLabels_[thisCellI];
00275 
00276                     const face& tri = triFcs[trii];
00277 
00278                     addVtkVerts.setSize(4);
00279                     addVtkVerts[0] = tri[0];
00280                     addVtkVerts[1] = tri[1];
00281                     addVtkVerts[2] = tri[2];
00282                     addVtkVerts[3] = mesh_.nPoints() + api;
00283 
00284                     cellTypes_[thisCellI] = VTK_TETRA;
00285                 }
00286             }
00287 
00288             api++;
00289         }
00290     }
00291 
00292     Pout<< "    Original cells:" << mesh_.nCells()
00293         << " points:" << mesh_.nPoints()
00294         << "   Additional cells:" << superCells_.size()
00295         << "  additional points:" << addPointCellLabels_.size()
00296         << nl << endl;
00297 }
00298 
00299 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd