OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkPV3Foam.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::vtkPV3Foam
00027 
00028 Description
00029     Provides a reader interface for OpenFOAM to VTK interaction.
00030 
00031 SourceFiles
00032     vtkPV3Foam.C
00033     vtkPV3Foam.H
00034     vtkPV3FoamI.H
00035     vtkPV3FoamFields.C
00036     vtkPV3FoamMesh.C
00037     vtkPV3FoamMeshLagrangian.C
00038     vtkPV3FoamMeshPatch.C
00039     vtkPV3FoamMeshSet.C
00040     vtkPV3FoamMeshVolume.C
00041     vtkPV3FoamMeshZone.C
00042     vtkPV3FoamFaceField.H
00043     vtkPV3FoamLagrangianFields.H
00044     vtkPV3FoamPatchField.H
00045     vtkPV3FoamPointFields.H
00046     vtkPV3FoamPoints.H
00047     vtkPV3FoamUpdateInfo.C
00048     vtkPV3FoamUpdateInfoFields.H
00049     vtkPV3FoamUtilities.C
00050     vtkPV3FoamVolFields.H
00051     vtkPV3FoamAddToSelection.H
00052 
00053     // Needed by VTK:
00054     vtkDataArrayTemplateImplicit.txx
00055 
00056 \*---------------------------------------------------------------------------*/
00057 
00058 #ifndef vtkPV3Foam_H
00059 #define vtkPV3Foam_H
00060 
00061 // do not include legacy strstream headers
00062 #ifndef  VTK_EXCLUDE_STRSTREAM_HEADERS
00063 # define VTK_EXCLUDE_STRSTREAM_HEADERS
00064 #endif
00065 
00066 #include "className.H"
00067 #include "fileName.H"
00068 #include "stringList.H"
00069 #include "wordList.H"
00070 #include "primitivePatch.H"
00071 #include "PrimitivePatchInterpolation.H"
00072 #include "volPointInterpolation.H"
00073 
00074 #undef VTKPV3FOAM_DUALPORT
00075 
00076 // * * * * * * * * * * * * * Forward Declarations  * * * * * * * * * * * * * //
00077 
00078 class vtkDataArraySelection;
00079 class vtkDataSet;
00080 class vtkPoints;
00081 class vtkPV3FoamReader;
00082 class vtkRenderer;
00083 class vtkTextActor;
00084 class vtkMultiBlockDataSet;
00085 class vtkPolyData;
00086 class vtkUnstructuredGrid;
00087 class vtkIndent;
00088 
00089 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00090 
00091 namespace Foam
00092 {
00093 
00094 // Foam class forward declarations
00095 class argList;
00096 class Time;
00097 class fvMesh;
00098 class IOobjectList;
00099 class polyPatch;
00100 class faceSet;
00101 class pointSet;
00102 
00103 template<class Type> class IOField;
00104 template<class Type> class List;
00105 
00106 /*---------------------------------------------------------------------------*\
00107                         Class vtkPV3Foam Declaration
00108 \*---------------------------------------------------------------------------*/
00109 
00110 class vtkPV3Foam
00111 {
00112     // Private classes
00113 
00114         //- Bookkeeping for GUI checklists and the multi-block organization
00115         class partInfo
00116         {
00117             const char *name_;
00118             int block_;
00119             int start_;
00120             int size_;
00121 
00122         public:
00123 
00124             partInfo(const char *name, const int blockNo=0)
00125             :
00126                 name_(name),
00127                 block_(blockNo),
00128                 start_(-1),
00129                 size_(0)
00130             {}
00131 
00132             //- Return the block holding these datasets
00133             int block() const
00134             {
00135                 return block_;
00136             }
00137 
00138             //- Assign block number, return previous value
00139             int block(int blockNo)
00140             {
00141                 int prev = block_;
00142                 block_ = blockNo;
00143                 return prev;
00144             }
00145 
00146             const char* name() const
00147             {
00148                 return name_;
00149             }
00150 
00151             int start() const
00152             {
00153                 return start_;
00154             }
00155 
00156             int end() const
00157             {
00158                 return start_ + size_;
00159             }
00160 
00161             int size() const
00162             {
00163                 return size_;
00164             }
00165 
00166             bool empty() const
00167             {
00168                 return !size_;
00169             }
00170 
00171             void reset()
00172             {
00173                 start_ = -1;
00174                 size_ = 0;
00175             }
00176 
00177             //- Assign new start and reset the size
00178             void operator=(const int i)
00179             {
00180                 start_ = i;
00181                 size_ = 0;
00182             }
00183 
00184             //- Increment the size
00185             void operator+=(const int n)
00186             {
00187                 size_ += n;
00188             }
00189         };
00190 
00191         //- bookkeeping for polyhedral cell decomposition
00192         //  hide in extra pointMap (cellSet/cellZone) for now
00193         class polyDecomp
00194         {
00195             labelList superCells_;
00196             labelList addPointCellLabels_;
00197             labelList pointMap_;
00198 
00199         public:
00200 
00201             polyDecomp()
00202             {}
00203 
00204             //- Label of original cell for decomposed cells
00205             labelList& superCells()
00206             {
00207                 return superCells_;
00208             }
00209 
00210             //- Label of original cell for decomposed cells
00211             const labelList& superCells() const
00212             {
00213                 return superCells_;
00214             }
00215 
00216             //- Cell-centre labels for additional points of decomposed cells
00217             labelList& addPointCellLabels()
00218             {
00219                 return addPointCellLabels_;
00220             }
00221 
00222             //- Cell-centre labels for additional points of decomposed cells
00223             const labelList& addPointCellLabels() const
00224             {
00225                 return addPointCellLabels_;
00226             }
00227 
00228             //- Point labels for subsetted meshes
00229             labelList& pointMap()
00230             {
00231                 return pointMap_;
00232             }
00233 
00234             //- Point labels for subsetted meshes
00235             const labelList& pointMap() const
00236             {
00237                 return pointMap_;
00238             }
00239 
00240 
00241             //- Clear
00242             void clear()
00243             {
00244                 superCells_.clear();
00245                 addPointCellLabels_.clear();
00246                 pointMap_.clear();
00247             }
00248         };
00249 
00250 
00251     // Private Data
00252 
00253         //- Access to the controlling vtkPV3FoamReader
00254         vtkPV3FoamReader* reader_;
00255 
00256         //- Foam time control
00257         autoPtr<Time> dbPtr_;
00258 
00259         //- Foam mesh
00260         fvMesh* meshPtr_;
00261 
00262         //- The mesh region
00263         word meshRegion_;
00264 
00265         //- The mesh directory for the region
00266         fileName meshDir_;
00267 
00268         //- The time index
00269         int timeIndex_;
00270 
00271         //- Track changes in mesh geometry
00272         bool meshChanged_;
00273 
00274         //- Track changes in fields
00275         bool fieldsChanged_;
00276 
00277         //- Selected geometrical parts (internalMesh, patches, ...)
00278         boolList partStatus_;
00279 
00280         //- Datasets corresponding to selected geometrical pieces
00281         //  a negative number indicates that no vtkmesh exists for this piece
00282         labelList partDataset_;
00283 
00284         //- First instance and size of various mesh parts
00285         //  used to index into partStatus_ and partDataset_
00286         partInfo partInfoVolume_;
00287         partInfo partInfoPatches_;
00288         partInfo partInfoLagrangian_;
00289         partInfo partInfoCellZones_;
00290         partInfo partInfoFaceZones_;
00291         partInfo partInfoPointZones_;
00292         partInfo partInfoCellSets_;
00293         partInfo partInfoFaceSets_;
00294         partInfo partInfoPointSets_;
00295 
00296         //- Decomposed cells information (mesh regions)
00297         //  TODO: regions
00298         List<polyDecomp> regionPolyDecomp_;
00299 
00300         //- Decomposed cells information (cellZone meshes)
00301         List<polyDecomp> zonePolyDecomp_;
00302 
00303         //- Decomposed cells information (cellSet meshes)
00304         List<polyDecomp> csetPolyDecomp_;
00305 
00306         //- List of patch names for rendering to window
00307         List<vtkTextActor*> patchTextActorsPtrs_;
00308 
00309     // Private Member Functions
00310 
00311         // Convenience method use to convert the readers from VTK 5
00312         // multiblock API to the current composite data infrastructure
00313         static void AddToBlock
00314         (
00315             vtkMultiBlockDataSet* output,
00316             vtkDataSet* dataset,
00317             const partInfo&,
00318             const label datasetNo,
00319             const string& datasetName
00320         );
00321 
00322         // Convenience method use to convert the readers from VTK 5
00323         // multiblock API to the current composite data infrastructure
00324         static vtkDataSet* GetDataSetFromBlock
00325         (
00326             vtkMultiBlockDataSet* output,
00327             const partInfo&,
00328             const label datasetNo
00329         );
00330 
00331         // Convenience method use to convert the readers from VTK 5
00332         // multiblock API to the current composite data infrastructure
00333         static label GetNumberOfDataSets
00334         (
00335             vtkMultiBlockDataSet* output,
00336             const partInfo&
00337         );
00338 
00339         //- Reset data counters
00340         void resetCounters();
00341 
00342         // Update information helper functions
00343 
00344             //- Update the mesh parts selected in the GUI
00345             void updateMeshPartsStatus();
00346 
00347             //- Internal mesh info
00348             void updateInfoInternalMesh();
00349 
00350             //- Lagrangian info
00351             void updateInfoLagrangian();
00352 
00353             //- Patch info
00354             void updateInfoPatches();
00355 
00356             //- Set info
00357             void updateInfoSets();
00358 
00359             //- Zone info
00360             void updateInfoZones();
00361 
00362             //- Read zone names for zoneType from file
00363             wordList readZoneNames(const word& zoneType);
00364 
00365             //- Add objects of Type to paraview array selection
00366             template<class Type>
00367             label addToSelection
00368             (
00369                 vtkDataArraySelection*,
00370                 const IOobjectList&,
00371                 const string& suffix=string::null
00372             );
00373 
00374             //- Field info
00375             template<template<class> class patchType, class meshType>
00376             void updateInfoFields(vtkDataArraySelection*);
00377 
00378             //- Lagrangian field info
00379             void updateInfoLagrangianFields();
00380 
00381 
00382         // Update helper functions
00383 
00384             //- Foam mesh
00385             void updateFoamMesh();
00386 
00387             //- Reduce memory footprint after conversion
00388             void reduceMemory();
00389 
00390             //- Volume fields
00391             void updateVolFields(vtkMultiBlockDataSet*);
00392 
00393             //- Point fields
00394             void updatePointFields(vtkMultiBlockDataSet*);
00395 
00396             //- Lagrangian fields
00397             void updateLagrangianFields(vtkMultiBlockDataSet*);
00398 
00399 
00400         // Mesh conversion functions
00401 
00402             //- Volume mesh
00403             void convertMeshVolume(vtkMultiBlockDataSet*, int& blockNo);
00404 
00405             //- Lagrangian mesh
00406             void convertMeshLagrangian(vtkMultiBlockDataSet*, int& blockNo);
00407 
00408             //- Patch meshes
00409             void convertMeshPatches(vtkMultiBlockDataSet*, int& blockNo);
00410 
00411             //- Cell zone meshes
00412             void convertMeshCellZones(vtkMultiBlockDataSet*, int& blockNo);
00413 
00414             //- Face zone meshes
00415             void convertMeshFaceZones(vtkMultiBlockDataSet*, int& blockNo);
00416 
00417             //- Point zone meshes
00418             void convertMeshPointZones(vtkMultiBlockDataSet*, int& blockNo);
00419 
00420             //- Cell set meshes
00421             void convertMeshCellSets(vtkMultiBlockDataSet*, int& blockNo);
00422 
00423             //- Face set meshes
00424             void convertMeshFaceSets(vtkMultiBlockDataSet*, int& blockNo);
00425 
00426             //- Point set meshes
00427             void convertMeshPointSets(vtkMultiBlockDataSet*, int& blockNo);
00428 
00429 
00430         // Add mesh functions
00431 
00432             //- Add internal mesh/cell set meshes
00433             vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&);
00434 
00435             //- Add Lagrangian mesh
00436             vtkPolyData* lagrangianVTKMesh
00437             (
00438                 const fvMesh&,
00439                 const word& cloudName
00440             );
00441 
00442             //- Add patch mesh
00443             vtkPolyData* patchVTKMesh(const polyPatch&);
00444 
00445             //- Add face zone mesh
00446             vtkPolyData* faceZoneVTKMesh
00447             (
00448                 const fvMesh&,
00449                 const labelList& faceLabels
00450             );
00451 
00452             //- Add point zone
00453             vtkPolyData* pointZoneVTKMesh
00454             (
00455                 const fvMesh&,
00456                 const labelList& pointLabels
00457             );
00458 
00459             //- Add face set mesh
00460             vtkPolyData* faceSetVTKMesh
00461             (
00462                 const fvMesh&,
00463                 const faceSet&
00464             );
00465 
00466             //- Add point mesh
00467             vtkPolyData* pointSetVTKMesh
00468             (
00469                 const fvMesh&,
00470                 const pointSet&
00471             );
00472 
00473         // Field conversion functions
00474 
00475             //- Convert volume fields
00476             void convertVolFields(vtkMultiBlockDataSet*);
00477 
00478             //- Convert point fields
00479             void convertPointFields(vtkMultiBlockDataSet*);
00480 
00481             //- Convert Lagrangian fields
00482             void convertLagrangianFields(vtkMultiBlockDataSet*);
00483 
00484 
00485         //- Add the fields in the selected time directory to the selection
00486         //  lists
00487         template<class GeoField>
00488         label addObjectsToSelection
00489         (
00490             vtkDataArraySelection*,
00491             const IOobjectList&,
00492             const string& suffix=string::null
00493         );
00494 
00495 
00496         // Convert Foam fields
00497 
00498             //- Volume fields - all types
00499             template<class Type>
00500             void convertVolFields
00501             (
00502                 const fvMesh&,
00503                 const PtrList<PrimitivePatchInterpolation<primitivePatch> >&,
00504                 const IOobjectList&,
00505                 vtkMultiBlockDataSet* output
00506             );
00507 
00508             //- Volume field - all selected parts
00509             template<class Type>
00510             void convertVolFieldBlock
00511             (
00512                 const GeometricField<Type, fvPatchField, volMesh>&,
00513                 autoPtr<GeometricField<Type, pointPatchField, pointMesh> >&,
00514                 vtkMultiBlockDataSet* output,
00515                 const partInfo& selector,
00516                 const List<polyDecomp>& decompLst
00517             );
00518 
00519             //- Volume field
00520             template<class Type>
00521             void convertVolField
00522             (
00523                 const GeometricField<Type, fvPatchField, volMesh>&,
00524                 vtkMultiBlockDataSet* output,
00525                 const partInfo&,
00526                 const label datasetNo,
00527                 const polyDecomp&
00528             );
00529 
00530             //- Patch field
00531             template<class Type>
00532             void convertPatchField
00533             (
00534                 const word& name,
00535                 const Field<Type>&,
00536                 vtkMultiBlockDataSet* output,
00537                 const partInfo&,
00538                 const label datasetNo
00539             );
00540 
00541             //- face set/zone field
00542             template<class Type>
00543             void convertFaceField
00544             (
00545                 const GeometricField<Type, fvPatchField, volMesh>&,
00546                 vtkMultiBlockDataSet* output,
00547                 const partInfo&,
00548                 const label datasetNo,
00549                 const fvMesh&,
00550                 const labelList& faceLabels
00551             );
00552 
00553             //- face set/zone field
00554             template<class Type>
00555             void convertFaceField
00556             (
00557                 const GeometricField<Type, fvPatchField, volMesh>&,
00558                 vtkMultiBlockDataSet* output,
00559                 const partInfo&,
00560                 const label datasetNo,
00561                 const fvMesh&,
00562                 const faceSet&
00563             );
00564 
00565             //- Lagrangian fields - all types
00566             template<class Type>
00567             void convertLagrangianFields
00568             (
00569                 const IOobjectList&,
00570                 vtkMultiBlockDataSet* output,
00571                 const label datasetNo
00572             );
00573 
00574             //- Lagrangian field
00575             template<class Type>
00576             void convertLagrangianField
00577             (
00578                 const IOField<Type>&,
00579                 vtkMultiBlockDataSet* output,
00580                 const partInfo&,
00581                 const label datasetNo
00582             );
00583 
00584             //- Point fields - all types
00585             template<class Type>
00586             void convertPointFields
00587             (
00588                 const fvMesh&,
00589                 const pointMesh&,
00590                 const IOobjectList&,
00591                 vtkMultiBlockDataSet* output
00592             );
00593 
00594             //- Point field - all selected parts
00595             template<class Type>
00596             void convertPointFieldBlock
00597             (
00598                 const GeometricField<Type, pointPatchField, pointMesh>&,
00599                 vtkMultiBlockDataSet* output,
00600                 const partInfo& selector,
00601                 const List<polyDecomp>&
00602             );
00603 
00604             //- Point fields
00605             template<class Type>
00606             void convertPointField
00607             (
00608                 const GeometricField<Type, pointPatchField, pointMesh>&,
00609                 const GeometricField<Type, fvPatchField, volMesh>&,
00610                 vtkMultiBlockDataSet* output,
00611                 const partInfo&,
00612                 const label datasetNo,
00613                 const polyDecomp&
00614             );
00615 
00616             //- Patch point field
00617             template<class Type>
00618             void convertPatchPointField
00619             (
00620                 const word& name,
00621                 const Field<Type>&,
00622                 vtkMultiBlockDataSet* output,
00623                 const partInfo&,
00624                 const label datasetNo
00625             );
00626 
00627 
00628        // GUI selection helper functions
00629 
00630             //- Extract up to the first non-word characters
00631             inline static word getFirstWord(const char*);
00632 
00633             //- Only keep what is listed in hashSet
00634             static void pruneObjectList
00635             (
00636                 IOobjectList&,
00637                 const wordHashSet&
00638             );
00639 
00640             //- Retrieve the current selections
00641             static wordHashSet getSelected(vtkDataArraySelection*);
00642 
00643             //- Retrieve a sub-list of the current selections
00644             static wordHashSet getSelected
00645             (
00646                 vtkDataArraySelection*,
00647                 const partInfo&
00648             );
00649 
00650             //- Retrieve the current selections
00651             static stringList getSelectedArrayEntries(vtkDataArraySelection*);
00652 
00653             //- Retrieve a sub-list of the current selections
00654             static stringList getSelectedArrayEntries
00655             (
00656                 vtkDataArraySelection*,
00657                 const partInfo&
00658             );
00659 
00660             //- Set selection(s)
00661             static void setSelectedArrayEntries
00662             (
00663                 vtkDataArraySelection*,
00664                 const stringList&
00665             );
00666 
00667             //- Get the first word from the mesh parts selection
00668             word getPartName(int);
00669 
00670 
00671         //- Disallow default bitwise copy construct
00672         vtkPV3Foam(const vtkPV3Foam&);
00673 
00674         //- Disallow default bitwise assignment
00675         void operator=(const vtkPV3Foam&);
00676 
00677 
00678 public:
00679 
00680     //- Static data members
00681 
00682         ClassName("vtkPV3Foam");
00683 
00684 
00685     // Constructors
00686 
00687         //- Construct from components
00688         vtkPV3Foam
00689         (
00690             const char* const FileName,
00691             vtkPV3FoamReader* reader
00692         );
00693 
00694 
00695     //- Destructor
00696 
00697         ~vtkPV3Foam();
00698 
00699 
00700     // Member Functions
00701 
00702         //- Update
00703         void updateInfo();
00704 
00705         void Update
00706         (
00707             vtkMultiBlockDataSet* output,
00708             vtkMultiBlockDataSet* lagrangianOutput
00709         );
00710 
00711         //- Clean any storage
00712         void CleanUp();
00713 
00714         //- Allocate and return a list of selected times
00715         //  returns the count via the parameter
00716         double* findTimes(int& nTimeSteps);
00717 
00718         //- Add patch names to the display
00719         void addPatchNames(vtkRenderer* renderer);
00720 
00721         //- Remove patch names from the display
00722         void removePatchNames(vtkRenderer* renderer);
00723 
00724         //- set the runTime to the first plausible request time,
00725         //  returns the timeIndex
00726         //  sets to "constant" on error
00727         int setTime(int count, const double requestTimes[]);
00728 
00729 
00730         //- The current time index
00731         int timeIndex() const
00732         {
00733            return timeIndex_;
00734         }
00735 
00736 
00737      // Access
00738 
00739         //- Debug information
00740         void PrintSelf(ostream&, vtkIndent) const;
00741 
00742         //- Simple memory used debugging information
00743         static void printMemory();
00744 
00745 };
00746 
00747 
00748 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00749 
00750 } // End namespace Foam
00751 
00752 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00753 
00754 #    include "vtkPV3FoamI.H"
00755 
00756 #endif
00757 
00758 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd