vtkPVFoam.H 14.9 KB
Newer Older
Henry's avatar
Henry committed
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2017-2019 OpenCFD Ltd.
Henry's avatar
Henry committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
25
    Foam::vtkPVFoam
Henry's avatar
Henry committed
26 27

Description
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    The backend for the vtkPVFoamReader reader module -
    providing a paraview reader interface for OpenFOAM meshes and fields.

    Similar, and sometimes better, functionality may be provided by the
    native VTK OpenFOAM reader. OpenCFD has recently (2017) been working
    on improving the native VTK OpenFOAM reader for the benefit of everyone.

    In some areas the reader module lacks compared to the native reader
    (notably the ability to work on decomosed datasets), but provides
    additional handling of sets,zones,groups. Some features have also since
    been adapted to the native reader. Additionally, the reader module
    provides a useful platform for testing new ideas.

Note
    The reader module allows two levels of caching. The OpenFOAM fvMesh
    can be cached in memory, for faster loading of fields. Additionally,
    the translated VTK geometries are held in a local cache. The cached
    VTK geometries should incur no additional overhead since they use
    the VTK reference counting for their storage management.
Henry's avatar
Henry committed
47 48

SourceFiles
49 50 51 52 53
    vtkPVFoam.C
    vtkPVFoamFields.C
    vtkPVFoamMesh.C
    vtkPVFoamMeshLagrangian.C
    vtkPVFoamMeshVolume.C
54
    vtkPVFoamTemplates.C
55
    vtkPVFoamUpdateInfo.C
56 57
    vtkPVFoamFieldTemplates.C
    vtkPVFoamUpdateTemplates.C
Henry's avatar
Henry committed
58 59 60 61 62 63

    // Needed by VTK:
    vtkDataArrayTemplateImplicit.txx

\*---------------------------------------------------------------------------*/

64 65
#ifndef vtkPVFoam_H
#define vtkPVFoam_H
Henry's avatar
Henry committed
66 67 68 69 70 71 72 73

#include "className.H"
#include "fileName.H"
#include "stringList.H"
#include "wordList.H"
#include "primitivePatch.H"
#include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H"
74
#include "foamPvCore.H"
75
#include "foamVtkTools.H"
76
#include "foamVtkMeshMaps.H"
Henry's avatar
Henry committed
77

78
#include "vtkPoints.h"
79
#include "vtkPolyData.h"
80
#include "vtkSmartPointer.h"
81 82
#include "vtkUnstructuredGrid.h"

Henry's avatar
Henry committed
83 84
// * * * * * * * * * * * * * Forward Declarations  * * * * * * * * * * * * * //

85
class vtkCellArray;
Henry's avatar
Henry committed
86 87
class vtkDataArraySelection;
class vtkDataSet;
88
class vtkFloatArray;
89 90
class vtkIndent;
class vtkMultiBlockDataSet;
91
class vtkPVFoamReader;
Henry's avatar
Henry committed
92 93
class vtkRenderer;
class vtkTextActor;
94

Henry's avatar
Henry committed
95 96 97 98 99 100 101 102
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// OpenFOAM class forward declarations
class argList;
class Time;
103
class faMesh;
Henry's avatar
Henry committed
104 105 106
class fvMesh;
class IOobjectList;
class polyPatch;
107
class fvMeshSubset;
Henry's avatar
Henry committed
108 109

template<class Type> class IOField;
110
template<class Type> class Field;
Henry's avatar
Henry committed
111 112 113
template<class Type> class List;

/*---------------------------------------------------------------------------*\
114
                        Class vtkPVFoam Declaration
Henry's avatar
Henry committed
115 116
\*---------------------------------------------------------------------------*/

117
class vtkPVFoam
118
:
119
    private foamPvCore
Henry's avatar
Henry committed
120
{
121 122
    // Convenience typedefs
    typedef PrimitivePatchInterpolation<primitivePatch> patchInterpolator;
Henry's avatar
Henry committed
123

124
        //- Bookkeeping for vtkPolyData
125
        struct foamVtpData
126
        :
127
            public vtk::Caching<vtkPolyData>,
128 129 130
            public foamVtkMeshMaps
        {};

131
        //- Bookkeeping for vtkUnstructuredGrid
132
        struct foamVtuData
133
        :
134
            public vtk::Caching<vtkUnstructuredGrid>,
135
            public foamVtkMeshMaps
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
        {
            //- The vtk points for the mesh (and decomposition)
            vtkSmartPointer<vtkPoints> points
            (
                const fvMesh& mesh
            ) const;

            //- The vtk points for the mesh (and decomposition),
            //- using the provided pointMap
            vtkSmartPointer<vtkPoints> points
            (
                const fvMesh& mesh,
                const labelUList& pointMap
            ) const;

            //- Internal mesh as vtkUnstructuredGrid
            vtkSmartPointer<vtkUnstructuredGrid> internal
            (
                const fvMesh& mesh,
                const bool decompPoly
            );

            //- Subsetted mesh as vtkUnstructuredGrid
            vtkSmartPointer<vtkUnstructuredGrid> subset
            (
                const fvMeshSubset& subsetter,
                const bool decompPoly
            );
        };
165

Henry's avatar
Henry committed
166 167 168

    // Private Data

169 170
        //- Access to the controlling vtkPVFoamReader
        vtkPVFoamReader* reader_;
Henry's avatar
Henry committed
171 172 173 174

        //- OpenFOAM time control
        autoPtr<Time> dbPtr_;

175 176 177 178 179
        //- OpenFOAM finite volume mesh
        fvMesh* volMeshPtr_;

        //- OpenFOAM finite area mesh
        faMesh* areaMeshPtr_;
Henry's avatar
Henry committed
180 181 182 183 184 185 186 187 188 189

        //- The mesh region
        word meshRegion_;

        //- The mesh directory for the region
        fileName meshDir_;

        //- The time index
        int timeIndex_;

190 191 192
        //- Previous/current decomposition request
        bool decomposePoly_;

Henry's avatar
Henry committed
193
        //- Track changes in mesh geometry
194
        enum polyMesh::readUpdateState meshState_;
Henry's avatar
Henry committed
195

196 197
        //- The index of selected parts mapped to their names
        Map<string> selectedPartIds_;
Henry's avatar
Henry committed
198

199 200 201 202 203
        //- Any information for 2D (VTP) geometries
        HashTable<foamVtpData, string> cachedVtp_;

        //- Cell maps and other information for 3D (VTU) geometries
        HashTable<foamVtuData, string> cachedVtu_;
Henry's avatar
Henry committed
204 205

        //- First instance and size of various mesh parts
206
        //  used to index into selectedPartIds and thus indirectly into
207
        //  cachedVtp, cachedVtu
208
        arrayRange rangeVolume_;
209
        arrayRange rangeArea_;
210
        arrayRange rangePatches_;
211
        arrayRange rangeClouds_;
212 213 214 215 216 217
        arrayRange rangeCellZones_;
        arrayRange rangeFaceZones_;
        arrayRange rangePointZones_;
        arrayRange rangeCellSets_;
        arrayRange rangeFaceSets_;
        arrayRange rangePointSets_;
Henry's avatar
Henry committed
218 219

        //- List of patch names for rendering to window
220
        List<vtkSmartPointer<vtkTextActor>> patchTextActors_;
Henry's avatar
Henry committed
221

222

Henry's avatar
Henry committed
223 224
    // Private Member Functions

225 226 227 228 229 230 231 232 233 234
        template<class Container>
        bool addOutputBlock
        (
            vtkMultiBlockDataSet* output,
            const HashTable<Container, string>& cache,
            const arrayRange& selector,
            const bool singleDataset = false
        ) const;


235 236 237
        //- Reset data counters
        void resetCounters();

238
    // Update information helper functions
239 240

        //- Internal mesh info
241
        void updateInfoInternalMesh(vtkDataArraySelection* select);
242

243 244 245
        //- Finite area mesh info
        void updateInfoAreaMesh(vtkDataArraySelection* select);

246
        //- Lagrangian info
247
        void updateInfoLagrangian(vtkDataArraySelection* select);
Henry's avatar
Henry committed
248

249 250 251 252 253 254
        //- Patch info, modifies enabledEntries
        void updateInfoPatches
        (
            vtkDataArraySelection* select,
            HashSet<string>& enabledEntries
        );
255 256

        //- Set info
257
        void updateInfoSets(vtkDataArraySelection* select);
258 259

        //- Zone info
260 261
        void updateInfoZones(vtkDataArraySelection* select);

262 263 264 265 266 267 268

        //- Get non-empty zone names for zoneType from file
        wordList getZoneNames(const word& zoneType) const;

        //- Get names of on non-empty zones from the mesh info
        template<class ZoneType>
        static wordList getZoneNames
Henry's avatar
Henry committed
269
        (
270
            const ZoneMesh<ZoneType, polyMesh>& zmesh
Henry's avatar
Henry committed
271 272
        );

273 274 275
        //- Field info
        template<template<class> class patchType, class meshType>
        void updateInfoFields
Henry's avatar
Henry committed
276
        (
277 278
            vtkDataArraySelection* select,
            const IOobjectList& objects
Henry's avatar
Henry committed
279 280
        );

281 282 283 284 285 286
        //- Volume/Area field info
        void updateInfoContinuumFields(vtkDataArraySelection* select);

        //- Point field info
        void updateInfoPointFields(vtkDataArraySelection* select);

287 288
        //- Lagrangian field info
        void updateInfoLagrangianFields(vtkDataArraySelection* select);
Henry's avatar
Henry committed
289 290


291
    // Mesh conversion functions
Henry's avatar
Henry committed
292

293
        //- Convert internalMesh
294
        void convertMeshVolume();
Henry's avatar
Henry committed
295

296 297 298
        //- Convert areaMesh
        void convertMeshArea();

299
        //- Convert Lagrangian points
300
        void convertMeshLagrangian();
Henry's avatar
Henry committed
301

302 303 304
        //- Convert mesh patches.
        //  The additionalIds (cached data) contain the patch Ids.
        //  There will be several for groups, but only one for regular patches.
305 306
        void convertMeshPatches();

307
        //- Convert cell zones
308
        void convertMeshCellZones();
Henry's avatar
Henry committed
309

310
        //- Convert cell sets
311
        void convertMeshCellSets();
Henry's avatar
Henry committed
312

313 314 315
        //- Convert face zones
        void convertMeshFaceZones();

316
        //- Convert face sets
317
        //  The cellMap (cached data) contains the face-labels.
318
        void convertMeshFaceSets();
Henry's avatar
Henry committed
319

320 321 322 323
        //- Convert point zones
        //  The pointMap (cached data) contains the point-labels.
        void convertMeshPointZones();

324
        //- Convert point sets
325
        //  The pointMap (cached data) contains the point-labels.
326
        void convertMeshPointSets();
Henry's avatar
Henry committed
327 328


329
    // Add mesh functions
Henry's avatar
Henry committed
330

331
        //- Lagrangian positions as vtkPolyData
332
        vtkSmartPointer<vtkPolyData> lagrangianVTKMesh
333 334 335
        (
            const polyMesh& mesh,
            const word& cloudName
336 337 338
        ) const;


339
    // Field conversion functions
340

341 342
        //- Face set/zone field
        template<class Type>
343
        vtkSmartPointer<vtkFloatArray> convertFaceFieldToVTK
344 345 346
        (
            const GeometricField<Type, fvPatchField, volMesh>& fld,
            const labelUList& faceLabels
347
        ) const;
348 349 350

        //- Volume field
        template<class Type>
351
        vtkSmartPointer<vtkFloatArray> convertVolFieldToVTK
352 353
        (
            const GeometricField<Type, fvPatchField, volMesh>& fld,
354
            const foamVtuData& vtuData
355
        ) const;
Henry's avatar
Henry committed
356 357


358
        //- Convert finite volume fields
359
        void convertVolFields();
Henry's avatar
Henry committed
360

361 362 363
        //- Convert finite area fields
        void convertAreaFields();

364
        //- Convert point fields
365
        void convertPointFields();
Henry's avatar
Henry committed
366

367
        //- Convert Lagrangian fields
368
        void convertLagrangianFields();
Henry's avatar
Henry committed
369 370


371
    // Convert OpenFOAM fields
Henry's avatar
Henry committed
372

373 374 375 376 377
        //- Volume field - all types
        template<class Type>
        void convertVolField
        (
            const PtrList<patchInterpolator>& patchInterpList,
378
            const GeometricField<Type, fvPatchField, volMesh>& fld
379
        );
Henry's avatar
Henry committed
380

381 382 383 384 385 386
        //- Volume fields - all types
        template<class Type>
        void convertVolFields
        (
            const fvMesh& mesh,
            const PtrList<patchInterpolator>& patchInterpList,
387
            const IOobjectList& objects
388
        );
Henry's avatar
Henry committed
389

390 391 392 393 394 395
        //- Volume internal fields (DimensionedField)- all types
        template<class Type>
        void convertDimFields
        (
            const fvMesh& mesh,
            const PtrList<patchInterpolator>& patchInterpList,
396
            const IOobjectList& objects
397
        );
Henry's avatar
Henry committed
398

399 400 401 402 403 404 405 406
        //- Area fields - all types
        template<class Type>
        void convertAreaFields
        (
            const faMesh& mesh,
            const IOobjectList& objects
        );

407 408 409 410 411 412
        //- Volume field - all selected parts
        template<class Type>
        void convertVolFieldBlock
        (
            const GeometricField<Type, fvPatchField, volMesh>& fld,
            autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr,
413
            const arrayRange& range
414
        );
Henry's avatar
Henry committed
415

416 417 418 419 420
        //- Lagrangian fields - all types
        template<class Type>
        void convertLagrangianFields
        (
            const IOobjectList& objects,
421
            vtkPolyData* vtkmesh
422
        );
Henry's avatar
Henry committed
423

424 425 426 427 428
        //- Point fields - all types
        template<class Type>
        void convertPointFields
        (
            const pointMesh& pMesh,
429
            const IOobjectList& objectst
430
        );
Henry's avatar
Henry committed
431

432 433 434 435 436
        //- Point field - all selected parts
        template<class Type>
        void convertPointFieldBlock
        (
            const GeometricField<Type, pointPatchField, pointMesh>& pfld,
437
            const arrayRange& range
438
        );
Henry's avatar
Henry committed
439

440 441
        //- Point field
        template<class Type>
442
        vtkSmartPointer<vtkFloatArray> convertPointField
443 444 445
        (
            const GeometricField<Type, pointPatchField, pointMesh>& pfld,
            const GeometricField<Type, fvPatchField, volMesh>& vfld,
446
            const foamVtuData& vtuData
447
        );
Henry's avatar
Henry committed
448 449


450
    // GUI selection helper functions
Henry's avatar
Henry committed
451

452
        //- Get the first word from the reader 'parts' selection
453
        word getReaderPartName(const int partId) const;
Henry's avatar
Henry committed
454 455


456
    // Constructors
Henry's avatar
Henry committed
457

458
        //- No copy construct
459
        vtkPVFoam(const vtkPVFoam&) = delete;
Henry's avatar
Henry committed
460

461
        //- No copy assignment
462
        void operator=(const vtkPVFoam&) = delete;
Henry's avatar
Henry committed
463 464 465 466 467 468


public:

    //- Static data members

469
        ClassName("vtkPVFoam");
Henry's avatar
Henry committed
470 471 472 473 474


    // Constructors

        //- Construct from components
475
        vtkPVFoam
Henry's avatar
Henry committed
476 477
        (
            const char* const FileName,
478
            vtkPVFoamReader* reader
Henry's avatar
Henry committed
479 480 481 482
        );


    //- Destructor
483
    ~vtkPVFoam();
Henry's avatar
Henry committed
484 485 486 487 488 489 490 491 492 493


    // Member Functions

        //- Update
        void updateInfo();

        void Update
        (
            vtkMultiBlockDataSet* output,
494
            vtkMultiBlockDataSet* outputLagrangian
Henry's avatar
Henry committed
495 496
        );

497 498 499 500 501
        //- Final part of Update(), after any last minute rendering.
        void UpdateFinalize();

        //- Add/remove patch names to/from the view
        void renderPatchNames(vtkRenderer* renderer, const bool show);
Henry's avatar
Henry committed
502

503 504 505
        //- Return a list of selected times.
        //  Use STL container since these values are used by the plugin
        std::vector<double> findTimes(const bool skipZero = false) const;
Henry's avatar
Henry committed
506

507
        //- Set the runTime to the first plausible request time,
Henry's avatar
Henry committed
508 509
        //  returns the timeIndex
        //  sets to "constant" on error
510
        int setTime(const std::vector<double>& requestTimes);
Henry's avatar
Henry committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524


        //- The current time index
        int timeIndex() const
        {
           return timeIndex_;
        }


     // Access

        //- Debug information
        void PrintSelf(ostream&, vtkIndent) const;

525
        void printInfo() const;
Henry's avatar
Henry committed
526 527 528 529 530 531 532 533 534 535 536 537
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //