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

ensightParts.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 <conversion/ensightParts.H>
00027 
00028 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00029 
00030 Foam::ensightParts::ensightParts(const polyMesh& pMesh)
00031 :
00032     partsList_()
00033 {
00034     recalculate(pMesh);
00035 }
00036 
00037 
00038 Foam::ensightParts::ensightParts(const IOobject& ioObj)
00039 :
00040     partsList_()
00041 {
00042     IOPtrList<ensightPart> ioList(ioObj);
00043     partsList_.transfer(ioList);
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00048 
00049 Foam::ensightParts::~ensightParts()
00050 {}
00051 
00052 
00053 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00054 
00055 void Foam::ensightParts::recalculate(const polyMesh& pMesh)
00056 {
00057     partsList_.clear();
00058 
00059     // extra space for unzoned cells
00060     label nPart =
00061     (
00062         pMesh.cellZones().size()
00063       + pMesh.boundaryMesh().size()
00064       + 1
00065     );
00066 
00067     partsList_.setSize(nPart);
00068     nPart = 0;
00069 
00070     label nZoneCells = 0;
00071 
00072     // do cell zones
00073     forAll(pMesh.cellZones(), zoneI)
00074     {
00075         const cellZone& cZone = pMesh.cellZones()[zoneI];
00076         nZoneCells += cZone.size();
00077 
00078         if (cZone.size())
00079         {
00080             partsList_.set
00081             (
00082                 nPart,
00083                 new ensightPartCells
00084                 (
00085                     nPart,
00086                     pMesh,
00087                     cZone
00088                 )
00089             );
00090 
00091             nPart++;
00092         }
00093     }
00094 
00095     // collect unzoned cells
00096 
00097     // special case: no zones at all - do entire mesh
00098     if (nZoneCells == 0)
00099     {
00100         partsList_.set
00101         (
00102             nPart,
00103             new ensightPartCells
00104             (
00105                 nPart,
00106                 pMesh
00107             )
00108         );
00109 
00110         nPart++;
00111     }
00112     else if (pMesh.nCells() > nZoneCells)
00113     {
00114         // determine which cells are not in a cellZone
00115         labelList unzoned(pMesh.nCells(), -1);
00116 
00117         forAll(pMesh.cellZones(), zoneI)
00118         {
00119             const labelList& idList = pMesh.cellZones()[zoneI];
00120 
00121             forAll(idList, i)
00122             {
00123                 unzoned[idList[i]] = idList[i];
00124             }
00125         }
00126 
00127         label nUnzoned = 0;
00128         forAll(unzoned, i)
00129         {
00130             if (unzoned[i] < 0)
00131             {
00132                 unzoned[nUnzoned] = i;
00133                 nUnzoned++;
00134             }
00135         }
00136         unzoned.setSize(nUnzoned);
00137 
00138         if (unzoned.size())
00139         {
00140             partsList_.set
00141             (
00142                 nPart,
00143                 new ensightPartCells
00144                 (
00145                     nPart,
00146                     pMesh,
00147                     unzoned
00148                 )
00149             );
00150 
00151             nPart++;
00152         }
00153     }
00154 
00155 
00156     // do boundaries, skipping empty and processor patches
00157     forAll(pMesh.boundaryMesh(), patchI)
00158     {
00159         const polyPatch& pPatch = pMesh.boundaryMesh()[patchI];
00160         if (pPatch.size() && !isA<processorPolyPatch>(pPatch))
00161         {
00162             partsList_.set
00163             (
00164                 nPart,
00165                 new ensightPartFaces
00166                 (
00167                     nPart,
00168                     pMesh,
00169                     pPatch
00170                 )
00171             );
00172 
00173             nPart++;
00174         }
00175     }
00176 
00177     // truncate to correct size
00178     partsList_.setSize(nPart);
00179 }
00180 
00181 
00182 void Foam::ensightParts::renumber
00183 (
00184     const labelList& origCellId,
00185     const labelList& origFaceId
00186 )
00187 {
00188     forAll(partsList_, partI)
00189     {
00190         if (partsList_[partI].isCellData())
00191         {
00192             partsList_[partI].renumber(origCellId);
00193         }
00194         else
00195         {
00196             partsList_[partI].renumber(origFaceId);
00197         }
00198     }
00199 }
00200 
00201 
00202 void Foam::ensightParts::writeGeometry( ensightGeoFile& os) const
00203 {
00204     // with some feedback
00205     Info<< "write geometry part:" << nl << flush;
00206 
00207     forAll(partsList_, partI)
00208     {
00209         Info<< " " << partI << flush;
00210         partsList_[partI].writeGeometry(os);
00211     }
00212 }
00213 
00214 
00215 bool Foam::ensightParts::writeSummary(Ostream& os) const
00216 {
00217     forAll(partsList_, partI)
00218     {
00219         partsList_[partI].writeSummary(os);
00220     }
00221 
00222     return true;
00223 }
00224 
00225 
00226 void Foam::ensightParts::writeData(Ostream& os) const
00227 {
00228     // Write size of list
00229     os << nl << partsList_.size();
00230 
00231     // Write beginning of contents
00232     os << nl << token::BEGIN_LIST;
00233 
00234     // Write list contents
00235     forAll(partsList_, i)
00236     {
00237         os << nl << partsList_[i];
00238     }
00239 
00240     // Write end of contents
00241     os << nl << token::END_LIST << nl;
00242 
00243     // Check state of IOstream
00244     os.check("Ostream& operator<<(Ostream&, const PtrList&)");
00245 }
00246 
00247 
00248 void Foam::ensightParts::writeScalarField
00249 (
00250     ensightFile& os,
00251     const List<scalar>& field,
00252     bool useFaceData
00253 ) const
00254 {
00255     forAll(partsList_, partI)
00256     {
00257         if
00258         (
00259             useFaceData
00260           ? partsList_[partI].isFaceData()
00261           : partsList_[partI].isCellData()
00262         )
00263         {
00264             partsList_[partI].writeScalarField(os,field);
00265         }
00266     }
00267 }
00268 
00269 
00270 void Foam::ensightParts::writeVectorField
00271 (
00272     ensightFile& os,
00273     const List<scalar>& field0,
00274     const List<scalar>& field1,
00275     const List<scalar>& field2,
00276     bool useFaceData
00277 ) const
00278 {
00279     forAll(partsList_, partI)
00280     {
00281         if
00282         (
00283             useFaceData
00284           ? partsList_[partI].isFaceData()
00285           : partsList_[partI].isCellData()
00286         )
00287         {
00288             partsList_[partI].writeVectorField(os, field0, field1, field2);
00289         }
00290     }
00291 }
00292 
00293 
00294 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
00295 
00296 Foam::ensightGeoFile& Foam::operator<<
00297 (
00298     ensightGeoFile& os,
00299     const ensightParts& parts
00300 )
00301 {
00302     parts.writeGeometry(os);
00303     return os;
00304 }
00305 
00306 
00307 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines