Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / postProcessing / graphics / PV3FoamReader / vtkPV3Foam / vtkPV3FoamUpdateInfo.C
blobfd9efa5b5cb9a263d349669e5d09e433326e580f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
28 // Foam includes
29 #include "cellSet.H"
30 #include "faceSet.H"
31 #include "pointSet.H"
32 #include "IOobjectList.H"
33 #include "IOPtrList.H"
34 #include "polyBoundaryMeshEntries.H"
35 #include "entry.H"
36 #include "Cloud.H"
37 #include "vtkPV3FoamReader.h"
39 // local headers
40 #include "vtkPV3FoamAddToSelection.H"
41 #include "vtkPV3FoamUpdateInfoFields.H"
43 // VTK includes
44 #include "vtkDataArraySelection.h"
47 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
49 namespace Foam
52 //- A class for reading zone information without requiring a mesh
53 class zonesEntries
55     public regIOobject,
56     public PtrList<entry>
59 public:
61     // Constructors
63         explicit zonesEntries(const IOobject& io)
64         :
65             regIOobject(io),
66             PtrList<entry>(readStream("regIOobject"))
67         {
68             close();
69         }
71    // Member functions
73         bool writeData(Ostream&) const
74         {
75             notImplemented("zonesEntries::writeData(Ostream&) const");
76             return false;
77         }
82 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
84 Foam::wordList Foam::vtkPV3Foam::readZoneNames(const word& zoneType)
86     wordList zoneNames;
88     // mesh not loaded - read from file
89     IOobject ioObj
90     (
91         zoneType,
92         dbPtr_().findInstance
93         (
94             meshDir_,
95             zoneType,
96             IOobject::READ_IF_PRESENT
97         ),
98         meshDir_,
99         dbPtr_(),
100         IOobject::READ_IF_PRESENT,
101         IOobject::NO_WRITE,
102         false
103     );
105     if (ioObj.headerOk())
106     {
107         zonesEntries zones(ioObj);
109         zoneNames.setSize(zones.size());
110         forAll(zones, zoneI)
111         {
112             zoneNames[zoneI] = zones[zoneI].keyword();
113         }
114     }
116     return zoneNames;
120 void Foam::vtkPV3Foam::updateInfoInternalMesh()
122     if (debug)
123     {
124         Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
125     }
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;
135     if (debug)
136     {
137         // just for debug info
138         getSelectedArrayEntries(partSelection);
140         Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
141     }
146 void Foam::vtkPV3Foam::updateInfoLagrangian()
148     if (debug)
149     {
150         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl
151             << "    " << dbPtr_->timePath()/cloud::prefix << endl;
152     }
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)
159     {
160         lagrangianPrefix = meshRegion_/cloud::prefix;
161     }
163     // Search for list of lagrangian objects for this time
164     fileNameList cloudDirs
165     (
166         readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
167     );
169     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
170     partInfoLagrangian_ = partSelection->GetNumberOfArrays();
172     int nClouds = 0;
173     forAll(cloudDirs, cloudI)
174     {
175         // Add cloud to GUI list
176         partSelection->AddArray
177         (
178             (cloudDirs[cloudI] + " - lagrangian").c_str()
179         );
181         ++nClouds;
182     }
184     partInfoLagrangian_ += nClouds;
186     if (debug)
187     {
188         // just for debug info
189         getSelectedArrayEntries(partSelection);
191         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
192     }
196 void Foam::vtkPV3Foam::updateInfoPatches()
198     if (debug)
199     {
200         Info<< "<beg> Foam::vtkPV3Foam::updateInfoPatches"
201             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
202     }
204     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
205     partInfoPatches_ = partSelection->GetNumberOfArrays();
207     int nPatches = 0;
208     if (meshPtr_)
209     {
210         const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
211         forAll(patches, patchI)
212         {
213             const polyPatch& pp = patches[patchI];
215             if (pp.size())
216             {
217                 // Add patch to GUI list
218                 partSelection->AddArray
219                 (
220                     (pp.name() + " - patch").c_str()
221                 );
223                 ++nPatches;
224             }
225         }
226     }
227     else
228     {
229         // mesh not loaded - read from file
230         // but this could fail if we've supplied a bad region name
231         IOobject ioObj
232         (
233             "boundary",
234             dbPtr_().findInstance
235             (
236                 meshDir_,
237                 "boundary",
238                 IOobject::READ_IF_PRESENT
239             ),
240             meshDir_,
241             dbPtr_(),
242             IOobject::READ_IF_PRESENT,
243             IOobject::NO_WRITE,
244             false
245         );
247         // this should only ever fail if the mesh region doesn't exist
248         if (ioObj.headerOk())
249         {
250             polyBoundaryMeshEntries patchEntries(ioObj);
252             // Add (non-zero) patches to the list of mesh parts
253             forAll(patchEntries, entryI)
254             {
255                 label nFaces
256                 (
257                     readLabel(patchEntries[entryI].dict().lookup("nFaces"))
258                 );
260                 // Valid patch if nFace > 0 - add patch to GUI list
261                 if (nFaces)
262                 {
263                     partSelection->AddArray
264                     (
265                         (patchEntries[entryI].keyword() + " - patch").c_str()
266                     );
268                     ++nPatches;
269                 }
270             }
271         }
272     }
273     partInfoPatches_ += nPatches;
275     if (debug)
276     {
277         // just for debug info
278         getSelectedArrayEntries(partSelection);
280         Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
281     }
285 void Foam::vtkPV3Foam::updateInfoZones()
287     if (!reader_->GetIncludeZones())
288     {
289         return;
290     }
292     if (debug)
293     {
294         Info<< "<beg> Foam::vtkPV3Foam::updateInfoZones"
295             << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
296     }
298     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
299     wordList namesLst;
301     //
302     // cellZones information
303     // ~~~~~~~~~~~~~~~~~~~~~
304     if (meshPtr_)
305     {
306         namesLst = meshPtr_->cellZones().names();
307     }
308     else
309     {
310         namesLst = readZoneNames("cellZones");
311     }
313     partInfoCellZones_ = partSelection->GetNumberOfArrays();
314     forAll(namesLst, elemI)
315     {
316         partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
317     }
318     partInfoCellZones_ += namesLst.size();
321     //
322     // faceZones information
323     // ~~~~~~~~~~~~~~~~~~~~~
324     if (meshPtr_)
325     {
326         namesLst = meshPtr_->faceZones().names();
327     }
328     else
329     {
330         namesLst = readZoneNames("faceZones");
331     }
333     partInfoFaceZones_ = partSelection->GetNumberOfArrays();
334     forAll(namesLst, elemI)
335     {
336         partSelection->AddArray
337         (
338             (namesLst[elemI] + " - faceZone").c_str()
339         );
340     }
341     partInfoFaceZones_ += namesLst.size();
344     //
345     // pointZones information
346     // ~~~~~~~~~~~~~~~~~~~~~~
347     if (meshPtr_)
348     {
349         namesLst = meshPtr_->pointZones().names();
350     }
351     else
352     {
353         namesLst = readZoneNames("pointZones");
354     }
356     partInfoPointZones_ = partSelection->GetNumberOfArrays();
357     forAll(namesLst, elemI)
358     {
359         partSelection->AddArray
360         (
361             (namesLst[elemI] + " - pointZone").c_str()
362         );
363     }
364     partInfoPointZones_ += namesLst.size();
367     if (debug)
368     {
369         // just for debug info
370         getSelectedArrayEntries(partSelection);
372         Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
373     }
377 void Foam::vtkPV3Foam::updateInfoSets()
379     if (!reader_->GetIncludeSets())
380     {
381         return;
382     }
384     if (debug)
385     {
386         Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
387     }
389     vtkDataArraySelection* partSelection = reader_->GetPartSelection();
391     // Add names of sets
392     IOobjectList objects
393     (
394         dbPtr_(),
395         dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
396         meshDir_/"sets"
397     );
400     partInfoCellSets_ = partSelection->GetNumberOfArrays();
401     partInfoCellSets_ += addToSelection<cellSet>
402     (
403         partSelection,
404         objects,
405         " - cellSet"
406     );
408     partInfoFaceSets_ = partSelection->GetNumberOfArrays();
409     partInfoFaceSets_ += addToSelection<faceSet>
410     (
411         partSelection,
412         objects,
413         " - faceSet"
414     );
416     partInfoPointSets_ = partSelection->GetNumberOfArrays();
417     partInfoPointSets_ += addToSelection<pointSet>
418     (
419         partSelection,
420         objects,
421         " - pointSet"
422     );
424     if (debug)
425     {
426         // just for debug info
427         getSelectedArrayEntries(partSelection);
429         Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
430     }
434 void Foam::vtkPV3Foam::updateInfoLagrangianFields()
436     if (debug)
437     {
438         Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangianFields"
439             << endl;
440     }
442     vtkDataArraySelection *fieldSelection =
443         reader_->GetLagrangianFieldSelection();
445     // preserve the enabled selections
446     stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
447     fieldSelection->RemoveAllArrays();
449     //
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)
458     {
459         return;
460     }
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)
468     {
469         lagrangianPrefix = meshRegion_/cloud::prefix;
470     }
472     IOobjectList objects
473     (
474         dbPtr_(),
475         dbPtr_().timeName(),
476         lagrangianPrefix/cloudName
477     );
479     addToSelection<IOField<label> >
480     (
481         fieldSelection,
482         objects
483     );
484     addToSelection<IOField<scalar> >
485     (
486         fieldSelection,
487         objects
488     );
489     addToSelection<IOField<vector> >
490     (
491         fieldSelection,
492         objects
493     );
494     addToSelection<IOField<sphericalTensor> >
495     (
496         fieldSelection,
498         objects
499     );
500     addToSelection<IOField<symmTensor> >
501     (
502         fieldSelection,
503         objects
504     );
505     addToSelection<IOField<tensor> >
506     (
507         fieldSelection,
508         objects
509     );
511     // restore the enabled selections
512     setSelectedArrayEntries(fieldSelection, enabledEntries);
514     if (debug)
515     {
516         Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangianFields - "
517             << "lagrangian objects.size() = " << objects.size() << endl;
518     }
522 // ************************************************************************* //