1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
88 // mesh not loaded - read from file
96 IOobject::READ_IF_PRESENT
100 IOobject::READ_IF_PRESENT,
105 if (ioObj.headerOk())
107 zonesEntries zones(ioObj);
109 zoneNames.setSize(zones.size());
112 zoneNames[zoneI] = zones[zoneI].keyword();
120 void Foam::vtkPV3Foam::updateInfoInternalMesh()
124 Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
127 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
129 // Determine mesh parts (internalMesh, patches...)
130 //- Add internal mesh as first entry
131 partInfoVolume_ = partSelection->GetNumberOfArrays();
132 partSelection->AddArray("internalMesh");
133 partInfoVolume_ += 1;
137 // just for debug info
138 getSelectedArrayEntries(partSelection);
140 Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
146 void Foam::vtkPV3Foam::updateInfoLagrangian()
150 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
151 << " " << dbPtr_->timePath()/cloud::prefix << endl;
155 // use the db directly since this might be called without a mesh,
156 // but the region must get added back in
157 fileName lagrangianPrefix(cloud::prefix);
158 if (meshRegion_ != polyMesh::defaultRegion)
160 lagrangianPrefix = meshRegion_/cloud::prefix;
163 // Search for list of lagrangian objects for this time
164 fileNameList cloudDirs
166 readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
169 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
170 partInfoLagrangian_ = partSelection->GetNumberOfArrays();
173 forAll(cloudDirs, cloudI)
175 // Add cloud to GUI list
176 partSelection->AddArray
178 (cloudDirs[cloudI] + " - lagrangian").c_str()
184 partInfoLagrangian_ += nClouds;
188 // just for debug info
189 getSelectedArrayEntries(partSelection);
191 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
196 void Foam::vtkPV3Foam::updateInfoPatches()
200 Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
201 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
204 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
205 partInfoPatches_ = partSelection->GetNumberOfArrays();
210 const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
211 forAll(patches, patchI)
213 const polyPatch& pp = patches[patchI];
217 // Add patch to GUI list
218 partSelection->AddArray
220 (pp.name() + " - patch").c_str()
229 // mesh not loaded - read from file
230 // but this could fail if we've supplied a bad region name
234 dbPtr_().findInstance
238 IOobject::READ_IF_PRESENT
242 IOobject::READ_IF_PRESENT,
247 // this should only ever fail if the mesh region doesn't exist
248 if (ioObj.headerOk())
250 polyBoundaryMeshEntries patchEntries(ioObj);
252 // Add (non-zero) patches to the list of mesh parts
253 forAll(patchEntries, entryI)
257 readLabel(patchEntries[entryI].dict().lookup("nFaces"))
260 // Valid patch if nFace > 0 - add patch to GUI list
263 partSelection->AddArray
265 (patchEntries[entryI].keyword() + " - patch").c_str()
273 partInfoPatches_ += nPatches;
277 // just for debug info
278 getSelectedArrayEntries(partSelection);
280 Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
285 void Foam::vtkPV3Foam::updateInfoZones()
287 if (!reader_->GetIncludeZones())
294 Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
295 << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
298 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
302 // cellZones information
303 // ~~~~~~~~~~~~~~~~~~~~~
306 namesLst = meshPtr_->cellZones().names();
310 namesLst = readZoneNames("cellZones");
313 partInfoCellZones_ = partSelection->GetNumberOfArrays();
314 forAll(namesLst, elemI)
316 partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
318 partInfoCellZones_ += namesLst.size();
322 // faceZones information
323 // ~~~~~~~~~~~~~~~~~~~~~
326 namesLst = meshPtr_->faceZones().names();
330 namesLst = readZoneNames("faceZones");
333 partInfoFaceZones_ = partSelection->GetNumberOfArrays();
334 forAll(namesLst, elemI)
336 partSelection->AddArray
338 (namesLst[elemI] + " - faceZone").c_str()
341 partInfoFaceZones_ += namesLst.size();
345 // pointZones information
346 // ~~~~~~~~~~~~~~~~~~~~~~
349 namesLst = meshPtr_->pointZones().names();
353 namesLst = readZoneNames("pointZones");
356 partInfoPointZones_ = partSelection->GetNumberOfArrays();
357 forAll(namesLst, elemI)
359 partSelection->AddArray
361 (namesLst[elemI] + " - pointZone").c_str()
364 partInfoPointZones_ += namesLst.size();
369 // just for debug info
370 getSelectedArrayEntries(partSelection);
372 Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
377 void Foam::vtkPV3Foam::updateInfoSets()
379 if (!reader_->GetIncludeSets())
386 Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
389 vtkDataArraySelection* partSelection = reader_->GetPartSelection();
395 dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
400 partInfoCellSets_ = partSelection->GetNumberOfArrays();
401 partInfoCellSets_ += addToSelection<cellSet>
408 partInfoFaceSets_ = partSelection->GetNumberOfArrays();
409 partInfoFaceSets_ += addToSelection<faceSet>
416 partInfoPointSets_ = partSelection->GetNumberOfArrays();
417 partInfoPointSets_ += addToSelection<pointSet>
426 // just for debug info
427 getSelectedArrayEntries(partSelection);
429 Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
434 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
438 Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
442 vtkDataArraySelection *fieldSelection =
443 reader_->GetLagrangianFieldSelection();
445 // preserve the enabled selections
446 stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
447 fieldSelection->RemoveAllArrays();
450 // TODO - currently only get fields from ONE cloud
451 // have to decide if the second set of fields get mixed in
452 // or dealt with separately
454 const partInfo& selector = partInfoLagrangian_;
455 int partId = selector.start();
457 if (!selector.size() || partId < 0)
462 word cloudName = getPartName(partId);
464 // use the db directly since this might be called without a mesh,
465 // but the region must get added back in
466 fileName lagrangianPrefix(cloud::prefix);
467 if (meshRegion_ != polyMesh::defaultRegion)
469 lagrangianPrefix = meshRegion_/cloud::prefix;
476 lagrangianPrefix/cloudName
479 addToSelection<IOField<label> >
484 addToSelection<IOField<scalar> >
489 addToSelection<IOField<vector> >
494 addToSelection<IOField<sphericalTensor> >
500 addToSelection<IOField<symmTensor> >
505 addToSelection<IOField<tensor> >
511 // restore the enabled selections
512 setSelectedArrayEntries(fieldSelection, enabledEntries);
516 Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
517 << "lagrangian objects.size() = " << objects.size() << endl;
522 // ************************************************************************* //