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

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