Commit 062bb366 authored by Mark Olesen's avatar Mark Olesen
Browse files

PV3FoamReader - code cleanup

 - streamlined code somewhat, minor attempt to reclaim some memory
 - now use "mesh parts" for patches/zones/sets/etc throughout to avoid
   ambiguity with mesh regions
 - collect superCells and addPointCellLabels in a class. The old version
   actually seemed to have overwritten the addPointCellLabels with each
   cellSet/cellZone. This means that part of the pointFields would be trashed
   in the combination of polyhedral cells, cellSets/cellZones and internalMesh
 - polyDecomp information for muitiple mesh regions, but not yet exploited
 - pointFields now working for cellZones/cellSets
 - extroplating fields onto walls also works as expected for interpolated
   pointFields
 - added tooltips to reader GUI

TODO:
 - pointFields (real and interpolated) for faceSets/faceZones
parent 775ef2c8
......@@ -12,7 +12,7 @@
animateable="0">
<FileListDomain name="files"/>
<Documentation>
Specifies the filename for the OpenFOAM Reader
Specifies the filename for the OpenFOAM Reader
</Documentation>
</StringVectorProperty>
......@@ -32,25 +32,25 @@
<TimeRangeInformationHelper/>
</DoubleVectorProperty>
<!-- Available Region array -->
<!-- Available Parts (volume, patches, lagrangian) array -->
<StringVectorProperty
name="RegionArrayInfo"
name="PartArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Region"/>
<ArraySelectionInformationHelper attribute_name="Part"/>
</StringVectorProperty>
<StringVectorProperty
name="RegionStatus"
name="PartStatus"
label="Mesh Parts"
command="SetRegionArrayStatus"
command="SetPartArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="RegionArrayInfo"
information_property="PartArrayInfo"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="RegionArrayInfo" function="ArrayList"/>
<Property name="PartArrayInfo" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
......@@ -132,6 +132,9 @@
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Extrapolate internalField to wall and empty patches
</Documentation>
</IntVectorProperty>
<!-- Include Sets check-box -->
......@@ -141,6 +144,9 @@
number_of_elements="1"
default_values="0"
animateable="0">
<Documentation>
Searches the polyMesh/sets/ directory
</Documentation>
<BooleanDomain name="bool"/>
</IntVectorProperty>
......@@ -151,6 +157,10 @@
number_of_elements="1"
default_values="0"
animateable="0">
<Documentation>
ZoneMesh information is used to find {cell,face,point}Zones.
The polyMesh/ directory is only checked on startup.
</Documentation>
<BooleanDomain name="bool"/>
</IntVectorProperty>
......@@ -162,6 +172,9 @@
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Show patch names in render window.
</Documentation>
</IntVectorProperty>
<!-- Cache Mesh check-box -->
......@@ -172,6 +185,9 @@
default_values="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Cache the fvMesh in memory.
</Documentation>
</IntVectorProperty>
<!-- Update GUI check box -->
......@@ -182,6 +198,9 @@
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
A simple way cause a reader GUI modification.
</Documentation>
</IntVectorProperty>
</SourceProxy>
......
......@@ -71,7 +71,7 @@ vtkPV3FoamReader::vtkPV3FoamReader()
UpdateGUI = 0;
RegionSelection = vtkDataArraySelection::New();
PartSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New();
PointFieldSelection = vtkDataArraySelection::New();
LagrangianFieldSelection = vtkDataArraySelection::New();
......@@ -85,7 +85,7 @@ vtkPV3FoamReader::vtkPV3FoamReader()
);
SelectionObserver->SetClientData(this);
RegionSelection->AddObserver
PartSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
......@@ -128,14 +128,14 @@ vtkPV3FoamReader::~vtkPV3FoamReader()
}
RegionSelection->RemoveObserver(this->SelectionObserver);
PartSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver);
LagrangianFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
RegionSelection->Delete();
PartSelection->Delete();
VolFieldSelection->Delete();
PointFieldSelection->Delete();
LagrangianFieldSelection->Delete();
......@@ -427,46 +427,46 @@ int vtkPV3FoamReader::GetTimeStep()
// ----------------------------------------------------------------------
// Region selection list control
// Parts selection list control
vtkDataArraySelection* vtkPV3FoamReader::GetRegionSelection()
vtkDataArraySelection* vtkPV3FoamReader::GetPartSelection()
{
vtkDebugMacro(<<"GetRegionSelection");
return RegionSelection;
vtkDebugMacro(<<"GetPartSelection");
return PartSelection;
}
int vtkPV3FoamReader::GetNumberOfRegionArrays()
int vtkPV3FoamReader::GetNumberOfPartArrays()
{
vtkDebugMacro(<<"GetNumberOfRegionArrays");
return RegionSelection->GetNumberOfArrays();
vtkDebugMacro(<<"GetNumberOfPartArrays");
return PartSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetRegionArrayName(int index)
const char* vtkPV3FoamReader::GetPartArrayName(int index)
{
vtkDebugMacro(<<"GetRegionArrayName");
return RegionSelection->GetArrayName(index);
vtkDebugMacro(<<"GetPartArrayName");
return PartSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetRegionArrayStatus(const char* name)
int vtkPV3FoamReader::GetPartArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetRegionArrayStatus");
return RegionSelection->ArrayIsEnabled(name);
vtkDebugMacro(<<"GetPartArrayStatus");
return PartSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetRegionArrayStatus(const char* name, int status)
void vtkPV3FoamReader::SetPartArrayStatus(const char* name, int status)
{
vtkDebugMacro(<<"SetRegionArrayStatus");
vtkDebugMacro(<<"SetPartArrayStatus");
if (status)
{
RegionSelection->EnableArray(name);
PartSelection->EnableArray(name);
}
else
{
RegionSelection->DisableArray(name);
PartSelection->DisableArray(name);
}
}
......
......@@ -88,12 +88,12 @@ public:
int GetTimeStep();
// Description:
// Region selection list control
vtkDataArraySelection* GetRegionSelection();
int GetNumberOfRegionArrays();
int GetRegionArrayStatus(const char* name);
void SetRegionArrayStatus(const char* name, int status);
const char* GetRegionArrayName(int index);
// Parts selection list control
vtkDataArraySelection* GetPartSelection();
int GetNumberOfPartArrays();
int GetPartArrayStatus(const char* name);
void SetPartArrayStatus(const char* name, int status);
const char* GetPartArrayName(int index);
// Description:
// volField selection list control
......@@ -191,7 +191,7 @@ private:
//- Dummy variable/switch for invoke a reader update
int UpdateGUI;
vtkDataArraySelection* RegionSelection;
vtkDataArraySelection* PartSelection;
vtkDataArraySelection* VolFieldSelection;
vtkDataArraySelection* PointFieldSelection;
vtkDataArraySelection* LagrangianFieldSelection;
......
......@@ -7,5 +7,6 @@ vtkPV3FoamMeshSet.C
vtkPV3FoamMeshVolume.C
vtkPV3FoamMeshZone.C
vtkPV3FoamUpdateInfo.C
vtkPV3FoamUtilities.C
LIB = $(FOAM_LIBBIN)/libvtkPV3Foam
......@@ -31,20 +31,13 @@ License
#include "fvMesh.H"
#include "Time.H"
#include "patchZones.H"
#include "IFstream.H"
// VTK includes
#include "vtkCharArray.h"
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkFieldData.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -55,120 +48,40 @@ defineTypeNameAndDebug(Foam::vtkPV3Foam, 0);
#include "vtkPV3FoamAddToSelection.H"
#include "vtkPV3FoamUpdateInfoFields.H"
void Foam::vtkPV3Foam::AddToBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
vtkDataSet* dataset,
const string& blockName
)
void Foam::vtkPV3Foam::resetCounters()
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (blockDO && !block)
{
FatalErrorIn("Foam::vtkPV3Foam::AddToBlock")
<< "Block already has a vtkDataSet assigned to it" << nl << endl;
return;
}
if (!block)
{
block = vtkMultiBlockDataSet::New();
output->SetBlock(blockNo, block);
block->Delete();
}
if (block)
{
if (debug)
{
Info<< "block[" << blockNo << "] has "
<< block->GetNumberOfBlocks()
<< " datasets prior to adding set " << datasetNo
<< " with name: " << blockName << endl;
}
// when assigning dataset 0, also name the parent block
if (!datasetNo && selector.name())
{
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
selector.name()
);
}
}
block->SetBlock(datasetNo, dataset);
if (blockName.size())
{
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(), blockName.c_str()
);
}
// Reset mesh part ids and sizes
partInfoVolume_.reset();
partInfoPatches_.reset();
partInfoLagrangian_.reset();
partInfoCellZones_.reset();
partInfoFaceZones_.reset();
partInfoPointZones_.reset();
partInfoCellSets_.reset();
partInfoFaceSets_.reset();
partInfoPointSets_.reset();
}
vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
void Foam::vtkPV3Foam::reduceMemory()
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
forAll(regionPolyDecomp_, i)
{
return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
regionPolyDecomp_[i].clear();
}
return 0;
}
Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const selectionInfo& selector
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
forAll(zonePolyDecomp_, i)
{
return block->GetNumberOfBlocks();
zonePolyDecomp_[i].clear();
}
return 0;
forAll(csetPolyDecomp_, i)
{
csetPolyDecomp_[i].clear();
}
}
void Foam::vtkPV3Foam::resetCounters()
{
// Reset region ids and sizes
regionInfoVolume_.reset();
regionInfoPatches_.reset();
regionInfoLagrangian_.reset();
regionInfoCellZones_.reset();
regionInfoFaceZones_.reset();
regionInfoPointZones_.reset();
regionInfoCellSets_.reset();
regionInfoFaceSets_.reset();
regionInfoPointSets_.reset();
}
int Foam::vtkPV3Foam::setTime(const double& requestedTime)
......@@ -231,242 +144,51 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime)
}
void Foam::vtkPV3Foam::updateRegionStatus()
void Foam::vtkPV3Foam::updateMeshPartsStatus()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV3Foam::updateRegionStatus" << endl;
Info<< "<beg> Foam::vtkPV3Foam::updateMeshPartsStatus" << endl;
}
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
const label nSelect = regionSelection->GetNumberOfArrays();
if (regionStatus_.size() != nSelect)
vtkDataArraySelection* selection = reader_->GetPartSelection();
label nElem = selection->GetNumberOfArrays();
if (partStatus_.size() != nElem)
{
regionStatus_.setSize(nSelect);
regionStatus_ = false;
partStatus_.setSize(nElem);
partStatus_ = false;
meshChanged_ = true;
}
// this needs fixing if we wish to re-use the datasets
regionDataset_.setSize(nSelect);
regionDataset_ = -1;
partDataset_.setSize(nElem);
partDataset_ = -1;
// Read the selected cell regions, zones, patches and add to region list
forAll(regionStatus_, regionId)
// Read the selected mesh parts (zones, patches ...) and add to list
forAll(partStatus_, partId)
{
int setting = regionSelection->GetArraySetting(regionId);
const int setting = selection->GetArraySetting(partId);
if (regionStatus_[regionId] != setting)
if (partStatus_[partId] != setting)
{
regionStatus_[regionId] = setting;
partStatus_[partId] = setting;
meshChanged_ = true;
}
if (debug)
{
Info<< " region[" << regionId << "] = "
<< regionStatus_[regionId]
<< " : " << regionSelection->GetArrayName(regionId) << endl;
}
}
if (debug)
{
Info<< "<end> Foam::vtkPV3Foam::updateRegionStatus" << endl;
}
}
Foam::wordHashSet Foam::vtkPV3Foam::getSelected
(
vtkDataArraySelection* select
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI=0; elemI < nElem; ++elemI)
{
if (select->GetArraySetting(elemI))
{
word name(getFirstWord(select->GetArrayName(elemI)));
selections.insert(name);
}
}
return selections;
}
Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const bool firstWord
)
{
stringList selections(select->GetNumberOfArrays());
label nElem = 0;
if (debug)
{
Info<< "available(";
forAll(selections, elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\n"
<< "selected(";
}
forAll(selections, elemI)
{
if (select->GetArraySetting(elemI))
{
if (firstWord)
{
selections[nElem] = getFirstWord
(
select->GetArrayName(elemI)
);
}
else
{
selections[nElem] = select->GetArrayName(elemI);
}
if (debug)
{
Info<< " " << selections[nElem];
}
++nElem;
}
}
if (debug)
{
Info<< " )" << endl;
}
selections.setSize(nElem);
return selections;
}
Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const selectionInfo& selector,
const bool firstWord
)
{
stringList selections(selector.size());
label nElem = 0;
if (debug)
{
Info<< "available(";
for
(
int elemI = selector.start();
elemI < selector.end();
++elemI
)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\n"
<< "selected(";
}
for
(
int elemI = selector.start();
elemI < selector.end();
++elemI
)
{
if (select->GetArraySetting(elemI))
{
if (firstWord)
{
selections[nElem] = getFirstWord
(
select->GetArrayName(elemI)
);
}
else
{
selections[nElem] = select->GetArrayName(elemI);
}