BUGFIX: Uninitialised member variables
[foam-extend-3.2.git] / applications / utilities / postProcessing / graphics / PV3FoamReader / vtkPV3Foam / vtkPV3FoamUpdateInfo.C
blob1c87c1ff7421961c9c8610e5a86da5d5e4ebbaa6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
29 // Foam includes
30 #include "cellSet.H"
31 #include "faceSet.H"
32 #include "pointSet.H"
33 #include "IOobjectList.H"
34 #include "IOPtrList.H"
35 #include "polyBoundaryMeshEntries.H"
36 #include "entry.H"
37 #include "Cloud.H"
38 #include "vtkPV3FoamReader.h"
40 // local headers
41 #include "vtkPV3FoamAddToSelection.H"
42 #include "vtkPV3FoamUpdateInfoFields.H"
44 // VTK includes
45 #include "vtkDataArraySelection.h"
48 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
50 namespace Foam
53 //- A class for reading zone information without requiring a mesh
54 class zonesEntries
56     public regIOobject,
57     public PtrList<entry>
60 public:
62     // Constructors
64         explicit zonesEntries(const IOobject& io)
65         :
66             regIOobject(io),
67             PtrList<entry>(readStream("regIOobject"))
68         {
69             close();
70         }
72    // Member functions
74         bool writeData(Ostream&) const
75         {
76             notImplemented("zonesEntries::writeData(Ostream&) const");
77             return false;
78         }
83 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
85 Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
87     wordList zoneNames;
89     // mesh not loaded - read from file
90     IOobject ioObj
91     (
92         zoneType,
93         dbPtr_().findInstance
94         (
95             meshDir_,
96             zoneType,
97             IOobject::READ_IF_PRESENT
98         ),
99         meshDir_,
100         dbPtr_(),
101         IOobject::READ_IF_PRESENT,
102         IOobject::NO_WRITE,
103         false
104     );
106     if (ioObj.headerOk())
107     {
108         zonesEntries zones(ioObj);
110         zoneNames.setSize(zones.size());
111         forAll(zones, zoneI)
112         {
113             zoneNames[zoneI] = zones[zoneI].keyword();
114         }
115     }
117     return zoneNames;
121 void Foam::vtkPV3Foam::updateInfoInternalMesh()
123     if (debug)
124     {
125         Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
126     }
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;
136     if (debug)
137     {
138         // just for debug info
139         getSelectedArrayEntries(partSelection);
141         Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
142     }
147 void Foam::vtkPV3Foam::updateInfoLagrangian()
149     if (debug)
150     {
151         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
152             << "    " << dbPtr_->timePath()/cloud::prefix << endl;
153     }
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)
160     {
161         lagrangianPrefix = meshRegion_/cloud::prefix;
162     }
164     // Search for list of lagrangian objects for this time
165     fileNameList cloudDirs
166     (
167         readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
168     );
170     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
171     partInfoLagrangian_ = partSelection->GetNumberOfArrays();
173     int nClouds = 0;
174     forAll(cloudDirs, cloudI)
175     {
176         // Add cloud to GUI list
177         partSelection->AddArray
178         (
179             (cloudDirs[cloudI] + " - lagrangian").c_str()
180         );
182         ++nClouds;
183     }
185     partInfoLagrangian_ += nClouds;
187     if (debug)
188     {
189         // just for debug info
190         getSelectedArrayEntries(partSelection);
192         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
193     }
197 void Foam::vtkPV3Foam::updateInfoPatches()
199     if (debug)
200     {
201         Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
202             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
203     }
205     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
206     partInfoPatches_ = partSelection->GetNumberOfArrays();
208     int nPatches = 0;
209     if (meshPtr_)
210     {
211         const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
212         forAll(patches, patchI)
213         {
214             const polyPatch& pp = patches[patchI];
216             if (pp.size())
217             {
218                 // Add patch to GUI list
219                 partSelection->AddArray
220                 (
221                     (pp.name() + " - patch").c_str()
222                 );
224                 ++nPatches;
225             }
226         }
227     }
228     else
229     {
230         // mesh not loaded - read from file
231         // but this could fail if we've supplied a bad region name
232         IOobject ioObj
233         (
234             "boundary",
235             dbPtr_().findInstance
236             (
237                 meshDir_,
238                 "boundary",
239                 IOobject::READ_IF_PRESENT
240             ),
241             meshDir_,
242             dbPtr_(),
243             IOobject::READ_IF_PRESENT,
244             IOobject::NO_WRITE,
245             false
246         );
248         // this should only ever fail if the mesh region doesn't exist
249         if (ioObj.headerOk())
250         {
251             polyBoundaryMeshEntries patchEntries(ioObj);
253             // Add (non-zero) patches to the list of mesh parts
254             forAll(patchEntries, entryI)
255             {
256                 label nFaces
257                 (
258                     readLabel(patchEntries[entryI].dict().lookup("nFaces"))
259                 );
261                 // Valid patch if nFace > 0 - add patch to GUI list
262                 if (nFaces)
263                 {
264                     partSelection->AddArray
265                     (
266                         (patchEntries[entryI].keyword() + " - patch").c_str()
267                     );
269                     ++nPatches;
270                 }
271             }
272         }
273     }
274     partInfoPatches_ += nPatches;
276     if (debug)
277     {
278         // just for debug info
279         getSelectedArrayEntries(partSelection);
281         Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
282     }
286 void Foam::vtkPV3Foam::updateInfoZones()
288     if (!reader_->GetIncludeZones())
289     {
290         return;
291     }
293     if (debug)
294     {
295         Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
296             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
297     }
299     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
300     wordList namesLst;
302     //
303     // cellZones information
304     // ~~~~~~~~~~~~~~~~~~~~~
305     if (meshPtr_)
306     {
307         namesLst = meshPtr_->cellZones().names();
308     }
309     else
310     {
311         namesLst = readZoneNames("cellZones");
312     }
314     partInfoCellZones_ = partSelection->GetNumberOfArrays();
315     forAll(namesLst, elemI)
316     {
317         partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
318     }
319     partInfoCellZones_ += namesLst.size();
322     //
323     // faceZones information
324     // ~~~~~~~~~~~~~~~~~~~~~
325     if (meshPtr_)
326     {
327         namesLst = meshPtr_->faceZones().names();
328     }
329     else
330     {
331         namesLst = readZoneNames("faceZones");
332     }
334     partInfoFaceZones_ = partSelection->GetNumberOfArrays();
335     forAll(namesLst, elemI)
336     {
337         partSelection->AddArray
338         (
339             (namesLst[elemI] + " - faceZone").c_str()
340         );
341     }
342     partInfoFaceZones_ += namesLst.size();
345     //
346     // pointZones information
347     // ~~~~~~~~~~~~~~~~~~~~~~
348     if (meshPtr_)
349     {
350         namesLst = meshPtr_->pointZones().names();
351     }
352     else
353     {
354         namesLst = readZoneNames("pointZones");
355     }
357     partInfoPointZones_ = partSelection->GetNumberOfArrays();
358     forAll(namesLst, elemI)
359     {
360         partSelection->AddArray
361         (
362             (namesLst[elemI] + " - pointZone").c_str()
363         );
364     }
365     partInfoPointZones_ += namesLst.size();
368     if (debug)
369     {
370         // just for debug info
371         getSelectedArrayEntries(partSelection);
373         Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
374     }
378 void Foam::vtkPV3Foam::updateInfoSets()
380     if (!reader_->GetIncludeSets())
381     {
382         return;
383     }
385     if (debug)
386     {
387         Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
388     }
390     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
392     // Add names of sets
393     IOobjectList objects
394     (
395         dbPtr_(),
396         dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
397         meshDir_/"sets"
398     );
401     partInfoCellSets_ = partSelection->GetNumberOfArrays();
402     partInfoCellSets_ += addToSelection<cellSet>
403     (
404         partSelection,
405         objects,
406         " - cellSet"
407     );
409     partInfoFaceSets_ = partSelection->GetNumberOfArrays();
410     partInfoFaceSets_ += addToSelection<faceSet>
411     (
412         partSelection,
413         objects,
414         " - faceSet"
415     );
417     partInfoPointSets_ = partSelection->GetNumberOfArrays();
418     partInfoPointSets_ += addToSelection<pointSet>
419     (
420         partSelection,
421         objects,
422         " - pointSet"
423     );
425     if (debug)
426     {
427         // just for debug info
428         getSelectedArrayEntries(partSelection);
430         Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
431     }
435 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
437     if (debug)
438     {
439         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
440             << endl;
441     }
443     vtkDataArraySelection *fieldSelection =
444         reader_->GetLagrangianFieldSelection();
446     // preserve the enabled selections
447     stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
448     fieldSelection->RemoveAllArrays();
450     //
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)
459     {
460         return;
461     }
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)
469     {
470         lagrangianPrefix = meshRegion_/cloud::prefix;
471     }
473     IOobjectList objects
474     (
475         dbPtr_(),
476         dbPtr_().timeName(),
477         lagrangianPrefix/cloudName
478     );
480     addToSelection<IOField<label> >
481     (
482         fieldSelection,
483         objects
484     );
485     addToSelection<IOField<scalar> >
486     (
487         fieldSelection,
488         objects
489     );
490     addToSelection<IOField<vector> >
491     (
492         fieldSelection,
493         objects
494     );
495     addToSelection<IOField<sphericalTensor> >
496     (
497         fieldSelection,
499         objects
500     );
501     addToSelection<IOField<symmTensor> >
502     (
503         fieldSelection,
504         objects
505     );
506     addToSelection<IOField<tensor> >
507     (
508         fieldSelection,
509         objects
510     );
512     // restore the enabled selections
513     setSelectedArrayEntries(fieldSelection, enabledEntries);
515     if (debug)
516     {
517         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
518             << "lagrangian objects.size() = " << objects.size() << endl;
519     }
523 // ************************************************************************* //