Commit 09f0cfd5 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

STYLE: reduce number of small methods in paraview reader

- improves the overview of the code
parent 48bf71dd
......@@ -47,7 +47,7 @@ License
// STL includes
#include <vector>
#undef EXPERIMENTAL_TIME_CACHING
#undef VTKPVFOAM_DUALPORT
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -62,10 +62,8 @@ vtkPVFoamReader::vtkPVFoamReader()
vtkDebugMacro(<<"Constructor");
SetNumberOfInputPorts(0);
FileName = nullptr;
backend_ = nullptr;
output0_ = nullptr;
#ifdef VTKPVFOAM_DUALPORT
// Add second output for the Lagrangian
......@@ -84,7 +82,7 @@ vtkPVFoamReader::vtkPVFoamReader()
CacheMesh = true;
SkipZeroTime = false;
SkipZeroTime = true;
ExtrapolatePatches = false;
UseVTKPolyhedron = false;
IncludeSets = false;
......@@ -152,12 +150,6 @@ vtkPVFoamReader::~vtkPVFoamReader()
delete[] FileName;
}
if (output0_)
{
output0_->Delete();
}
PartSelection->RemoveAllObservers();
VolFieldSelection->RemoveAllObservers();
PointFieldSelection->RemoveAllObservers();
......@@ -258,7 +250,7 @@ int vtkPVFoamReader::RequestInformation
<<"time-range " << times.front() << ':' << times.back() << "\n"
<<"times " << times.size() << "(";
for (const double& val : times)
for (auto val : times)
{
cout<< ' ' << val;
}
......@@ -294,12 +286,12 @@ int vtkPVFoamReader::RequestData
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
vtkErrorMacro("FileName must be specified!");
return 0;
}
if (!backend_)
{
// catch some previous error
// Catch some previous error
vtkErrorMacro("Reader failed - perhaps no mesh?");
return 0;
}
......@@ -365,76 +357,23 @@ int vtkPVFoamReader::RequestData
)
);
if (Foam::vtkPVFoam::debug)
{
cout<< "update output with "
<< output->GetNumberOfBlocks() << " blocks\n";
}
#ifdef EXPERIMENTAL_TIME_CACHING
bool needsUpdate = false;
if (!output0_)
{
output0_ = vtkMultiBlockDataSet::New();
needsUpdate = true;
}
// This experimental bit of code seems to work for the geometry,
// but trashes the fields and still triggers the GeometryFilter
if (needsUpdate)
{
backend_->Update(output);
output0_->ShallowCopy(output);
}
else
{
output->ShallowCopy(output0_);
}
if (Foam::vtkPVFoam::debug)
{
if (needsUpdate)
{
cout<< "full UPDATE ---------\n";
}
else
{
cout<< "cached UPDATE ---------\n";
}
cout<< "UPDATED output: ";
output->Print(cout);
cout<< "UPDATED output0_: ";
output0_->Print(cout);
}
#else
#ifdef VTKPVFOAM_DUALPORT
backend_->Update
vtkMultiBlockDataSet* output1 = vtkMultiBlockDataSet::SafeDownCast
(
output,
vtkMultiBlockDataSet::SafeDownCast
outputVector->GetInformationObject(1)->Get
(
outputVector->GetInformationObject(1)->Get
(
vtkMultiBlockDataSet::DATA_OBJECT()
)
vtkMultiBlockDataSet::DATA_OBJECT()
)
);
backend_->Update(output, output1);
#else
backend_->Update(output, output);
backend_->Update(output, nullptr);
#endif
updatePatchNamesView(ShowPatchNames);
#endif
// Do any cleanup on the OpenFOAM side
backend_->CleanUp();
backend_->UpdateFinalize();
return 1;
}
......
......@@ -251,9 +251,6 @@ private:
vtkDataArraySelection* PointFieldSelection;
vtkDataArraySelection* LagrangianFieldSelection;
//- Cached data for output port0 (experimental!)
vtkMultiBlockDataSet* output0_;
//- Backend portion of the reader
Foam::vtkPVFoam* backend_;
};
......
......@@ -39,6 +39,9 @@ License
#include "vtkTextProperty.h"
#include "vtkSmartPointer.h"
// Templates (only needed here)
#include "vtkPVFoamUpdateTemplates.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
......@@ -100,31 +103,6 @@ void Foam::vtkPVFoam::resetCounters()
}
void Foam::vtkPVFoam::reduceMemory()
{
forAll(regionVtus_, i)
{
regionVtus_[i].clear();
}
forAll(zoneVtus_, i)
{
zoneVtus_[i].clear();
}
forAll(csetVtus_, i)
{
csetVtus_[i].clear();
}
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = nullptr;
}
}
int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[])
{
Time& runTime = dbPtr_();
......@@ -201,52 +179,6 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[])
}
void Foam::vtkPVFoam::updateMeshPartsStatus()
{
if (debug)
{
Info<< "<beg> updateMeshPartsStatus" << endl;
}
vtkDataArraySelection* selection = reader_->GetPartSelection();
label nElem = selection->GetNumberOfArrays();
if (partStatus_.size() != nElem)
{
partStatus_.setSize(nElem);
partStatus_ = false;
meshChanged_ = true;
}
// this needs fixing if we wish to re-use the datasets
partDataset_.setSize(nElem);
partDataset_ = -1;
// Read the selected mesh parts (zones, patches ...) and add to list
forAll(partStatus_, partId)
{
const int setting = selection->GetArraySetting(partId);
if (partStatus_[partId] != setting)
{
partStatus_[partId] = setting;
meshChanged_ = true;
}
if (debug > 1)
{
Info<< " part[" << partId << "] = "
<< partStatus_[partId]
<< " : " << selection->GetArrayName(partId) << endl;
}
}
if (debug)
{
Info<< "<end> updateMeshPartsStatus" << endl;
}
}
Foam::word Foam::vtkPVFoam::getPartName(const int partId)
{
return getFoamName(reader_->GetPartArrayName(partId));
......@@ -270,7 +202,7 @@ Foam::vtkPVFoam::vtkPVFoam
meshChanged_(true),
fieldsChanged_(true),
rangeVolume_("unzoned"),
rangePatches_("patches"),
rangePatches_("patch"),
rangeLagrangian_("lagrangian"),
rangeCellZones_("cellZone"),
rangeFaceZones_("faceZone"),
......@@ -433,7 +365,18 @@ void Foam::vtkPVFoam::updateInfo()
}
// Update volume, point and lagrangian fields
updateInfoFields();
updateInfoFields<fvPatchField, volMesh>
(
reader_->GetVolFieldSelection()
);
updateInfoFields<pointPatchField, pointMesh>
(
reader_->GetPointFieldSelection()
);
updateInfoLagrangianFields
(
reader_->GetLagrangianFieldSelection()
);
if (debug)
{
......@@ -442,84 +385,121 @@ void Foam::vtkPVFoam::updateInfo()
}
void Foam::vtkPVFoam::updateFoamMesh()
void Foam::vtkPVFoam::Update
(
vtkMultiBlockDataSet* output,
vtkMultiBlockDataSet* outputLagrangian
)
{
if (debug)
{
Info<< "<beg> updateFoamMesh" << endl;
cout<< "<beg> Foam::vtkPVFoam::Update\n";
output->Print(cout);
if (outputLagrangian) outputLagrangian->Print(cout);
printMemory();
}
reader_->UpdateProgress(0.1);
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = nullptr;
}
// Check to see if the OpenFOAM mesh has been created
if (!meshPtr_)
// Set up mesh parts selection(s)
{
if (debug)
{
Info<< "Creating OpenFOAM mesh for region " << meshRegion_
<< " at time=" << dbPtr_().timeName()
<< endl;
Info<< "<beg> updateMeshPartsStatus" << endl;
}
vtkDataArraySelection* selection = reader_->GetPartSelection();
label nElem = selection->GetNumberOfArrays();
if (partStatus_.size() != nElem)
{
partStatus_.setSize(nElem);
partStatus_ = false;
meshChanged_ = true;
}
meshPtr_ = new fvMesh
(
IOobject
(
meshRegion_,
dbPtr_().timeName(),
dbPtr_(),
IOobject::MUST_READ
)
);
// this needs fixing if we wish to re-use the datasets
partDataset_.setSize(nElem);
partDataset_ = -1;
meshChanged_ = true;
}
else
{
// Read the selected mesh parts (zones, patches ...) and add to list
forAll(partStatus_, partId)
{
const int setting = selection->GetArraySetting(partId);
if (partStatus_[partId] != setting)
{
partStatus_[partId] = setting;
meshChanged_ = true;
}
if (debug > 1)
{
Info<< " part[" << partId << "] = "
<< partStatus_[partId]
<< " : " << selection->GetArrayName(partId) << endl;
}
}
if (debug)
{
Info<< "Using existing OpenFOAM mesh" << endl;
Info<< "<end> updateMeshPartsStatus" << endl;
}
}
if (debug)
reader_->UpdateProgress(0.15);
// Update the OpenFOAM mesh
{
Info<< "<end> updateFoamMesh" << endl;
printMemory();
}
}
if (debug)
{
Info<< "<beg> updateFoamMesh" << endl;
printMemory();
}
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = nullptr;
}
void Foam::vtkPVFoam::Update
(
vtkMultiBlockDataSet* output,
vtkMultiBlockDataSet* lagrangianOutput
)
{
if (debug)
{
cout<< "<beg> Foam::vtkPVFoam::Update - output with "
<< output->GetNumberOfBlocks() << " and "
<< lagrangianOutput->GetNumberOfBlocks() << " blocks\n";
output->Print(cout);
lagrangianOutput->Print(cout);
printMemory();
}
reader_->UpdateProgress(0.1);
// Check to see if the OpenFOAM mesh has been created
if (!meshPtr_)
{
if (debug)
{
Info<< "Creating OpenFOAM mesh for region " << meshRegion_
<< " at time=" << dbPtr_().timeName()
<< endl;
// Set up mesh parts selection(s)
updateMeshPartsStatus();
}
reader_->UpdateProgress(0.15);
meshPtr_ = new fvMesh
(
IOobject
(
meshRegion_,
dbPtr_().timeName(),
dbPtr_(),
IOobject::MUST_READ
)
);
meshChanged_ = true;
}
else
{
if (debug)
{
Info<< "Using existing OpenFOAM mesh" << endl;
}
}
if (debug)
{
Info<< "<end> updateFoamMesh" << endl;
printMemory();
}
}
// Update the OpenFOAM mesh
updateFoamMesh();
reader_->UpdateProgress(0.4);
// Convert meshes - start port0 at block=0
......@@ -545,18 +525,24 @@ void Foam::vtkPVFoam::Update
reader_->UpdateProgress(0.7);
}
#ifdef VTKPVFOAM_DUALPORT
// restart port1 at block=0
blockNo = 0;
#endif
convertMeshLagrangian(lagrangianOutput, blockNo);
if (outputLagrangian)
{
// Lagrangian dual port - restart port1 at block=0
blockNo = 0;
convertMeshLagrangian(outputLagrangian, blockNo);
}
else
{
convertMeshLagrangian(output, blockNo);
}
reader_->UpdateProgress(0.8);
// Update fields
convertVolFields(output);
convertPointFields(output);
convertLagrangianFields(lagrangianOutput);
convertLagrangianFields(outputLagrangian ? outputLagrangian : output);
if (debug)
{
Info<< "done reader part" << nl << endl;
......@@ -564,13 +550,31 @@ void Foam::vtkPVFoam::Update
reader_->UpdateProgress(0.95);
meshChanged_ = fieldsChanged_ = false;
// Standard memory cleanup
forAll(regionVtus_, i)
{
regionVtus_[i].clear();
}
forAll(zoneVtus_, i)
{
zoneVtus_[i].clear();
}
forAll(csetVtus_, i)
{
csetVtus_[i].clear();
}
}
void Foam::vtkPVFoam::CleanUp()
void Foam::vtkPVFoam::UpdateFinalize()
{
// reclaim some memory
reduceMemory();
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = nullptr;
}
reader_->UpdateProgress(1.0);
}
......
......@@ -55,8 +55,6 @@ SourceFiles
#include "volPointInterpolation.H"
#include "foamPvCore.H"
#undef VTKPVFOAM_DUALPORT
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
......@@ -231,9 +229,6 @@ class vtkPVFoam
// Update information helper functions
//- Update the mesh parts selected in the GUI
void updateMeshPartsStatus();
//- Internal mesh info
void updateInfoInternalMesh(vtkDataArraySelection*);
......@@ -259,9 +254,6 @@ class vtkPVFoam
const ZoneMesh<ZoneType, polyMesh>& zmesh
);
//- Field (volume, point, lagrangian) info
void updateInfoFields();
//- Field info
template<template<class> class patchType, class meshType>
void updateInfoFields
......@@ -273,15 +265,6 @@ class vtkPVFoam
void updateInfoLagrangianFields(vtkDataArraySelection* select);
// Update helper functions
//- OpenFOAM mesh
void updateFoamMesh();
//- Reduce memory footprint after conversion
void reduceMemory();
// Mesh conversion functions
//- Convert volume mesh
......@@ -506,19 +489,19 @@ public:
void Update
(
vtkMultiBlockDataSet* output,
vtkMultiBlockDataSet* lagrangianOutput
vtkMultiBlockDataSet* outputLagrangian
);
//- Clean any storage
void CleanUp();
//- 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);
//- 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;
//- Add/remove patch names to/from the view
void renderPatchNames(vtkRenderer*, const bool show);