Commit 0d02dd8d authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: first pv reader version with delayed assembly of output blocks

- this greatly simplifies data management and opens the possibility of
  reusing converted vtk meshes instead of converting each time.
parent 12231112
......@@ -38,6 +38,7 @@ License
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkSmartPointer.h"
#include "vtkInformation.h"
// Templates (only needed here)
#include "vtkPVFoamUpdateTemplates.C"
......@@ -117,6 +118,70 @@ void Foam::vtkPVFoam::resetCounters()
}
template<class Container>
bool Foam::vtkPVFoam::addOutputBlock
(
vtkMultiBlockDataSet* output,
const HashTable<Container, string>& cache,
const arrayRange& selector,
const bool singleDataset
) const
{
const auto blockNo = output->GetNumberOfBlocks();
vtkSmartPointer<vtkMultiBlockDataSet> block;
int datasetNo = 0;
for (auto partId : selector)
{
if (selectedPartIds_.found(partId))
{
const auto& longName = selectedPartIds_[partId];
const word shortName = getPartName(partId);
auto iter = cache.find(longName);
if (iter.found() && (*iter).vtkmesh)
{
auto dataset = (*iter).vtkmesh;
if (singleDataset)
{
output->SetBlock(blockNo, dataset);
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
shortName.c_str()
);
++datasetNo;
break;
}
else if (datasetNo == 0)
{
block = vtkSmartPointer<vtkMultiBlockDataSet>::New();
output->SetBlock(blockNo, block);
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
selector.name()
);
}
block->SetBlock(datasetNo, dataset);
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(),
shortName.c_str()
);
++datasetNo;
}
}
}
return datasetNo;
}
int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[])
{
Time& runTime = dbPtr_();
......@@ -417,11 +482,6 @@ void Foam::vtkPVFoam::Update
// Set up mesh parts selection(s)
{
if (debug)
{
Info<< "<beg> updateMeshPartsStatus" << endl;
}
vtkDataArraySelection* selection = reader_->GetPartSelection();
const int n = selection->GetNumberOfArrays();
......@@ -464,11 +524,6 @@ void Foam::vtkPVFoam::Update
<< " : " << str << nl;
}
}
if (debug)
{
Info<< "<end> updateMeshPartsStatus" << endl;
}
}
reader_->UpdateProgress(0.15);
......@@ -538,49 +593,51 @@ void Foam::vtkPVFoam::Update
cachedVtp_.retain(nowActive);
cachedVtu_.retain(nowActive);
// Reset (expire) dataset ids
partDataset_.clear();
// Convert meshes - start port0 at block=0
int blockNo = 0;
convertMeshVolume(output, blockNo);
convertMeshPatches(output, blockNo);
convertMeshVolume();
convertMeshPatches();
reader_->UpdateProgress(0.6);
if (reader_->GetIncludeZones())
{
convertMeshCellZones(output, blockNo);
convertMeshFaceZones(output, blockNo);
convertMeshPointZones(output, blockNo);
convertMeshCellZones();
convertMeshFaceZones();
convertMeshPointZones();
reader_->UpdateProgress(0.65);
}
if (reader_->GetIncludeSets())
{
convertMeshCellSets(output, blockNo);
convertMeshFaceSets(output, blockNo);
convertMeshPointSets(output, blockNo);
convertMeshCellSets();
convertMeshFaceSets();
convertMeshPointSets();
reader_->UpdateProgress(0.7);
}
if (outputLagrangian)
{
// Lagrangian dual port - restart port1 at block=0
blockNo = 0;
convertMeshLagrangian(outputLagrangian, blockNo);
}
else
{
convertMeshLagrangian(output, blockNo);
}
convertMeshLagrangian();
reader_->UpdateProgress(0.8);
// Update fields
convertVolFields(output);
convertPointFields(output);
convertLagrangianFields(outputLagrangian ? outputLagrangian : output);
convertVolFields();
convertPointFields();
convertLagrangianFields();
// Assemble multiblock output
addOutputBlock(output, cachedVtu_, rangeVolume_, true); // One dataset
addOutputBlock(output, cachedVtp_, rangePatches_);
addOutputBlock(output, cachedVtu_, rangeCellZones_);
addOutputBlock(output, cachedVtp_, rangeFaceZones_);
addOutputBlock(output, cachedVtp_, rangePointZones_);
addOutputBlock(output, cachedVtu_, rangeCellSets_);
addOutputBlock(output, cachedVtp_, rangeFaceSets_);
addOutputBlock(output, cachedVtp_, rangePointSets_);
addOutputBlock
(
(outputLagrangian ? outputLagrangian : output),
cachedVtp_,
rangeLagrangian_
);
if (debug)
{
......
......@@ -55,6 +55,10 @@ SourceFiles
#include "volPointInterpolation.H"
#include "foamPvCore.H"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
......@@ -65,11 +69,8 @@ class vtkPVFoamReader;
class vtkRenderer;
class vtkTextActor;
class vtkMultiBlockDataSet;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkIndent;
template<class T> class vtkSmartPointer;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -82,6 +83,7 @@ class Time;
class fvMesh;
class IOobjectList;
class polyPatch;
class fvMeshSubset;
template<class Type> class IOField;
template<class Type> class Field;
......@@ -160,16 +162,19 @@ class vtkPVFoam
}
};
//- Bookkeeping for vtkPolyData
class foamVtpData
{
public:
vtkSmartPointer<vtkPolyData> vtkmesh;
};
//- Bookkeeping for vtkUnstructuredGrid
class foamVtuData
:
public polyDecomp
class foamVtuData : public polyDecomp
{
public:
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh;
};
......@@ -202,9 +207,6 @@ class vtkPVFoam
//- The index of selected parts mapped to their names
Map<string> selectedPartIds_;
//- Datasets corresponding to selected geometrical pieces
Map<label> partDataset_;
//- Any information for 2D (VTP) geometries
HashTable<foamVtpData, string> cachedVtp_;
......@@ -213,7 +215,7 @@ class vtkPVFoam
//- First instance and size of various mesh parts
// used to index into selectedPartIds and thus indirectly into
// cachedVtp, cachedVtu and partDataset
// cachedVtp, cachedVtu
arrayRange rangeVolume_;
arrayRange rangePatches_;
arrayRange rangeLagrangian_;
......@@ -230,6 +232,16 @@ class vtkPVFoam
// Private Member Functions
template<class Container>
bool addOutputBlock
(
vtkMultiBlockDataSet* output,
const HashTable<Container, string>& cache,
const arrayRange& selector,
const bool singleDataset = false
) const;
//- Reset data counters
void resetCounters();
......@@ -279,31 +291,38 @@ class vtkPVFoam
// Mesh conversion functions
//- Convert volume mesh
void convertMeshVolume(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshVolume();
//- Convert Lagrangian points
void convertMeshLagrangian(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshLagrangian();
//- Convert mesh patches
void convertMeshPatches(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshPatches();
//- Convert subsetted mesh
void convertMeshSubset
(
const fvMeshSubset& subsetter,
const string& longName
);
//- Convert cell zones
void convertMeshCellZones(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshCellZones();
//- Convert face zones
void convertMeshFaceZones(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshFaceZones();
//- Convert point zones
void convertMeshPointZones(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshPointZones();
//- Convert cell sets
void convertMeshCellSets(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshCellSets();
//- Convert face sets
void convertMeshFaceSets(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshFaceSets();
//- Convert point sets
void convertMeshPointSets(vtkMultiBlockDataSet* output, int& blockNo);
void convertMeshPointSets();
// Add mesh functions
......@@ -359,13 +378,13 @@ class vtkPVFoam
//- Convert volume fields
void convertVolFields(vtkMultiBlockDataSet* output);
void convertVolFields();
//- Convert point fields
void convertPointFields(vtkMultiBlockDataSet* output);
void convertPointFields();
//- Convert Lagrangian fields
void convertLagrangianFields(vtkMultiBlockDataSet* output);
void convertLagrangianFields();
// Convert OpenFOAM fields
......@@ -375,8 +394,7 @@ class vtkPVFoam
void convertVolField
(
const PtrList<patchInterpolator>& patchInterpList,
const GeometricField<Type, fvPatchField, volMesh>& fld,
vtkMultiBlockDataSet* output
const GeometricField<Type, fvPatchField, volMesh>& fld
);
//- Volume fields - all types
......@@ -385,8 +403,7 @@ class vtkPVFoam
(
const fvMesh& mesh,
const PtrList<patchInterpolator>& patchInterpList,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
const IOobjectList& objects
);
//- Volume internal fields (DimensionedField)- all types
......@@ -395,8 +412,7 @@ class vtkPVFoam
(
const fvMesh& mesh,
const PtrList<patchInterpolator>& patchInterpList,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
const IOobjectList& objects
);
//- Volume field - all selected parts
......@@ -405,7 +421,6 @@ class vtkPVFoam
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr,
vtkMultiBlockDataSet* output,
const arrayRange& range
);
......@@ -414,8 +429,7 @@ class vtkPVFoam
void convertLagrangianFields
(
const IOobjectList& objects,
vtkMultiBlockDataSet* output,
const label datasetNo
vtkPolyData* vtkmesh
);
//- Point fields - all types
......@@ -423,8 +437,7 @@ class vtkPVFoam
void convertPointFields
(
const pointMesh& pMesh,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
const IOobjectList& objectst
);
//- Point field - all selected parts
......@@ -432,7 +445,6 @@ class vtkPVFoam
void convertPointFieldBlock
(
const GeometricField<Type, pointPatchField, pointMesh>& pfld,
vtkMultiBlockDataSet* output,
const arrayRange& range
);
......
......@@ -53,8 +53,7 @@ template<class Type>
void Foam::vtkPVFoam::convertVolField
(
const PtrList<patchInterpolator>& patchInterpList,
const GeometricField<Type, fvPatchField, volMesh>& fld,
vtkMultiBlockDataSet* output
const GeometricField<Type, fvPatchField, volMesh>& fld
)
{
const fvMesh& mesh = fld.mesh();
......@@ -78,38 +77,12 @@ void Foam::vtkPVFoam::convertVolField
);
}
// Convert activated internalMesh regions
convertVolFieldBlock
(
fld,
ptfPtr,
output,
rangeVolume_
);
// Convert activated cellZones
convertVolFieldBlock
(
fld,
ptfPtr,
output,
rangeCellZones_
);
// Convert activated cellSets
convertVolFieldBlock
(
fld,
ptfPtr,
output,
rangeCellSets_
);
//
// Convert patches - if activated
// - skip field conversion for groups
//
convertVolFieldBlock(fld, ptfPtr, rangeVolume_); // internalMesh
convertVolFieldBlock(fld, ptfPtr, rangeCellZones_); // cellZones
convertVolFieldBlock(fld, ptfPtr, rangeCellSets_); // cellSets
// Patches - skip field conversion for groups
for (auto partId : rangePatches_)
{
if
......@@ -122,7 +95,6 @@ void Foam::vtkPVFoam::convertVolField
}
const word patchName = getPartName(partId);
const label datasetNo = partDataset_.lookup(partId, -1);
const label patchId = patches.findPatchID(patchName);
if (patchId < 0)
......@@ -130,15 +102,12 @@ void Foam::vtkPVFoam::convertVolField
continue;
}
vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData>
(
output, rangePatches_, datasetNo
);
if (!vtkmesh)
auto iter = cachedVtp_.find(selectedPartIds_[partId]);
if (!iter.found() || !(*iter).vtkmesh)
{
continue;
}
auto vtkmesh = (*iter).vtkmesh;
const fvPatchField<Type>& ptf = fld.boundaryField()[patchId];
......@@ -201,9 +170,8 @@ void Foam::vtkPVFoam::convertVolField
}
}
//
// Convert face zones - if activated
//
// Face Zones
for (auto partId : rangeFaceZones_)
{
if (!selectedPartIds_.found(partId))
......@@ -211,14 +179,14 @@ void Foam::vtkPVFoam::convertVolField
continue;
}
const word zoneName = getPartName(partId);
const label datasetNo = partDataset_.lookup(partId, -1);
if (datasetNo < 0)
auto iter = cachedVtu_.find(selectedPartIds_[partId]);
if (!iter.found() || !(*iter).vtkmesh)
{
continue;
}
auto vtkmesh = (*iter).vtkmesh;
const word zoneName = getPartName(partId);
const faceZoneMesh& zMesh = mesh.faceZones();
const label zoneId = zMesh.findZoneID(zoneName);
......@@ -227,28 +195,19 @@ void Foam::vtkPVFoam::convertVolField
continue;
}
vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData>
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
(
output, rangeFaceZones_, datasetNo
fld,
zMesh[zoneId]
);
if (vtkmesh)
{
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
(
fld,
zMesh[zoneId]
);
vtkmesh->GetCellData()->AddArray(cdata);
}
vtkmesh->GetCellData()->AddArray(cdata);
// TODO: points
}
//
// Convert face sets - if activated
//
// Face Sets
for (auto partId : rangeFaceSets_)
{
if (!selectedPartIds_.found(partId))
......@@ -256,19 +215,14 @@ void Foam::vtkPVFoam::convertVolField
continue;
}
const word selectName = getPartName(partId);
const label datasetNo = partDataset_.lookup(partId, -1);
vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData>
(
output, rangeFaceSets_, datasetNo
);
if (!vtkmesh)
auto iter = cachedVtu_.find(selectedPartIds_[partId]);
if (!iter.found() || !(*iter).vtkmesh)
{
continue;
}
auto vtkmesh = (*iter).vtkmesh;
const word selectName = getPartName(partId);
const faceSet fSet(mesh, selectName);
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
......@@ -289,13 +243,12 @@ void Foam::vtkPVFoam::convertVolFields
(
const fvMesh& mesh,
const PtrList<patchInterpolator>& patchInterpList,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
const IOobjectList& objects
)
{
forAllConstIters(objects, iter)
{
// restrict to GeometricField<Type, ...>
// Restrict to GeometricField<Type, ...>
if
(
iter()->headerClassName()
......@@ -313,7 +266,7 @@ void Foam::vtkPVFoam::convertVolFields
);
// Convert
convertVolField(patchInterpList, fld, output);
convertVolField(patchInterpList, fld);
}