1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "vtkPV3Foam.H"
32 #include "IOobjectList.H"
33 #include "IOPtrList.H"
34 #include "polyBoundaryMeshEntries.H"
37 #include "vtkPV3FoamReader.h"
40 #include "vtkPV3FoamAddToSelection.H"
41 #include "vtkPV3FoamUpdateInfoFields.H"
44 #include "vtkDataArraySelection.h"
47 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
52 //- A class for reading zone information without requiring a mesh
63 explicit zonesEntries(const IOobject& io)
66 PtrList<entry>(readStream("regIOobject"))
73 bool writeData(Ostream&) const
75 notImplemented("zonesEntries::writeData(Ostream&) const");
82 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
84 template<class ZoneType>
85 Foam::wordList Foam::vtkPV3Foam::getZoneNames
87 const ZoneMesh<ZoneType, polyMesh>& zmesh
90 wordList names(zmesh.size());
95 if (zmesh[zoneI].size())
97 names[nZone++] = zmesh[zoneI].name();
100 names.setSize(nZone);
106 Foam::wordList Foam::vtkPV3Foam::getZoneNames(const word& zoneType) const
110 // mesh not loaded - read from file
114 dbPtr_().findInstance
118 IOobject::READ_IF_PRESENT
122 IOobject::READ_IF_PRESENT,
127 if (ioObj.headerOk())
129 zonesEntries zones(ioObj);
131 names.setSize(zones.size());
134 names[zoneI] = zones[zoneI].keyword();
142 void Foam::vtkPV3Foam::updateInfoInternalMesh
144 vtkDataArraySelection* arraySelection
149 Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
152 // Determine mesh parts (internalMesh, patches...)
153 //- Add internal mesh as first entry
154 arrayRangeVolume_.reset(arraySelection->GetNumberOfArrays());
155 arraySelection->AddArray
159 arrayRangeVolume_ += 1;
163 // just for debug info
164 getSelectedArrayEntries(arraySelection);
166 Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
171 void Foam::vtkPV3Foam::updateInfoLagrangian
173 vtkDataArraySelection* arraySelection
178 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
179 << " " << dbPtr_->timePath()/cloud::prefix << endl;
183 // use the db directly since this might be called without a mesh,
184 // but the region must get added back in
185 fileName lagrangianPrefix(cloud::prefix);
186 if (meshRegion_ != polyMesh::defaultRegion)
188 lagrangianPrefix = meshRegion_/cloud::prefix;
191 // Search for list of lagrangian objects for this time
192 fileNameList cloudDirs
194 readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
197 arrayRangeLagrangian_.reset(arraySelection->GetNumberOfArrays());
200 forAll(cloudDirs, cloudI)
202 // Add cloud to GUI list
203 arraySelection->AddArray
205 (cloudDirs[cloudI] + " - lagrangian").c_str()
210 arrayRangeLagrangian_ += nClouds;
214 // just for debug info
215 getSelectedArrayEntries(arraySelection);
217 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
222 void Foam::vtkPV3Foam::updateInfoPatches
224 vtkDataArraySelection* arraySelection
229 Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
230 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
233 arrayRangePatches_.reset(arraySelection->GetNumberOfArrays());
238 const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
239 forAll(patches, patchI)
241 const polyPatch& pp = patches[patchI];
245 // Add patch to GUI list
246 arraySelection->AddArray
248 (pp.name() + " - patch").c_str()
257 // mesh not loaded - read from file
258 // but this could fail if we've supplied a bad region name
262 dbPtr_().findInstance
266 IOobject::READ_IF_PRESENT
270 IOobject::READ_IF_PRESENT,
275 // this should only ever fail if the mesh region doesn't exist
276 if (ioObj.headerOk())
278 polyBoundaryMeshEntries patchEntries(ioObj);
280 // Add (non-zero) patches to the list of mesh parts
281 forAll(patchEntries, entryI)
285 readLabel(patchEntries[entryI].dict().lookup("nFaces"))
288 // Valid patch if nFace > 0 - add patch to GUI list
291 arraySelection->AddArray
293 (patchEntries[entryI].keyword() + " - patch").c_str()
301 arrayRangePatches_ += nPatches;
305 // just for debug info
306 getSelectedArrayEntries(arraySelection);
308 Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
313 void Foam::vtkPV3Foam::updateInfoZones
315 vtkDataArraySelection* arraySelection
318 if (!reader_->GetIncludeZones())
325 Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
326 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
332 // cellZones information
333 // ~~~~~~~~~~~~~~~~~~~~~
336 namesLst = getZoneNames(meshPtr_->cellZones());
340 namesLst = getZoneNames("cellZones");
343 arrayRangeCellZones_.reset(arraySelection->GetNumberOfArrays());
344 forAll(namesLst, elemI)
346 arraySelection->AddArray
348 (namesLst[elemI] + " - cellZone").c_str()
351 arrayRangeCellZones_ += namesLst.size();
355 // faceZones information
356 // ~~~~~~~~~~~~~~~~~~~~~
359 namesLst = getZoneNames(meshPtr_->faceZones());
363 namesLst = getZoneNames("faceZones");
366 arrayRangeFaceZones_.reset(arraySelection->GetNumberOfArrays());
367 forAll(namesLst, elemI)
369 arraySelection->AddArray
371 (namesLst[elemI] + " - faceZone").c_str()
374 arrayRangeFaceZones_ += namesLst.size();
378 // pointZones information
379 // ~~~~~~~~~~~~~~~~~~~~~~
382 namesLst = getZoneNames(meshPtr_->pointZones());
386 namesLst = getZoneNames("pointZones");
389 arrayRangePointZones_.reset(arraySelection->GetNumberOfArrays());
390 forAll(namesLst, elemI)
392 arraySelection->AddArray
394 (namesLst[elemI] + " - pointZone").c_str()
397 arrayRangePointZones_ += namesLst.size();
401 // just for debug info
402 getSelectedArrayEntries(arraySelection);
404 Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
409 void Foam::vtkPV3Foam::updateInfoSets
411 vtkDataArraySelection* arraySelection
414 if (!reader_->GetIncludeSets())
421 Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
424 // Add names of sets. Search for last time directory with a sets
425 // subdirectory. Take care not to search beyond the last mesh.
427 word facesInstance = dbPtr_().findInstance
431 IOobject::READ_IF_PRESENT
434 word setsInstance = dbPtr_().findInstance
438 IOobject::READ_IF_PRESENT,
442 IOobjectList objects(dbPtr_(), setsInstance, meshDir_/"sets");
446 Info<< " Foam::vtkPV3Foam::updateInfoSets read "
447 << objects.names() << " from " << setsInstance << endl;
451 arrayRangeCellSets_.reset(arraySelection->GetNumberOfArrays());
452 arrayRangeCellSets_ += addToSelection<cellSet>
459 arrayRangeFaceSets_.reset(arraySelection->GetNumberOfArrays());
460 arrayRangeFaceSets_ += addToSelection<faceSet>
467 arrayRangePointSets_.reset(arraySelection->GetNumberOfArrays());
468 arrayRangePointSets_ += addToSelection<pointSet>
477 // just for debug info
478 getSelectedArrayEntries(arraySelection);
480 Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
485 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
489 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
493 vtkDataArraySelection* fieldSelection =
494 reader_->GetLagrangianFieldSelection();
496 // preserve the enabled selections
497 stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
498 fieldSelection->RemoveAllArrays();
500 // TODO - currently only get fields from ONE cloud
501 // have to decide if the second set of fields get mixed in
502 // or dealt with separately
504 const arrayRange& range = arrayRangeLagrangian_;
510 int partId = range.start();
511 word cloudName = getPartName(partId);
513 // use the db directly since this might be called without a mesh,
514 // but the region must get added back in
515 fileName lagrangianPrefix(cloud::prefix);
516 if (meshRegion_ != polyMesh::defaultRegion)
518 lagrangianPrefix = meshRegion_/cloud::prefix;
525 lagrangianPrefix/cloudName
528 addToSelection<IOField<label> >
533 addToSelection<IOField<scalar> >
538 addToSelection<IOField<vector> >
543 addToSelection<IOField<sphericalTensor> >
549 addToSelection<IOField<symmTensor> >
554 addToSelection<IOField<tensor> >
560 // restore the enabled selections
561 setSelectedArrayEntries(fieldSelection, enabledEntries);
565 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
566 << "lagrangian objects.size() = " << objects.size() << endl;
571 // ************************************************************************* //