1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "vtkPV3Foam.H"
33 #include "IOobjectList.H"
34 #include "IOPtrList.H"
35 #include "polyBoundaryMeshEntries.H"
38 #include "vtkPV3FoamReader.h"
41 #include "vtkPV3FoamAddToSelection.H"
42 #include "vtkPV3FoamUpdateInfoFields.H"
45 #include "vtkDataArraySelection.h"
48 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
53 //- A class for reading zone information without requiring a mesh
64 explicit zonesEntries(const IOobject& io)
67 PtrList<entry>(readStream("regIOobject"))
74 bool writeData(Ostream&) const
76 notImplemented("zonesEntries::writeData(Ostream&) const");
83 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
85 Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
89 // mesh not loaded - read from file
97 IOobject::READ_IF_PRESENT
101 IOobject::READ_IF_PRESENT,
106 if (ioObj.headerOk())
108 zonesEntries zones(ioObj);
110 zoneNames.setSize(zones.size());
113 zoneNames[zoneI] = zones[zoneI].keyword();
121 void Foam::vtkPV3Foam::updateInfoInternalMesh()
125 Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
128 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
130 // Determine mesh parts (internalMesh, patches...)
131 //- Add internal mesh as first entry
132 partInfoVolume_ = partSelection->GetNumberOfArrays();
133 partSelection->AddArray("internalMesh");
134 partInfoVolume_ += 1;
138 // just for debug info
139 getSelectedArrayEntries(partSelection);
141 Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
147 void Foam::vtkPV3Foam::updateInfoLagrangian()
151 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
152 << " " << dbPtr_->timePath()/cloud::prefix << endl;
156 // use the db directly since this might be called without a mesh,
157 // but the region must get added back in
158 fileName lagrangianPrefix(cloud::prefix);
159 if (meshRegion_ != polyMesh::defaultRegion)
161 lagrangianPrefix = meshRegion_/cloud::prefix;
164 // Search for list of lagrangian objects for this time
165 fileNameList cloudDirs
167 readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
170 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
171 partInfoLagrangian_ = partSelection->GetNumberOfArrays();
174 forAll(cloudDirs, cloudI)
176 // Add cloud to GUI list
177 partSelection->AddArray
179 (cloudDirs[cloudI] + " - lagrangian").c_str()
185 partInfoLagrangian_ += nClouds;
189 // just for debug info
190 getSelectedArrayEntries(partSelection);
192 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
197 void Foam::vtkPV3Foam::updateInfoPatches()
201 Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
202 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
205 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
206 partInfoPatches_ = partSelection->GetNumberOfArrays();
211 const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
212 forAll(patches, patchI)
214 const polyPatch& pp = patches[patchI];
218 // Add patch to GUI list
219 partSelection->AddArray
221 (pp.name() + " - patch").c_str()
230 // mesh not loaded - read from file
231 // but this could fail if we've supplied a bad region name
235 dbPtr_().findInstance
239 IOobject::READ_IF_PRESENT
243 IOobject::READ_IF_PRESENT,
248 // this should only ever fail if the mesh region doesn't exist
249 if (ioObj.headerOk())
251 polyBoundaryMeshEntries patchEntries(ioObj);
253 // Add (non-zero) patches to the list of mesh parts
254 forAll(patchEntries, entryI)
258 readLabel(patchEntries[entryI].dict().lookup("nFaces"))
261 // Valid patch if nFace > 0 - add patch to GUI list
264 partSelection->AddArray
266 (patchEntries[entryI].keyword() + " - patch").c_str()
274 partInfoPatches_ += nPatches;
278 // just for debug info
279 getSelectedArrayEntries(partSelection);
281 Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
286 void Foam::vtkPV3Foam::updateInfoZones()
288 if (!reader_->GetIncludeZones())
295 Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
296 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
299 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
303 // cellZones information
304 // ~~~~~~~~~~~~~~~~~~~~~
307 namesLst = meshPtr_->cellZones().names();
311 namesLst = readZoneNames("cellZones");
314 partInfoCellZones_ = partSelection->GetNumberOfArrays();
315 forAll(namesLst, elemI)
317 partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
319 partInfoCellZones_ += namesLst.size();
323 // faceZones information
324 // ~~~~~~~~~~~~~~~~~~~~~
327 namesLst = meshPtr_->faceZones().names();
331 namesLst = readZoneNames("faceZones");
334 partInfoFaceZones_ = partSelection->GetNumberOfArrays();
335 forAll(namesLst, elemI)
337 partSelection->AddArray
339 (namesLst[elemI] + " - faceZone").c_str()
342 partInfoFaceZones_ += namesLst.size();
346 // pointZones information
347 // ~~~~~~~~~~~~~~~~~~~~~~
350 namesLst = meshPtr_->pointZones().names();
354 namesLst = readZoneNames("pointZones");
357 partInfoPointZones_ = partSelection->GetNumberOfArrays();
358 forAll(namesLst, elemI)
360 partSelection->AddArray
362 (namesLst[elemI] + " - pointZone").c_str()
365 partInfoPointZones_ += namesLst.size();
370 // just for debug info
371 getSelectedArrayEntries(partSelection);
373 Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
378 void Foam::vtkPV3Foam::updateInfoSets()
380 if (!reader_->GetIncludeSets())
387 Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
390 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
396 dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
401 partInfoCellSets_ = partSelection->GetNumberOfArrays();
402 partInfoCellSets_ += addToSelection<cellSet>
409 partInfoFaceSets_ = partSelection->GetNumberOfArrays();
410 partInfoFaceSets_ += addToSelection<faceSet>
417 partInfoPointSets_ = partSelection->GetNumberOfArrays();
418 partInfoPointSets_ += addToSelection<pointSet>
427 // just for debug info
428 getSelectedArrayEntries(partSelection);
430 Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
435 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
439 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
443 vtkDataArraySelection *fieldSelection =
444 reader_->GetLagrangianFieldSelection();
446 // preserve the enabled selections
447 stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
448 fieldSelection->RemoveAllArrays();
451 // TODO - currently only get fields from ONE cloud
452 // have to decide if the second set of fields get mixed in
453 // or dealt with separately
455 const partInfo& selector = partInfoLagrangian_;
456 int partId = selector.start();
458 if (!selector.size() || partId < 0)
463 word cloudName = getPartName(partId);
465 // use the db directly since this might be called without a mesh,
466 // but the region must get added back in
467 fileName lagrangianPrefix(cloud::prefix);
468 if (meshRegion_ != polyMesh::defaultRegion)
470 lagrangianPrefix = meshRegion_/cloud::prefix;
477 lagrangianPrefix/cloudName
480 addToSelection<IOField<label> >
485 addToSelection<IOField<scalar> >
490 addToSelection<IOField<vector> >
495 addToSelection<IOField<sphericalTensor> >
501 addToSelection<IOField<symmTensor> >
506 addToSelection<IOField<tensor> >
512 // restore the enabled selections
513 setSelectedArrayEntries(fieldSelection, enabledEntries);
517 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
518 << "lagrangian objects.size() = " << objects.size() << endl;
523 // ************************************************************************* //