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

vtkPV3FoamUpdateInfo.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 "vtkPV3Foam.H"
00028 
00029 // Foam includes
00030 #include "cellSet.H"
00031 #include "faceSet.H"
00032 #include "pointSet.H"
00033 #include "IOobjectList.H"
00034 #include "IOPtrList.H"
00035 #include "polyBoundaryMeshEntries.H"
00036 #include "entry.H"
00037 #include "Cloud.H"
00038 #include "vtkPV3FoamReader.h"
00039 
00040 // local headers
00041 #include "vtkPV3FoamAddToSelection.H"
00042 #include "vtkPV3FoamUpdateInfoFields.H"
00043 
00044 // VTK includes
00045 #include "vtkDataArraySelection.h"
00046 
00047 
00048 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 //- A class for reading zone information without requiring a mesh
00054 class zonesEntries
00055 :
00056     public regIOobject,
00057     public PtrList<entry>
00058 {
00059 
00060 public:
00061 
00062     // Constructors
00063 
00064         explicit zonesEntries(const IOobject& io)
00065         :
00066             regIOobject(io),
00067             PtrList<entry>(readStream("regIOobject"))
00068         {
00069             close();
00070         }
00071 
00072    // Member functions
00073 
00074         bool writeData(Ostream&) const
00075         {
00076             notImplemented("zonesEntries::writeData(Ostream&) const");
00077             return false;
00078         }
00079 };
00080 
00081 }
00082 
00083 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00084 
00085 Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
00086 {
00087     wordList zoneNames;
00088 
00089     // mesh not loaded - read from file
00090     IOobject ioObj
00091     (
00092         zoneType,
00093         dbPtr_().findInstance
00094         (
00095             meshDir_,
00096             zoneType,
00097             IOobject::READ_IF_PRESENT
00098         ),
00099         meshDir_,
00100         dbPtr_(),
00101         IOobject::READ_IF_PRESENT,
00102         IOobject::NO_WRITE,
00103         false
00104     );
00105 
00106     if (ioObj.headerOk())
00107     {
00108         zonesEntries zones(ioObj);
00109 
00110         zoneNames.setSize(zones.size());
00111         forAll(zones, zoneI)
00112         {
00113             zoneNames[zoneI] = zones[zoneI].keyword();
00114         }
00115     }
00116 
00117     return zoneNames;
00118 }
00119 
00120 
00121 void Foam::vtkPV3Foam::updateInfoInternalMesh()
00122 {
00123     if (debug)
00124     {
00125         Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
00126     }
00127 
00128     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
00129 
00130     // Determine mesh parts (internalMesh, patches...)
00131     //- Add internal mesh as first entry
00132     partInfoVolume_ = partSelection->GetNumberOfArrays();
00133     partSelection->AddArray("internalMesh");
00134     partInfoVolume_ += 1;
00135 
00136     if (debug)
00137     {
00138         // just for debug info
00139         getSelectedArrayEntries(partSelection);
00140 
00141         Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
00142     }
00143 
00144 }
00145 
00146 
00147 void Foam::vtkPV3Foam::updateInfoLagrangian()
00148 {
00149     if (debug)
00150     {
00151         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
00152             << "    " << dbPtr_->timePath()/cloud::prefix << endl;
00153     }
00154 
00155 
00156     // use the db directly since this might be called without a mesh,
00157     // but the region must get added back in
00158     fileName lagrangianPrefix(cloud::prefix);
00159     if (meshRegion_ != polyMesh::defaultRegion)
00160     {
00161         lagrangianPrefix = meshRegion_/cloud::prefix;
00162     }
00163 
00164     // Search for list of lagrangian objects for this time
00165     fileNameList cloudDirs
00166     (
00167         readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
00168     );
00169 
00170     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
00171     partInfoLagrangian_ = partSelection->GetNumberOfArrays();
00172 
00173     int nClouds = 0;
00174     forAll(cloudDirs, cloudI)
00175     {
00176         // Add cloud to GUI list
00177         partSelection->AddArray
00178         (
00179             (cloudDirs[cloudI] + " - lagrangian").c_str()
00180         );
00181 
00182         ++nClouds;
00183     }
00184 
00185     partInfoLagrangian_ += nClouds;
00186 
00187     if (debug)
00188     {
00189         // just for debug info
00190         getSelectedArrayEntries(partSelection);
00191 
00192         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
00193     }
00194 }
00195 
00196 
00197 void Foam::vtkPV3Foam::updateInfoPatches()
00198 {
00199     if (debug)
00200     {
00201         Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
00202             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
00203     }
00204 
00205     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
00206     partInfoPatches_ = partSelection->GetNumberOfArrays();
00207 
00208     int nPatches = 0;
00209     if (meshPtr_)
00210     {
00211         const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
00212         forAll(patches, patchI)
00213         {
00214             const polyPatch& pp = patches[patchI];
00215 
00216             if (pp.size())
00217             {
00218                 // Add patch to GUI list
00219                 partSelection->AddArray
00220                 (
00221                     (pp.name() + " - patch").c_str()
00222                 );
00223 
00224                 ++nPatches;
00225             }
00226         }
00227     }
00228     else
00229     {
00230         // mesh not loaded - read from file
00231         // but this could fail if we've supplied a bad region name
00232         IOobject ioObj
00233         (
00234             "boundary",
00235             dbPtr_().findInstance
00236             (
00237                 meshDir_,
00238                 "boundary",
00239                 IOobject::READ_IF_PRESENT
00240             ),
00241             meshDir_,
00242             dbPtr_(),
00243             IOobject::READ_IF_PRESENT,
00244             IOobject::NO_WRITE,
00245             false
00246         );
00247 
00248         // this should only ever fail if the mesh region doesn't exist
00249         if (ioObj.headerOk())
00250         {
00251             polyBoundaryMeshEntries patchEntries(ioObj);
00252 
00253             // Add (non-zero) patches to the list of mesh parts
00254             forAll(patchEntries, entryI)
00255             {
00256                 label nFaces
00257                 (
00258                     readLabel(patchEntries[entryI].dict().lookup("nFaces"))
00259                 );
00260 
00261                 // Valid patch if nFace > 0 - add patch to GUI list
00262                 if (nFaces)
00263                 {
00264                     partSelection->AddArray
00265                     (
00266                         (patchEntries[entryI].keyword() + " - patch").c_str()
00267                     );
00268 
00269                     ++nPatches;
00270                 }
00271             }
00272         }
00273     }
00274     partInfoPatches_ += nPatches;
00275 
00276     if (debug)
00277     {
00278         // just for debug info
00279         getSelectedArrayEntries(partSelection);
00280 
00281         Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
00282     }
00283 }
00284 
00285 
00286 void Foam::vtkPV3Foam::updateInfoZones()
00287 {
00288     if (!reader_->GetIncludeZones())
00289     {
00290         return;
00291     }
00292 
00293     if (debug)
00294     {
00295         Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
00296             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
00297     }
00298 
00299     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
00300     wordList namesLst;
00301 
00302     //
00303     // cellZones information
00304     // ~~~~~~~~~~~~~~~~~~~~~
00305     if (meshPtr_)
00306     {
00307         namesLst = meshPtr_->cellZones().names();
00308     }
00309     else
00310     {
00311         namesLst = readZoneNames("cellZones");
00312     }
00313 
00314     partInfoCellZones_ = partSelection->GetNumberOfArrays();
00315     forAll(namesLst, elemI)
00316     {
00317         partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
00318     }
00319     partInfoCellZones_ += namesLst.size();
00320 
00321 
00322     //
00323     // faceZones information
00324     // ~~~~~~~~~~~~~~~~~~~~~
00325     if (meshPtr_)
00326     {
00327         namesLst = meshPtr_->faceZones().names();
00328     }
00329     else
00330     {
00331         namesLst = readZoneNames("faceZones");
00332     }
00333 
00334     partInfoFaceZones_ = partSelection->GetNumberOfArrays();
00335     forAll(namesLst, elemI)
00336     {
00337         partSelection->AddArray
00338         (
00339             (namesLst[elemI] + " - faceZone").c_str()
00340         );
00341     }
00342     partInfoFaceZones_ += namesLst.size();
00343 
00344 
00345     //
00346     // pointZones information
00347     // ~~~~~~~~~~~~~~~~~~~~~~
00348     if (meshPtr_)
00349     {
00350         namesLst = meshPtr_->pointZones().names();
00351     }
00352     else
00353     {
00354         namesLst = readZoneNames("pointZones");
00355     }
00356 
00357     partInfoPointZones_ = partSelection->GetNumberOfArrays();
00358     forAll(namesLst, elemI)
00359     {
00360         partSelection->AddArray
00361         (
00362             (namesLst[elemI] + " - pointZone").c_str()
00363         );
00364     }
00365     partInfoPointZones_ += namesLst.size();
00366 
00367 
00368     if (debug)
00369     {
00370         // just for debug info
00371         getSelectedArrayEntries(partSelection);
00372 
00373         Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
00374     }
00375 }
00376 
00377 
00378 void Foam::vtkPV3Foam::updateInfoSets()
00379 {
00380     if (!reader_->GetIncludeSets())
00381     {
00382         return;
00383     }
00384 
00385     if (debug)
00386     {
00387         Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
00388     }
00389 
00390     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
00391 
00392     // Add names of sets
00393     IOobjectList objects
00394     (
00395         dbPtr_(),
00396         dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
00397         meshDir_/"sets"
00398     );
00399 
00400 
00401     partInfoCellSets_ = partSelection->GetNumberOfArrays();
00402     partInfoCellSets_ += addToSelection<cellSet>
00403     (
00404         partSelection,
00405         objects,
00406         " - cellSet"
00407     );
00408 
00409     partInfoFaceSets_ = partSelection->GetNumberOfArrays();
00410     partInfoFaceSets_ += addToSelection<faceSet>
00411     (
00412         partSelection,
00413         objects,
00414         " - faceSet"
00415     );
00416 
00417     partInfoPointSets_ = partSelection->GetNumberOfArrays();
00418     partInfoPointSets_ += addToSelection<pointSet>
00419     (
00420         partSelection,
00421         objects,
00422         " - pointSet"
00423     );
00424 
00425     if (debug)
00426     {
00427         // just for debug info
00428         getSelectedArrayEntries(partSelection);
00429 
00430         Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
00431     }
00432 }
00433 
00434 
00435 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
00436 {
00437     if (debug)
00438     {
00439         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
00440             << endl;
00441     }
00442 
00443     vtkDataArraySelection *fieldSelection =
00444         reader_->GetLagrangianFieldSelection();
00445 
00446     // preserve the enabled selections
00447     stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
00448     fieldSelection->RemoveAllArrays();
00449 
00450     //
00451     // TODO - currently only get fields from ONE cloud
00452     // have to decide if the second set of fields get mixed in
00453     // or dealt with separately
00454 
00455     const partInfo& selector = partInfoLagrangian_;
00456     int partId = selector.start();
00457 
00458     if (!selector.size() || partId < 0)
00459     {
00460         return;
00461     }
00462 
00463     word cloudName = getPartName(partId);
00464 
00465     // use the db directly since this might be called without a mesh,
00466     // but the region must get added back in
00467     fileName lagrangianPrefix(cloud::prefix);
00468     if (meshRegion_ != polyMesh::defaultRegion)
00469     {
00470         lagrangianPrefix = meshRegion_/cloud::prefix;
00471     }
00472 
00473     IOobjectList objects
00474     (
00475         dbPtr_(),
00476         dbPtr_().timeName(),
00477         lagrangianPrefix/cloudName
00478     );
00479 
00480     addToSelection<IOField<label> >
00481     (
00482         fieldSelection,
00483         objects
00484     );
00485     addToSelection<IOField<scalar> >
00486     (
00487         fieldSelection,
00488         objects
00489     );
00490     addToSelection<IOField<vector> >
00491     (
00492         fieldSelection,
00493         objects
00494     );
00495     addToSelection<IOField<sphericalTensor> >
00496     (
00497         fieldSelection,
00498 
00499         objects
00500     );
00501     addToSelection<IOField<symmTensor> >
00502     (
00503         fieldSelection,
00504         objects
00505     );
00506     addToSelection<IOField<tensor> >
00507     (
00508         fieldSelection,
00509         objects
00510     );
00511 
00512     // restore the enabled selections
00513     setSelectedArrayEntries(fieldSelection, enabledEntries);
00514 
00515     if (debug)
00516     {
00517         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
00518             << "lagrangian objects.size() = " << objects.size() << endl;
00519     }
00520 }
00521 
00522 
00523 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd