FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025 
00026     Note: bug in vtk displaying wedges? Seems to display ok if we decompose
00027     them. Should be thoroughly tested!
00028     (they appear rarely in polyhedral meshes, do appear in some cut meshes)
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #include "vtkTopo.H"
00033 #include <OpenFOAM/polyMesh.H>
00034 #include <OpenFOAM/cellShape.H>
00035 #include <OpenFOAM/cellModeller.H>
00036 
00037 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00038 
00039 // Construct from components
00040 Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
00041 :
00042     mesh_(mesh),
00043     vertLabels_(),
00044     cellTypes_(),
00045     addPointCellLabels_(),
00046     superCells_()
00047 {
00048     const cellModel& tet = *(cellModeller::lookup("tet"));
00049     const cellModel& pyr = *(cellModeller::lookup("pyr"));
00050     const cellModel& prism = *(cellModeller::lookup("prism"));
00051     const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
00052     const cellModel& hex = *(cellModeller::lookup("hex"));
00053 
00054 
00055     const cellShapeList& cellShapes = mesh_.cellShapes();
00056 
00057 
00058     // Number of additional points needed by the decomposition of polyhedra
00059     label nAddPoints = 0;
00060 
00061     // Number of additional cells generated by the decomposition of polyhedra
00062     label nAddCells = 0;
00063 
00064     // Scan for cells which need to be decomposed and count additional points
00065     // and cells
00066 
00067     forAll(cellShapes, cellI)
00068     {
00069         const cellModel& model = cellShapes[cellI].model();
00070 
00071         if 
00072         (
00073             model != hex
00074 //         && model != wedge            // See above.
00075          && model != prism
00076          && model != pyr
00077          && model != tet
00078          && model != tetWedge
00079         )
00080         {
00081             const cell& cFaces = mesh_.cells()[cellI];
00082 
00083             forAll(cFaces, cFaceI)
00084             {
00085                 const face& f = mesh_.faces()[cFaces[cFaceI]];
00086 
00087                 label nQuads = 0;
00088                 label nTris = 0;
00089                 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
00090 
00091                 nAddCells += nQuads + nTris;
00092             }
00093 
00094             nAddCells--;
00095             nAddPoints++;
00096         }
00097     }
00098 
00099     // Set size of additional point addressing array
00100     // (from added point to original cell)
00101     addPointCellLabels_.setSize(nAddPoints);
00102 
00103     // Set size of additional cells mapping array
00104     // (from added cell to original cell)
00105     superCells_.setSize(nAddCells);
00106 
00107     // List of vertex labels in VTK ordering
00108     vertLabels_.setSize(cellShapes.size() + nAddCells);
00109 
00110     // Label of vtk type
00111     cellTypes_.setSize(cellShapes.size() + nAddCells);
00112 
00113     // Set counters for additional points and additional cells
00114     label api = 0, aci = 0;
00115 
00116     forAll(cellShapes, cellI)
00117     {
00118         const cellShape& cellShape = cellShapes[cellI];
00119         const cellModel& cellModel = cellShape.model();
00120 
00121         labelList& vtkVerts = vertLabels_[cellI];
00122 
00123         if (cellModel == tet)
00124         {
00125             vtkVerts = cellShape;
00126 
00127             cellTypes_[cellI] = VTK_TETRA;
00128         }
00129         else if (cellModel == pyr)
00130         {
00131             vtkVerts = cellShape;
00132 
00133             cellTypes_[cellI] = VTK_PYRAMID;
00134         }
00135         else if (cellModel == prism)
00136         {
00137             vtkVerts.setSize(6);
00138             vtkVerts[0] = cellShape[0];
00139             vtkVerts[1] = cellShape[2];
00140             vtkVerts[2] = cellShape[1];
00141             vtkVerts[3] = cellShape[3];
00142             vtkVerts[4] = cellShape[5];
00143             vtkVerts[5] = cellShape[4];
00144 
00145             // VTK calls this a wedge.
00146             cellTypes_[cellI] = VTK_WEDGE;
00147         }
00148         else if (cellModel == tetWedge)
00149         {
00150             // Treat as squeezed prism
00151             vtkVerts.setSize(6);
00152             vtkVerts[0] = cellShape[0];
00153             vtkVerts[1] = cellShape[2];
00154             vtkVerts[2] = cellShape[1];
00155             vtkVerts[3] = cellShape[3];
00156             vtkVerts[4] = cellShape[4];
00157             vtkVerts[5] = cellShape[4];
00158 
00159             cellTypes_[cellI] = VTK_WEDGE;
00160         }
00161 //        else if (cellModel == wedge)
00162 //        {
00163 //            // Treat as squeezed hex
00164 //            vtkVerts.setSize(8);
00165 //            vtkVerts[0] = cellShape[0];
00166 //            vtkVerts[1] = cellShape[1];
00167 //            vtkVerts[2] = cellShape[2];
00168 //            vtkVerts[3] = cellShape[0];
00169 //            vtkVerts[4] = cellShape[3];
00170 //            vtkVerts[5] = cellShape[4];
00171 //            vtkVerts[6] = cellShape[5];
00172 //            vtkVerts[7] = cellShape[6];
00173 //
00174 //            cellTypes_[cellI] = VTK_HEXAHEDRON;
00175 //        }
00176         else if (cellModel == hex)
00177         {
00178             vtkVerts.setSize(8);
00179             vtkVerts[0] = cellShape[0];
00180             vtkVerts[1] = cellShape[1];
00181             vtkVerts[2] = cellShape[2];
00182             vtkVerts[3] = cellShape[3];
00183             vtkVerts[4] = cellShape[4];
00184             vtkVerts[5] = cellShape[5];
00185             vtkVerts[6] = cellShape[6];
00186             vtkVerts[7] = cellShape[7];
00187 
00188             cellTypes_[cellI] = VTK_HEXAHEDRON;
00189         }
00190         else
00191         {
00192             // Polyhedral cell. Decompose into tets + prisms.
00193             // (see dxFoamExec/createDxConnections.C)
00194 
00195             // Mapping from additional point to cell
00196             addPointCellLabels_[api] = cellI;
00197 
00198             // Whether to insert cell in place of original or not.
00199             bool substituteCell = true;
00200 
00201             const labelList& cFaces = mesh_.cells()[cellI];
00202 
00203             forAll(cFaces, cFaceI)
00204             {
00205                 const face& f = mesh_.faces()[cFaces[cFaceI]];
00206 
00207                 // Number of triangles and quads in decomposition
00208                 label nTris = 0;
00209                 label nQuads = 0;
00210                 f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
00211 
00212                 // Do actual decomposition into triFcs and quadFcs.
00213                 faceList triFcs(nTris);
00214                 faceList quadFcs(nQuads);
00215                 label trii = 0;
00216                 label quadi = 0;
00217                 f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
00218 
00219                 forAll(quadFcs, quadi)
00220                 {
00221                     label thisCellI = -1;
00222 
00223                     if (substituteCell)
00224                     {
00225                         thisCellI = cellI;
00226 
00227                         substituteCell = false;
00228                     }
00229                     else
00230                     {
00231                         thisCellI = mesh_.nCells() + aci;
00232 
00233                         superCells_[aci] = cellI;
00234 
00235                         aci++;
00236                     }
00237 
00238                     labelList& addVtkVerts = vertLabels_[thisCellI];
00239 
00240                     addVtkVerts.setSize(5);
00241 
00242                     const face& quad = quadFcs[quadi];
00243 
00244                     addVtkVerts[0] = quad[0];
00245                     addVtkVerts[1] = quad[1];
00246                     addVtkVerts[2] = quad[2];
00247                     addVtkVerts[3] = quad[3];
00248                     addVtkVerts[4] = mesh_.nPoints() + api;
00249 
00250                     cellTypes_[thisCellI] = VTK_PYRAMID;
00251                 }
00252 
00253                 forAll(triFcs, trii)
00254                 {
00255                     label thisCellI = -1;
00256 
00257                     if (substituteCell)
00258                     {
00259                         thisCellI = cellI;
00260 
00261                         substituteCell = false;
00262                     }
00263                     else
00264                     {
00265                         thisCellI = mesh_.nCells() + aci;
00266 
00267                         superCells_[aci] = cellI;
00268 
00269                         aci++;
00270                     }
00271 
00272 
00273                     labelList& addVtkVerts = vertLabels_[thisCellI];
00274 
00275                     const face& tri = triFcs[trii];
00276 
00277                     addVtkVerts.setSize(4);
00278                     addVtkVerts[0] = tri[0];
00279                     addVtkVerts[1] = tri[1];
00280                     addVtkVerts[2] = tri[2];
00281                     addVtkVerts[3] = mesh_.nPoints() + api;
00282 
00283                     cellTypes_[thisCellI] = VTK_TETRA;
00284                 }
00285             }
00286 
00287             api++;
00288         }
00289     }
00290 
00291     Pout<< "    Original cells:" << mesh_.nCells()
00292         << " points:" << mesh_.nPoints()
00293         << "   Additional cells:" << superCells_.size()
00294         << "  additional points:" << addPointCellLabels_.size()
00295         << nl << endl;
00296 }
00297 
00298 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines