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

ensightPartCells.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 \*----------------------------------------------------------------------------*/
00026 
00027 #include "ensightPartCells.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "IOstream.H"
00030 #include "IStringStream.H"
00031 #include "dictionary.H"
00032 #include "cellModeller.H"
00033 
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039    defineTypeNameAndDebug(ensightPartCells, 0);
00040    addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream);
00041 }
00042 
00043 Foam::List<Foam::word> Foam::ensightPartCells::elemTypes_
00044 (
00045     IStringStream
00046     (
00047         "(tetra4 pyramid5 penta6 hexa8 nfaced)"
00048     )()
00049 );
00050 
00051 
00052 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00053 
00054 void Foam::ensightPartCells::classify(const labelList& idList)
00055 {
00056     // References to cell shape models
00057     const cellModel& tet   = *(cellModeller::lookup("tet"));
00058     const cellModel& pyr   = *(cellModeller::lookup("pyr"));
00059     const cellModel& prism = *(cellModeller::lookup("prism"));
00060     const cellModel& hex   = *(cellModeller::lookup("hex"));
00061 
00062     const polyMesh& mesh = *meshPtr_;
00063     const cellShapeList& cellShapes = mesh.cellShapes();
00064 
00065     offset_ = 0;
00066     size_ = mesh.nCells();
00067 
00068     bool limited = false;
00069     if (&idList)
00070     {
00071         limited = true;
00072         size_ = idList.size();
00073     }
00074 
00075     // count the shapes
00076     label nTet   = 0;
00077     label nPyr   = 0;
00078     label nPrism = 0;
00079     label nHex   = 0;
00080     label nPoly  = 0;
00081 
00082 
00083     // TODO: allow tet-decomposition of polyhedral cells
00084 #if 0
00085     label nTetDecomp = 0;
00086     label nPyrDecomp = 0;
00087 #endif
00088 
00089     for (label listI = 0; listI < size_; ++listI)
00090     {
00091         label cellId = listI;
00092         if (limited)
00093         {
00094             cellId = idList[listI];
00095         }
00096 
00097         const cellShape& cellShape = cellShapes[cellId];
00098         const cellModel& cellModel = cellShape.model();
00099 
00100         if (cellModel == tet)
00101         {
00102             nTet++;
00103         }
00104         else if (cellModel == pyr)
00105         {
00106             nPyr++;
00107         }
00108         else if (cellModel == prism)
00109         {
00110             nPrism++;
00111         }
00112         else if (cellModel == hex)
00113         {
00114             nHex++;
00115         }
00116         else
00117         {
00118             nPoly++;
00119 
00120             // TODO: allow tet-decomposition of polyhedral cells
00121 #if 0
00122             const cell& cFaces = mesh.cells()[cellI];
00123 
00124             forAll(cFaces, cFaceI)
00125             {
00126                 const face& f = mesh.faces()[cFaces[cFaceI]];
00127 
00128                 label nQuads = 0;
00129                 label nTris = 0;
00130                 f.nTrianglesQuads(mesh.points(), nTris, nQuads);
00131 
00132                 nTetDecomp += nTris;
00133                 nPyrDecomp += nQuads;
00134             }
00135 
00136             nAddCells--;
00137             nAddPoints++;
00138 #endif
00139         }
00140     }
00141 
00142 
00143     // we can avoid double looping, but at the cost of allocation
00144     labelList tetCells(nTet);
00145     labelList pyramidCells(nPyr);
00146     labelList prismCells(nPrism);
00147     labelList hexCells(nHex);
00148     labelList polyCells(nPoly);
00149 
00150     nTet   = 0,
00151     nPyr   = 0;
00152     nPrism = 0;
00153     nHex   = 0;
00154     nPoly  = 0;
00155 
00156     // classify the shapes
00157     for (label listI = 0; listI < size_; ++listI)
00158     {
00159         label cellId = listI;
00160         if (limited)
00161         {
00162             cellId = idList[listI];
00163         }
00164 
00165         const cellShape& cellShape = cellShapes[cellId];
00166         const cellModel& cellModel = cellShape.model();
00167 
00168         if (cellModel == tet)
00169         {
00170             tetCells[nTet++] = cellId;
00171         }
00172         else if (cellModel == pyr)
00173         {
00174             pyramidCells[nPyr++] = cellId;
00175         }
00176         else if (cellModel == prism)
00177         {
00178             prismCells[nPrism++] = cellId;
00179         }
00180         else if (cellModel == hex)
00181         {
00182             hexCells[nHex++] = cellId;
00183         }
00184         else
00185         {
00186             polyCells[nPoly++] = cellId;
00187 
00188             // TODO: allow tet-decomposition of polyhedral cells
00189 #if 0
00190             // Mapping from additional point to cell
00191             addPointCellLabels_[api] = cellId;
00192 
00193             const cell& cFaces = mesh.cells()[cellId];
00194 
00195             forAll(cFaces, cFaceI)
00196             {
00197                 const face& f = mesh.faces()[cFaces[cFaceI]];
00198 
00199                 label nQuads = 0;
00200                 label nTris = 0;
00201                 f.nTrianglesQuads(mesh.points(), nTris, nQuads);
00202 
00203                 nTetDecomp += nTris;
00204                 nPyrDecomp += nQuads;
00205             }
00206 
00207             nAddCells--;
00208             nAddPoints++;
00209 #endif
00210         }
00211     }
00212 
00213 
00214     // MUST match with elementTypes
00215     elemLists_.setSize(elementTypes().size());
00216 
00217     elemLists_[tetra4Elements].transfer( tetCells );
00218     elemLists_[pyramid5Elements].transfer( pyramidCells );
00219     elemLists_[penta6Elements].transfer( prismCells );
00220     elemLists_[hexa8Elements].transfer( hexCells );
00221     elemLists_[nfacedElements].transfer( polyCells );
00222 }
00223 
00224 
00225 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00226 
00227 Foam::ensightPartCells::ensightPartCells
00228 (
00229     label partNumber,
00230     const string& partDescription
00231 )
00232 :
00233     ensightPart(partNumber, partDescription)
00234 {}
00235 
00236 
00237 Foam::ensightPartCells::ensightPartCells
00238 (
00239     label partNumber,
00240     const polyMesh& pMesh
00241 )
00242 :
00243     ensightPart(partNumber, "cells", pMesh)
00244 {
00245     classify();
00246 }
00247 
00248 
00249 Foam::ensightPartCells::ensightPartCells
00250 (
00251     label partNumber,
00252     const polyMesh& pMesh,
00253     const labelList& idList
00254 )
00255 :
00256     ensightPart(partNumber, "cells", pMesh)
00257 {
00258     classify(idList);
00259 }
00260 
00261 
00262 Foam::ensightPartCells::ensightPartCells
00263 (
00264     label partNumber,
00265     const polyMesh& pMesh,
00266     const cellZone& cZone
00267 )
00268 :
00269     ensightPart(partNumber, cZone.name(), pMesh)
00270 {
00271     classify(cZone);
00272 }
00273 
00274 
00275 Foam::ensightPartCells::ensightPartCells(const ensightPartCells& part)
00276 :
00277     ensightPart(part)
00278 {}
00279 
00280 
00281 Foam::ensightPartCells::ensightPartCells(Istream& is)
00282 :
00283     ensightPart()
00284 {
00285     reconstruct(is);
00286 }
00287 
00288 
00289 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00290 
00291 Foam::ensightPartCells::~ensightPartCells()
00292 {}
00293 
00294 
00295 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00296 
00297 Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
00298 {
00299     const polyMesh& mesh = *meshPtr_;
00300 
00301     localPoints ptList(mesh);
00302     labelList& usedPoints = ptList.list;
00303     label nPoints = 0;
00304 
00305     forAll(elemLists_, typeI)
00306     {
00307         const labelList& idList = elemLists_[typeI];
00308 
00309         // add all points from cells
00310         forAll(idList, i)
00311         {
00312             label id = idList[i] + offset_;
00313             const labelList& cFaces = mesh.cells()[id];
00314 
00315             forAll(cFaces, cFaceI)
00316             {
00317                 const face& f = mesh.faces()[cFaces[cFaceI]];
00318 
00319                 forAll(f, fp)
00320                 {
00321                     if (usedPoints[f[fp]] == -1)
00322                     {
00323                         usedPoints[f[fp]] = nPoints++;
00324                     }
00325                 }
00326             }
00327         }
00328     }
00329 
00330     // this is not absolutely necessary, but renumber anyhow
00331     nPoints = 0;
00332     forAll(usedPoints, ptI)
00333     {
00334         if (usedPoints[ptI] > -1)
00335         {
00336             usedPoints[ptI] = nPoints++;
00337         }
00338     }
00339 
00340     ptList.nPoints = nPoints;
00341     return ptList;
00342 }
00343 
00344 
00345 void Foam::ensightPartCells::writeConnectivity
00346 (
00347     ensightGeoFile& os,
00348     const string& key,
00349     const labelList& idList,
00350     const labelList& pointMap
00351 ) const
00352 {
00353     os.writeKeyword(key);
00354     os.write(idList.size());
00355     os.newline();
00356 
00357     const polyMesh& mesh = *meshPtr_;
00358 
00359     // write polyhedral
00360     if (word(key) == "nfaced")
00361     {
00362         const faceList& meshFaces = mesh.faces();
00363 
00364         // write the number of faces per element
00365         forAll(idList, i)
00366         {
00367             label id = idList[i] + offset_;
00368             const labelList& cFace = mesh.cells()[id];
00369 
00370             os.write( cFace.size() );
00371             os.newline();
00372         }
00373 
00374         // write the number of points per element face
00375         forAll(idList, i)
00376         {
00377             label id = idList[i] + offset_;
00378             const labelList& cFace = mesh.cells()[id];
00379 
00380             forAll(cFace, faceI)
00381             {
00382                 const face& cf = meshFaces[cFace[faceI]];
00383 
00384                 os.write( cf.size() );
00385                 os.newline();
00386             }
00387         }
00388 
00389         // write the points describing each element face
00390         forAll(idList, i)
00391         {
00392             label id = idList[i] + offset_;
00393             const labelList& cFace = mesh.cells()[id];
00394 
00395             forAll(cFace, faceI)
00396             {
00397                 const face& cf = meshFaces[cFace[faceI]];
00398 
00399                 forAll(cf, ptI)
00400                 {
00401                     // convert global -> local index
00402                     // (note: Ensight indices start with 1)
00403                     os.write( pointMap[cf[ptI]] + 1);
00404                 }
00405                 os.newline();
00406             }
00407         }
00408     }
00409     else
00410     {
00411         // write primitive
00412         const cellShapeList& cellShapes = mesh.cellShapes();
00413 
00414         forAll(idList, i)
00415         {
00416             label id = idList[i] + offset_;
00417             const cellShape& cellPoints = cellShapes[id];
00418 
00419             // convert global -> local index
00420             // (note: Ensight indices start with 1)
00421             forAll(cellPoints, ptI)
00422             {
00423                 os.write( pointMap[cellPoints[ptI]] + 1 );
00424             }
00425             os.newline();
00426         }
00427     }
00428 }
00429 
00430 
00431 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd