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

ensightPartFaces.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 "ensightPartFaces.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "IOstreams.H"
00030 #include "IStringStream.H"
00031 #include "dictionary.H"
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037    defineTypeNameAndDebug(ensightPartFaces, 0);
00038    addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
00039 }
00040 
00041 
00042 Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_
00043 (
00044     IStringStream
00045     (
00046         "(tria3 quad4 nsided)"
00047     )()
00048 );
00049 
00050 
00051 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00052 
00053 Foam::ensightPartFaces::ensightPartFaces
00054 (
00055     label partNumber,
00056     const string& partDescription
00057 )
00058 :
00059     ensightPart(partNumber, partDescription)
00060 {
00061     isCellData_ = false;
00062 }
00063 
00064 
00065 Foam::ensightPartFaces::ensightPartFaces
00066 (
00067     label partNumber,
00068     const polyMesh& pMesh,
00069     const polyPatch& pPatch
00070 )
00071 :
00072     ensightPart(partNumber, pPatch.name(), pMesh)
00073 {
00074     isCellData_ = false;
00075     offset_ = pPatch.start();
00076     size_ = pPatch.size();
00077 
00078     // count the shapes
00079     label nTri  = 0;
00080     label nQuad = 0;
00081     label nPoly = 0;
00082 
00083     forAll (pPatch, patchfaceI)
00084     {
00085         const face& f = pMesh.faces()[patchfaceI + offset_];
00086 
00087         if (f.size() == 3)
00088         {
00089             nTri++;
00090         }
00091         else if (f.size() == 4)
00092         {
00093             nQuad++;
00094         }
00095         else
00096         {
00097             nPoly++;
00098         }
00099     }
00100 
00101     // we can avoid double looping, but at the cost of allocation
00102 
00103     labelList triCells(nTri);
00104     labelList quadCells(nQuad);
00105     labelList polygonCells(nPoly);
00106 
00107     nTri  = 0;
00108     nQuad = 0;
00109     nPoly = 0;
00110 
00111     // classify the shapes
00112     forAll(pPatch, patchfaceI)
00113     {
00114         const face& f = pMesh.faces()[patchfaceI + offset_];
00115 
00116         if (f.size() == 3)
00117         {
00118             triCells[nTri++] = patchfaceI;
00119         }
00120         else if (f.size() == 4)
00121         {
00122             quadCells[nQuad++] = patchfaceI;
00123         }
00124         else
00125         {
00126             polygonCells[nPoly++] = patchfaceI;
00127         }
00128     }
00129 
00130 
00131     // MUST match with elementTypes
00132     elemLists_.setSize(elementTypes().size());
00133 
00134     elemLists_[tria3Elements].transfer( triCells );
00135     elemLists_[quad4Elements].transfer( quadCells );
00136     elemLists_[nsidedElements].transfer( polygonCells );
00137 }
00138 
00139 
00140 Foam::ensightPartFaces::ensightPartFaces(const ensightPartFaces &part)
00141 :
00142     ensightPart(part)
00143 {}
00144 
00145 
00146 Foam::ensightPartFaces::ensightPartFaces(Istream& is)
00147 :
00148     ensightPart()
00149 {
00150     isCellData_ = false;
00151     reconstruct(is);
00152 }
00153 
00154 
00155 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00156 
00157 Foam::ensightPartFaces::~ensightPartFaces()
00158 {}
00159 
00160 
00161 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00162 
00163 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
00164 {
00165     const polyMesh& mesh = *meshPtr_;
00166 
00167     localPoints ptList(mesh);
00168     labelList& usedPoints = ptList.list;
00169     label nPoints = 0;
00170 
00171     forAll(elemLists_, typeI)
00172     {
00173         const labelList& idList = elemLists_[typeI];
00174 
00175         // add all points from faces
00176         forAll(idList, i)
00177         {
00178             label id = idList[i] + offset_;
00179             const face& f = mesh.faces()[id];
00180 
00181             forAll(f, fp)
00182             {
00183                 if (usedPoints[f[fp]] == -1)
00184                 {
00185                     usedPoints[f[fp]] = nPoints++;
00186                 }
00187             }
00188         }
00189     }
00190 
00191     // this is not absolutely necessary, but renumber anyhow
00192     nPoints = 0;
00193     forAll(usedPoints, ptI)
00194     {
00195         if (usedPoints[ptI] > -1)
00196         {
00197             usedPoints[ptI] = nPoints++;
00198         }
00199     }
00200 
00201     ptList.nPoints = nPoints;
00202     return ptList;
00203 }
00204 
00205 
00206 void Foam::ensightPartFaces::writeConnectivity
00207 (
00208     ensightGeoFile& os,
00209     const string& key,
00210     const labelList& idList,
00211     const labelList& pointMap
00212 ) const
00213 {
00214     os.writeKeyword(key);
00215     os.write(idList.size());
00216     os.newline();
00217 
00218     const faceList& meshFaces = meshPtr_->faces();
00219 
00220     // write (polygon) face sizes
00221     if (word(key) == "nsided")
00222     {
00223         // write the number of points per face
00224         forAll(idList, i)
00225         {
00226             label id = idList[i] + offset_;
00227             const face& f = meshFaces[id];
00228 
00229             os.write( f.size() );
00230             os.newline();
00231         }
00232     }
00233 
00234     // write the points describing the face
00235     forAll(idList, i)
00236     {
00237         label id = idList[i] + offset_;
00238         const face& f = meshFaces[id];
00239 
00240         // convert global -> local index
00241         // (note: Ensight indices start with 1)
00242         forAll(f, fp)
00243         {
00244             os.write( pointMap[f[fp]] + 1 );
00245         }
00246         os.newline();
00247     }
00248 }
00249 
00250 
00251 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd