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
This commit is contained in:
Mark Olesen
2008-08-03 14:17:25 +02:00
parent 775ef2c843
commit 062bb36693
18 changed files with 1330 additions and 1406 deletions

View File

@ -12,7 +12,7 @@
animateable="0"> animateable="0">
<FileListDomain name="files"/> <FileListDomain name="files"/>
<Documentation> <Documentation>
Specifies the filename for the OpenFOAM Reader Specifies the filename for the OpenFOAM Reader
</Documentation> </Documentation>
</StringVectorProperty> </StringVectorProperty>
@ -32,25 +32,25 @@
<TimeRangeInformationHelper/> <TimeRangeInformationHelper/>
</DoubleVectorProperty> </DoubleVectorProperty>
<!-- Available Region array --> <!-- Available Parts (volume, patches, lagrangian) array -->
<StringVectorProperty <StringVectorProperty
name="RegionArrayInfo" name="PartArrayInfo"
information_only="1"> information_only="1">
<ArraySelectionInformationHelper attribute_name="Region"/> <ArraySelectionInformationHelper attribute_name="Part"/>
</StringVectorProperty> </StringVectorProperty>
<StringVectorProperty <StringVectorProperty
name="RegionStatus" name="PartStatus"
label="Mesh Parts" label="Mesh Parts"
command="SetRegionArrayStatus" command="SetPartArrayStatus"
number_of_elements="0" number_of_elements="0"
repeat_command="1" repeat_command="1"
number_of_elements_per_command="2" number_of_elements_per_command="2"
element_types="2 0" element_types="2 0"
information_property="RegionArrayInfo" information_property="PartArrayInfo"
animateable="0"> animateable="0">
<ArraySelectionDomain name="array_list"> <ArraySelectionDomain name="array_list">
<RequiredProperties> <RequiredProperties>
<Property name="RegionArrayInfo" function="ArrayList"/> <Property name="PartArrayInfo" function="ArrayList"/>
</RequiredProperties> </RequiredProperties>
</ArraySelectionDomain> </ArraySelectionDomain>
</StringVectorProperty> </StringVectorProperty>
@ -132,6 +132,9 @@
default_values="0" default_values="0"
animateable="0"> animateable="0">
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
<Documentation>
Extrapolate internalField to wall and empty patches
</Documentation>
</IntVectorProperty> </IntVectorProperty>
<!-- Include Sets check-box --> <!-- Include Sets check-box -->
@ -141,6 +144,9 @@
number_of_elements="1" number_of_elements="1"
default_values="0" default_values="0"
animateable="0"> animateable="0">
<Documentation>
Searches the polyMesh/sets/ directory
</Documentation>
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
</IntVectorProperty> </IntVectorProperty>
@ -151,6 +157,10 @@
number_of_elements="1" number_of_elements="1"
default_values="0" default_values="0"
animateable="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"/> <BooleanDomain name="bool"/>
</IntVectorProperty> </IntVectorProperty>
@ -162,6 +172,9 @@
default_values="0" default_values="0"
animateable="0"> animateable="0">
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
<Documentation>
Show patch names in render window.
</Documentation>
</IntVectorProperty> </IntVectorProperty>
<!-- Cache Mesh check-box --> <!-- Cache Mesh check-box -->
@ -172,6 +185,9 @@
default_values="1" default_values="1"
animateable="0"> animateable="0">
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
<Documentation>
Cache the fvMesh in memory.
</Documentation>
</IntVectorProperty> </IntVectorProperty>
<!-- Update GUI check box --> <!-- Update GUI check box -->
@ -182,6 +198,9 @@
default_values="0" default_values="0"
animateable="0"> animateable="0">
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
<Documentation>
A simple way cause a reader GUI modification.
</Documentation>
</IntVectorProperty> </IntVectorProperty>
</SourceProxy> </SourceProxy>

View File

@ -71,7 +71,7 @@ vtkPV3FoamReader::vtkPV3FoamReader()
UpdateGUI = 0; UpdateGUI = 0;
RegionSelection = vtkDataArraySelection::New(); PartSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New(); VolFieldSelection = vtkDataArraySelection::New();
PointFieldSelection = vtkDataArraySelection::New(); PointFieldSelection = vtkDataArraySelection::New();
LagrangianFieldSelection = vtkDataArraySelection::New(); LagrangianFieldSelection = vtkDataArraySelection::New();
@ -85,7 +85,7 @@ vtkPV3FoamReader::vtkPV3FoamReader()
); );
SelectionObserver->SetClientData(this); SelectionObserver->SetClientData(this);
RegionSelection->AddObserver PartSelection->AddObserver
( (
vtkCommand::ModifiedEvent, vtkCommand::ModifiedEvent,
this->SelectionObserver this->SelectionObserver
@ -128,14 +128,14 @@ vtkPV3FoamReader::~vtkPV3FoamReader()
} }
RegionSelection->RemoveObserver(this->SelectionObserver); PartSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver); VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver); PointFieldSelection->RemoveObserver(this->SelectionObserver);
LagrangianFieldSelection->RemoveObserver(this->SelectionObserver); LagrangianFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete(); SelectionObserver->Delete();
RegionSelection->Delete(); PartSelection->Delete();
VolFieldSelection->Delete(); VolFieldSelection->Delete();
PointFieldSelection->Delete(); PointFieldSelection->Delete();
LagrangianFieldSelection->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"); vtkDebugMacro(<<"GetPartSelection");
return RegionSelection; return PartSelection;
} }
int vtkPV3FoamReader::GetNumberOfRegionArrays() int vtkPV3FoamReader::GetNumberOfPartArrays()
{ {
vtkDebugMacro(<<"GetNumberOfRegionArrays"); vtkDebugMacro(<<"GetNumberOfPartArrays");
return RegionSelection->GetNumberOfArrays(); return PartSelection->GetNumberOfArrays();
} }
const char* vtkPV3FoamReader::GetRegionArrayName(int index) const char* vtkPV3FoamReader::GetPartArrayName(int index)
{ {
vtkDebugMacro(<<"GetRegionArrayName"); vtkDebugMacro(<<"GetPartArrayName");
return RegionSelection->GetArrayName(index); return PartSelection->GetArrayName(index);
} }
int vtkPV3FoamReader::GetRegionArrayStatus(const char* name) int vtkPV3FoamReader::GetPartArrayStatus(const char* name)
{ {
vtkDebugMacro(<<"GetRegionArrayStatus"); vtkDebugMacro(<<"GetPartArrayStatus");
return RegionSelection->ArrayIsEnabled(name); 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) if (status)
{ {
RegionSelection->EnableArray(name); PartSelection->EnableArray(name);
} }
else else
{ {
RegionSelection->DisableArray(name); PartSelection->DisableArray(name);
} }
} }

View File

@ -88,12 +88,12 @@ public:
int GetTimeStep(); int GetTimeStep();
// Description: // Description:
// Region selection list control // Parts selection list control
vtkDataArraySelection* GetRegionSelection(); vtkDataArraySelection* GetPartSelection();
int GetNumberOfRegionArrays(); int GetNumberOfPartArrays();
int GetRegionArrayStatus(const char* name); int GetPartArrayStatus(const char* name);
void SetRegionArrayStatus(const char* name, int status); void SetPartArrayStatus(const char* name, int status);
const char* GetRegionArrayName(int index); const char* GetPartArrayName(int index);
// Description: // Description:
// volField selection list control // volField selection list control
@ -191,7 +191,7 @@ private:
//- Dummy variable/switch for invoke a reader update //- Dummy variable/switch for invoke a reader update
int UpdateGUI; int UpdateGUI;
vtkDataArraySelection* RegionSelection; vtkDataArraySelection* PartSelection;
vtkDataArraySelection* VolFieldSelection; vtkDataArraySelection* VolFieldSelection;
vtkDataArraySelection* PointFieldSelection; vtkDataArraySelection* PointFieldSelection;
vtkDataArraySelection* LagrangianFieldSelection; vtkDataArraySelection* LagrangianFieldSelection;

View File

@ -7,5 +7,6 @@ vtkPV3FoamMeshSet.C
vtkPV3FoamMeshVolume.C vtkPV3FoamMeshVolume.C
vtkPV3FoamMeshZone.C vtkPV3FoamMeshZone.C
vtkPV3FoamUpdateInfo.C vtkPV3FoamUpdateInfo.C
vtkPV3FoamUtilities.C
LIB = $(FOAM_LIBBIN)/libvtkPV3Foam LIB = $(FOAM_LIBBIN)/libvtkPV3Foam

View File

@ -31,20 +31,13 @@ License
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H" #include "Time.H"
#include "patchZones.H" #include "patchZones.H"
#include "IFstream.H"
// VTK includes // VTK includes
#include "vtkCharArray.h"
#include "vtkDataArraySelection.h" #include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkFieldData.h"
#include "vtkMultiBlockDataSet.h" #include "vtkMultiBlockDataSet.h"
#include "vtkRenderer.h" #include "vtkRenderer.h"
#include "vtkTextActor.h" #include "vtkTextActor.h"
#include "vtkTextProperty.h" #include "vtkTextProperty.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -55,122 +48,42 @@ defineTypeNameAndDebug(Foam::vtkPV3Foam, 0);
#include "vtkPV3FoamAddToSelection.H" #include "vtkPV3FoamAddToSelection.H"
#include "vtkPV3FoamUpdateInfoFields.H" #include "vtkPV3FoamUpdateInfoFields.H"
void Foam::vtkPV3Foam::AddToBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
vtkDataSet* dataset,
const string& blockName
)
{
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()
);
}
}
vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
}
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)
{
return block->GetNumberOfBlocks();
}
return 0;
}
void Foam::vtkPV3Foam::resetCounters() void Foam::vtkPV3Foam::resetCounters()
{ {
// Reset region ids and sizes // Reset mesh part ids and sizes
regionInfoVolume_.reset(); partInfoVolume_.reset();
regionInfoPatches_.reset(); partInfoPatches_.reset();
regionInfoLagrangian_.reset(); partInfoLagrangian_.reset();
regionInfoCellZones_.reset(); partInfoCellZones_.reset();
regionInfoFaceZones_.reset(); partInfoFaceZones_.reset();
regionInfoPointZones_.reset(); partInfoPointZones_.reset();
regionInfoCellSets_.reset(); partInfoCellSets_.reset();
regionInfoFaceSets_.reset(); partInfoFaceSets_.reset();
regionInfoPointSets_.reset(); partInfoPointSets_.reset();
} }
void Foam::vtkPV3Foam::reduceMemory()
{
forAll(regionPolyDecomp_, i)
{
regionPolyDecomp_[i].clear();
}
forAll(zonePolyDecomp_, i)
{
zonePolyDecomp_[i].clear();
}
forAll(csetPolyDecomp_, i)
{
csetPolyDecomp_[i].clear();
}
}
int Foam::vtkPV3Foam::setTime(const double& requestedTime) int Foam::vtkPV3Foam::setTime(const double& requestedTime)
{ {
if (debug) if (debug)
@ -231,242 +144,51 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime)
} }
void Foam::vtkPV3Foam::updateRegionStatus() void Foam::vtkPV3Foam::updateMeshPartsStatus()
{ {
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::updateRegionStatus" << endl; Info<< "<beg> Foam::vtkPV3Foam::updateMeshPartsStatus" << endl;
} }
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* selection = reader_->GetPartSelection();
const label nSelect = regionSelection->GetNumberOfArrays(); label nElem = selection->GetNumberOfArrays();
if (regionStatus_.size() != nSelect)
if (partStatus_.size() != nElem)
{ {
regionStatus_.setSize(nSelect); partStatus_.setSize(nElem);
regionStatus_ = false; partStatus_ = false;
meshChanged_ = true; meshChanged_ = true;
} }
// this needs fixing if we wish to re-use the datasets // this needs fixing if we wish to re-use the datasets
regionDataset_.setSize(nSelect); partDataset_.setSize(nElem);
regionDataset_ = -1; partDataset_ = -1;
// Read the selected cell regions, zones, patches and add to region list // Read the selected mesh parts (zones, patches ...) and add to list
forAll(regionStatus_, regionId) 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; meshChanged_ = true;
} }
if (debug) if (debug)
{ {
Info<< " region[" << regionId << "] = " Info<< " part[" << partId << "] = "
<< regionStatus_[regionId] << partStatus_[partId]
<< " : " << regionSelection->GetArrayName(regionId) << endl; << " : " << selection->GetArrayName(partId) << endl;
} }
} }
if (debug) if (debug)
{ {
Info<< "<end> Foam::vtkPV3Foam::updateRegionStatus" << endl; Info<< "<end> Foam::vtkPV3Foam::updateMeshPartsStatus" << 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);
}
if (debug)
{
Info<< " " << selections[nElem];
}
++nElem;
}
}
if (debug)
{
Info<< " )" << endl;
}
selections.setSize(nElem);
return selections;
}
void Foam::vtkPV3Foam::setSelectedArrayEntries
(
vtkDataArraySelection* select,
const stringList& selections
)
{
if (debug > 1)
{
Info<< "<beg> Foam::vtkPV3Foam::setSelectedArrayEntries" << endl;
}
const label nEntries = select->GetNumberOfArrays();
// Reset all current entries to 'not selected'
select->DisableAllArrays();
// Loop through entries, setting values from selectedEntries
forAll(selections, elemI)
{
if (debug > 1)
{
Info<< "selections[" << elemI << "] = " << selections[elemI]
<< endl;
}
for (label i=0; i<nEntries; i++)
{
string arrayName = select->GetArrayName(i);
if (arrayName == selections[elemI])
{
if (debug > 1)
{
Info<< "enabling array: " << arrayName << " Index = "
<< i
<< endl;
}
select->EnableArray(arrayName.c_str());
break;
}
}
}
if (debug > 1)
{
Info<< "<end> Foam::vtkPV3Foam::setSelectedArrayEntries" << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkPV3Foam::vtkPV3Foam Foam::vtkPV3Foam::vtkPV3Foam
@ -482,15 +204,15 @@ Foam::vtkPV3Foam::vtkPV3Foam
timeIndex_(-1), timeIndex_(-1),
meshChanged_(true), meshChanged_(true),
fieldsChanged_(true), fieldsChanged_(true),
regionInfoVolume_("unzoned"), partInfoVolume_("unzoned"),
regionInfoPatches_("patches"), partInfoPatches_("patches"),
regionInfoLagrangian_("lagrangian"), partInfoLagrangian_("lagrangian"),
regionInfoCellZones_("cellZone"), partInfoCellZones_("cellZone"),
regionInfoFaceZones_("faceZone"), partInfoFaceZones_("faceZone"),
regionInfoPointZones_("pointZone"), partInfoPointZones_("pointZone"),
regionInfoCellSets_("cellSet"), partInfoCellSets_("cellSet"),
regionInfoFaceSets_("faceSet"), partInfoFaceSets_("faceSet"),
regionInfoPointSets_("pointSet") partInfoPointSets_("pointSet")
{ {
if (debug) if (debug)
{ {
@ -569,29 +291,25 @@ void Foam::vtkPV3Foam::updateInfo()
resetCounters(); resetCounters();
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
stringList selectedEntries;
// enable 'internalMesh' on the first call // enable 'internalMesh' on the first call
if (regionSelection->GetNumberOfArrays() == 0 && !meshPtr_) // or preserve the enabled selections
stringList enabledEntries;
if (!partSelection->GetNumberOfArrays() && !meshPtr_)
{ {
selectedEntries.setSize(1); enabledEntries.setSize(1);
selectedEntries[0] = "internalMesh"; enabledEntries[0] = "internalMesh";
} }
else else
{ {
// preserve the enabled selections enabledEntries = getSelectedArrayEntries(partSelection);
selectedEntries = getSelectedArrayEntries
(
regionSelection,
false
);
} }
// Clear current region list/array // Clear current mesh parts list
regionSelection->RemoveAllArrays(); partSelection->RemoveAllArrays();
// Update region array - add Lagrangian at the bottom // Update mesh parts list - add Lagrangian at the bottom
updateInfoInternalMesh(); updateInfoInternalMesh();
updateInfoPatches(); updateInfoPatches();
updateInfoSets(); updateInfoSets();
@ -599,11 +317,7 @@ void Foam::vtkPV3Foam::updateInfo()
updateInfoLagrangian(); updateInfoLagrangian();
// restore the enabled selections // restore the enabled selections
setSelectedArrayEntries setSelectedArrayEntries(partSelection, enabledEntries);
(
regionSelection,
selectedEntries
);
if (meshChanged_) if (meshChanged_)
{ {
@ -696,14 +410,14 @@ void Foam::vtkPV3Foam::Update
} }
reader_->UpdateProgress(0.1); reader_->UpdateProgress(0.1);
// Set up region selection(s) // Set up mesh parts selection(s)
updateRegionStatus(); updateMeshPartsStatus();
// Update the Foam mesh // Update the Foam mesh
updateFoamMesh(); updateFoamMesh();
reader_->UpdateProgress(0.2); reader_->UpdateProgress(0.2);
// Convert meshes // Convert meshes - start port0 at block=0
int blockNo = 0; int blockNo = 0;
convertMeshVolume(output, blockNo); convertMeshVolume(output, blockNo);
@ -724,6 +438,7 @@ void Foam::vtkPV3Foam::Update
convertMeshPointSets(output, blockNo); convertMeshPointSets(output, blockNo);
} }
// restart port1 at block=0
blockNo = 0; blockNo = 0;
convertMeshLagrangian(lagrangianOutput, blockNo); convertMeshLagrangian(lagrangianOutput, blockNo);
@ -733,6 +448,10 @@ void Foam::vtkPV3Foam::Update
convertVolFields(output); convertVolFields(output);
convertPointFields(output); convertPointFields(output);
convertLagrangianFields(lagrangianOutput); convertLagrangianFields(lagrangianOutput);
reader_->UpdateProgress(0.95);
// reclaim some memory
reduceMemory();
reader_->UpdateProgress(1.0); reader_->UpdateProgress(1.0);
meshChanged_ = fieldsChanged_ = false; meshChanged_ = fieldsChanged_ = false;
@ -789,11 +508,10 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
removePatchNames(renderer); removePatchNames(renderer);
// get the display patches, strip off any suffix // get the display patches, strip off any suffix
const stringList selectedPatches = getSelectedArrayEntries wordHashSet selectedPatches = getSelected
( (
reader_->GetRegionSelection(), reader_->GetPartSelection(),
regionInfoPatches_, partInfoPatches_
true
); );
if (!selectedPatches.size()) if (!selectedPatches.size())
@ -828,68 +546,60 @@ void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
const polyPatch& pp = pbMesh[patchI]; const polyPatch& pp = pbMesh[patchI];
// Only include the patch if it is selected // Only include the patch if it is selected
bool isSelected = false; if (!selectedPatches.found(pp.name()))
forAll(selectedPatches, elemI)
{ {
if (pp.name() == selectedPatches[elemI]) continue;
}
const labelListList& edgeFaces = pp.edgeFaces();
const vectorField& n = pp.faceNormals();
boolList featEdge(pp.nEdges(), false);
forAll(edgeFaces, edgeI)
{
const labelList& eFaces = edgeFaces[edgeI];
if (eFaces.size() != 2)
{ {
isSelected = true; featEdge[edgeI] = true;
break; }
else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
{
featEdge[edgeI] = true;
} }
} }
if (isSelected) // Do topological analysis of patch, find disconnected regions
patchZones pZones(pp, featEdge);
nZones[patchI] = pZones.nZones();
labelList zoneNFaces(pZones.nZones(), 0);
// Save start of information for current patch
label patchStart = zoneCentre.size();
// Create storage for additional zone centres
forAll(zoneNFaces, zoneI)
{ {
const labelListList& edgeFaces = pp.edgeFaces(); zoneCentre.append(vector::zero);
const vectorField& n = pp.faceNormals(); }
boolList featEdge(pp.nEdges(), false); // Do averaging per individual zone
forAll(pp, faceI)
{
label zoneI = pZones[faceI];
zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points());
zoneNFaces[zoneI]++;
}
forAll(edgeFaces, edgeI) for (label i=0; i<nZones[patchI]; i++)
{ {
const labelList& eFaces = edgeFaces[edgeI]; zoneCentre[patchStart + i] /= zoneNFaces[i];
if (eFaces.size() != 2)
{
featEdge[edgeI] = true;
}
else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
{
featEdge[edgeI] = true;
}
}
// Do topological analysis of patch. Determine disconnected regions
patchZones pZones(pp, featEdge);
nZones[patchI] = pZones.nZones();
labelList zoneNFaces(pZones.nZones(), 0);
// Save start of information for current patch
label patchStart = zoneCentre.size();
// Create storage for additional zone centres
forAll(zoneNFaces, zoneI)
{
zoneCentre.append(vector::zero);
}
// Do averaging per individual zone
forAll(pp, faceI)
{
label zoneI = pZones[faceI];
zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points());
zoneNFaces[zoneI]++;
}
for (label i=0; i<nZones[patchI]; i++)
{
zoneCentre[patchStart + i] /= zoneNFaces[i];
}
} }
} }
zoneCentre.shrink(); zoneCentre.shrink();
if (debug) if (debug)
@ -990,46 +700,4 @@ void Foam::vtkPV3Foam::PrintSelf(ostream& os, vtkIndent indent) const
<< (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl; << (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
} }
// parse these bits of info from /proc/meminfo (Linux)
//
// MemTotal: 2062660 kB
// MemFree: 1124400 kB
//
// used = MemTotal - MemFree is what the free(1) uses.
//
void Foam::vtkPV3Foam::printMemory()
{
const char* meminfo = "/proc/meminfo";
if (exists(meminfo))
{
IFstream is(meminfo);
label memTotal = 0;
label memFree = 0;
string line;
while (is.getLine(line).good())
{
char tag[32];
int value;
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
{
if (!strcmp(tag, "MemTotal:"))
{
memTotal = value;
}
else if (!strcmp(tag, "MemFree:"))
{
memFree = value;
}
}
}
Info << "memUsed: " << (memTotal - memFree) << " kB\n";
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -46,6 +46,7 @@ SourceFiles
vtkPV3FoamPoints.H vtkPV3FoamPoints.H
vtkPV3FoamUpdateInfo.C vtkPV3FoamUpdateInfo.C
vtkPV3FoamUpdateInfoFields.H vtkPV3FoamUpdateInfoFields.H
vtkPV3FoamUtilities.C
vtkPV3FoamVolFields.H vtkPV3FoamVolFields.H
vtkPV3FoamAddToSelection.H vtkPV3FoamAddToSelection.H
@ -103,58 +104,10 @@ class List;
class vtkPV3Foam class vtkPV3Foam
{ {
// Private data
//- Access to the controlling vtkPV3FoamReader
vtkPV3FoamReader* reader_;
//- Foam time control
autoPtr<Time> dbPtr_;
//- Foam mesh
fvMesh* meshPtr_;
//- Number of meshes
// TODO - for info only - only set up to process ONE mesh
int nMesh_;
//- The time index
int timeIndex_;
//- Track changes in mesh geometry
bool meshChanged_;
//- Track changes in fields
bool fieldsChanged_;
//- Cell-centre labels used as additional points for decomposed cells
labelList addPointCellLabels_;
//- Label of original cell for decomposed cells (internal mesh)
labelList superCells_;
//- Label of original cell for decomposed cells (cellZone meshes)
List<labelList> zoneSuperCells_;
//- Label of original cell for decomposed cells (cellSet meshes)
List<labelList> csetSuperCells_;
//- List of patch names
List<vtkTextActor*> patchTextActorsPtrs_;
//- Selected geometrical pieces
// [0] = internal mesh, patches, zones, sets, lagrangian
boolList regionStatus_;
//- Selected regions indices in each respective block
labelList regionDataset_;
// Private classes // Private classes
//- bookkeeping for the GUI checklists and the multi-block organization //- Bookkeeping for GUI checklists and the multi-block organization
class selectionInfo class partInfo
{ {
const char *name_; const char *name_;
int block_; int block_;
@ -163,7 +116,7 @@ class vtkPV3Foam
public: public:
selectionInfo(const char *name, const int blockNo=0) partInfo(const char *name, const int blockNo=0)
: :
name_(name), name_(name),
block_(blockNo), block_(blockNo),
@ -224,19 +177,121 @@ class vtkPV3Foam
} }
}; };
// Private data //- bookkeeping for polyhedral cell decomposition
// hide in extra pointMap (cellSet/cellZone) for now
class polyDecomp
{
labelList superCells_;
labelList addPointCellLabels_;
labelList pointMap_;
//- First instance and size of various regions public:
selectionInfo regionInfoVolume_;
selectionInfo regionInfoPatches_;
selectionInfo regionInfoLagrangian_;
selectionInfo regionInfoCellZones_;
selectionInfo regionInfoFaceZones_;
selectionInfo regionInfoPointZones_;
selectionInfo regionInfoCellSets_;
selectionInfo regionInfoFaceSets_;
selectionInfo regionInfoPointSets_;
polyDecomp()
{}
//- Label of original cell for decomposed cells
labelList& superCells()
{
return superCells_;
}
//- Label of original cell for decomposed cells
const labelList& superCells() const
{
return superCells_;
}
//- Cell-centre labels for additional points of decomposed cells
labelList& addPointCellLabels()
{
return addPointCellLabels_;
}
//- Cell-centre labels for additional points of decomposed cells
const labelList& addPointCellLabels() const
{
return addPointCellLabels_;
}
//- Point labels for subsetted meshes
labelList& pointMap()
{
return pointMap_;
}
//- Point labels for subsetted meshes
const labelList& pointMap() const
{
return pointMap_;
}
//- Clear
void clear()
{
superCells_.clear();
addPointCellLabels_.clear();
pointMap_.clear();
}
};
// Private Data
//- Access to the controlling vtkPV3FoamReader
vtkPV3FoamReader* reader_;
//- Foam time control
autoPtr<Time> dbPtr_;
//- Foam mesh
fvMesh* meshPtr_;
//- Number of meshes
// TODO - for info only - only set up to process ONE mesh
int nMesh_;
//- The time index
int timeIndex_;
//- Track changes in mesh geometry
bool meshChanged_;
//- Track changes in fields
bool fieldsChanged_;
//- Selected geometrical parts (internalMesh, patches, ...)
boolList partStatus_;
//- Datasets corresponding to selected geometrical pieces
// a negative number indicates that no vtkmesh exists for this piece
labelList partDataset_;
//- First instance and size of various mesh parts
// used to index into partStatus_ and partDataset_
partInfo partInfoVolume_;
partInfo partInfoPatches_;
partInfo partInfoLagrangian_;
partInfo partInfoCellZones_;
partInfo partInfoFaceZones_;
partInfo partInfoPointZones_;
partInfo partInfoCellSets_;
partInfo partInfoFaceSets_;
partInfo partInfoPointSets_;
//- Decomposed cells information (mesh regions)
// TODO: regions
List<polyDecomp> regionPolyDecomp_;
//- Decomposed cells information (cellZone meshes)
List<polyDecomp> zonePolyDecomp_;
//- Decomposed cells information (cellSet meshes)
List<polyDecomp> csetPolyDecomp_;
//- List of patch names for rendering to window
List<vtkTextActor*> patchTextActorsPtrs_;
// Private Member Functions // Private Member Functions
@ -245,10 +300,10 @@ class vtkPV3Foam
static void AddToBlock static void AddToBlock
( (
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
vtkDataSet* dataset, vtkDataSet* dataset,
const string& blockName=string::null const partInfo&,
const label datasetNo,
const string& datasetName
); );
// Convenience method use to convert the readers from VTK 5 // Convenience method use to convert the readers from VTK 5
@ -256,7 +311,7 @@ class vtkPV3Foam
static vtkDataSet* GetDataSetFromBlock static vtkDataSet* GetDataSetFromBlock
( (
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo const label datasetNo
); );
@ -265,7 +320,7 @@ class vtkPV3Foam
static label GetNumberOfDataSets static label GetNumberOfDataSets
( (
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& const partInfo&
); );
//- Reset data counters //- Reset data counters
@ -273,8 +328,8 @@ class vtkPV3Foam
// Update information helper functions // Update information helper functions
//- Update the regions selected in the GUI //- Update the mesh parts selected in the GUI
void updateRegionStatus(); void updateMeshPartsStatus();
//- Internal mesh info //- Internal mesh info
void updateInfoInternalMesh(); void updateInfoInternalMesh();
@ -294,7 +349,7 @@ class vtkPV3Foam
//- Read zone names for zoneType from file //- Read zone names for zoneType from file
wordList readZoneNames(const word& zoneType); wordList readZoneNames(const word& zoneType);
//- Add to paraview array selection //- Add objects of Type to paraview array selection
template<class Type> template<class Type>
label addToSelection label addToSelection
( (
@ -316,6 +371,9 @@ class vtkPV3Foam
//- Foam mesh //- Foam mesh
void updateFoamMesh(); void updateFoamMesh();
//- Reduce memory footprint after conversion
void reduceMemory();
//- Volume fields //- Volume fields
void updateVolFields(vtkMultiBlockDataSet*); void updateVolFields(vtkMultiBlockDataSet*);
@ -359,11 +417,7 @@ class vtkPV3Foam
// Add mesh functions // Add mesh functions
//- Add internal mesh/cell set meshes //- Add internal mesh/cell set meshes
vtkUnstructuredGrid* volumeVTKMesh vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&);
(
const fvMesh&,
labelList& superCells
);
//- Add Lagrangian mesh //- Add Lagrangian mesh
vtkPolyData* lagrangianVTKMesh vtkPolyData* lagrangianVTKMesh
@ -439,15 +493,26 @@ class vtkPV3Foam
vtkMultiBlockDataSet* output vtkMultiBlockDataSet* output
); );
//- Volume field - all selected parts
template<class Type>
void convertVolFieldBlock
(
const GeometricField<Type, fvPatchField, volMesh>&,
const GeometricField<Type, pointPatchField, pointMesh>&,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
);
//- Volume field //- Volume field
template<class Type> template<class Type>
void convertVolField void convertVolField
( (
const GeometricField<Type, fvPatchField, volMesh>&, const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo, const label datasetNo,
labelList& superCells const polyDecomp&
); );
//- Patch field //- Patch field
@ -457,7 +522,7 @@ class vtkPV3Foam
const word& name, const word& name,
const Field<Type>&, const Field<Type>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo const label datasetNo
); );
@ -467,7 +532,7 @@ class vtkPV3Foam
( (
const GeometricField<Type, fvPatchField, volMesh>&, const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo, const label datasetNo,
const fvMesh&, const fvMesh&,
const labelList& faceLabels const labelList& faceLabels
@ -479,7 +544,7 @@ class vtkPV3Foam
( (
const GeometricField<Type, fvPatchField, volMesh>&, const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo, const label datasetNo,
const fvMesh&, const fvMesh&,
const faceSet& const faceSet&
@ -500,7 +565,7 @@ class vtkPV3Foam
( (
const IOField<Type>&, const IOField<Type>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo const label datasetNo
); );
@ -514,6 +579,16 @@ class vtkPV3Foam
vtkMultiBlockDataSet* output vtkMultiBlockDataSet* output
); );
//- Point field - all selected parts
template<class Type>
void convertPointFieldBlock
(
const GeometricField<Type, pointPatchField, pointMesh>&,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>&
);
//- Point fields //- Point fields
template<class Type> template<class Type>
void convertPointField void convertPointField
@ -521,8 +596,9 @@ class vtkPV3Foam
const GeometricField<Type, pointPatchField, pointMesh>&, const GeometricField<Type, pointPatchField, pointMesh>&,
const GeometricField<Type, fvPatchField, volMesh>&, const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo const label datasetNo,
const polyDecomp&
); );
//- Patch point field //- Patch point field
@ -532,7 +608,7 @@ class vtkPV3Foam
const word& name, const word& name,
const Field<Type>&, const Field<Type>&,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo&, const partInfo&,
const label datasetNo const label datasetNo
); );
@ -542,29 +618,31 @@ class vtkPV3Foam
//- Extract up to the first non-word characters //- Extract up to the first non-word characters
inline static word getFirstWord(const char*); inline static word getFirstWord(const char*);
//- Subset an IOobjectList based on a hashSet //- Only keep what is listed in hashSet
static void subsetObjectList static void pruneObjectList
( (
IOobjectList&, IOobjectList&,
const wordHashSet& const wordHashSet&
); );
//- Store the current selection(s) //- Retrieve the current selections
static wordHashSet getSelected(vtkDataArraySelection*); static wordHashSet getSelected(vtkDataArraySelection*);
//- Store the current selection(s) //- Retrieve a sub-list of the current selections
static stringList getSelectedArrayEntries static wordHashSet getSelected
( (
vtkDataArraySelection*, vtkDataArraySelection*,
const bool firstWord=false const partInfo&
); );
//- Store the current selection(s) for a sub-selection //- Retrieve the current selections
static stringList getSelectedArrayEntries(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
static stringList getSelectedArrayEntries static stringList getSelectedArrayEntries
( (
vtkDataArraySelection*, vtkDataArraySelection*,
const selectionInfo&, const partInfo&
const bool firstWord=false
); );
//- Set selection(s) //- Set selection(s)
@ -574,6 +652,9 @@ class vtkPV3Foam
const stringList& const stringList&
); );
//- Get the first word from the mesh parts selection
word getPartName(int);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
vtkPV3Foam(const vtkPV3Foam&); vtkPV3Foam(const vtkPV3Foam&);

View File

@ -44,46 +44,21 @@ Foam::label Foam::vtkPV3Foam::addToSelection
const string& suffix const string& suffix
) )
{ {
IOobjectList objects(objectLst.lookupClass(Type::typeName)); SortableList<word> names(objectLst.names(Type::typeName));
SortableList<word> objectNames(objects.size()); forAll(names, nameI)
label count = 0;
forAllConstIter(IOobjectList, objects, iter)
{ {
objectNames[count++] = iter()->name(); if (suffix.size())
}
if (count)
{
objectNames.sort();
forAll(objectNames, objI)
{ {
if (debug) select->AddArray((names[nameI] + suffix).c_str());
{ }
Info<<" addToSelection<" << Type::typeName << "> to GUI " else
<< ":" << objectNames[objI] << endl; {
} select->AddArray(names[nameI].c_str());
if (suffix.size())
{
select->AddArray
(
(objectNames[objI] + suffix).c_str()
);
}
else
{
select->AddArray
(
objectNames[objI].c_str()
);
}
} }
} }
return count; return names.size();
} }

View File

@ -42,19 +42,13 @@ void Foam::vtkPV3Foam::convertFaceField
( (
const GeometricField<Type, fvPatchField, volMesh>& tf, const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo, const label datasetNo,
const fvMesh& mesh, const fvMesh& mesh,
const labelList& faceLabels const labelList& faceLabels
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces(); const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner(); const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour(); const labelList& faceNeigh = mesh.faceNeighbour();
@ -102,7 +96,13 @@ void Foam::vtkPV3Foam::convertFaceField
cellData->InsertTuple(faceI, vec); cellData->InsertTuple(faceI, vec);
} }
vtkmesh->GetCellData()->AddArray(cellData);
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete(); cellData->Delete();
} }
@ -112,19 +112,13 @@ void Foam::vtkPV3Foam::convertFaceField
( (
const GeometricField<Type, fvPatchField, volMesh>& tf, const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo, const label datasetNo,
const fvMesh& mesh, const fvMesh& mesh,
const faceSet& fSet const faceSet& fSet
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces(); const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner(); const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour(); const labelList& faceNeigh = mesh.faceNeighbour();
@ -175,7 +169,13 @@ void Foam::vtkPV3Foam::convertFaceField
++faceI; ++faceI;
} }
vtkmesh->GetCellData()->AddArray(cellData);
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete(); cellData->Delete();
} }

View File

@ -44,7 +44,7 @@ Description
#include "vtkPV3FoamLagrangianFields.H" #include "vtkPV3FoamLagrangianFields.H"
void Foam::vtkPV3Foam::subsetObjectList void Foam::vtkPV3Foam::pruneObjectList
( (
IOobjectList& objects, IOobjectList& objects,
const wordHashSet& selected const wordHashSet& selected
@ -83,10 +83,9 @@ void Foam::vtkPV3Foam::convertVolFields
} }
const fvMesh& mesh = *meshPtr_; const fvMesh& mesh = *meshPtr_;
// Get objects (fields) for this time - only keep selected fields // Get objects (fields) for this time - only keep selected fields
IOobjectList objects(mesh, dbPtr_().timeName()); IOobjectList objects(mesh, dbPtr_().timeName());
subsetObjectList(objects, selectedFields); pruneObjectList(objects, selectedFields);
if (!objects.size()) if (!objects.size())
{ {
@ -170,11 +169,9 @@ void Foam::vtkPV3Foam::convertPointFields
} }
const fvMesh& mesh = *meshPtr_; const fvMesh& mesh = *meshPtr_;
// Get objects (fields) for this time - only keep selected fields // Get objects (fields) for this time - only keep selected fields
IOobjectList objects(mesh, dbPtr_().timeName()); IOobjectList objects(mesh, dbPtr_().timeName());
pruneObjectList(objects, selectedFields);
subsetObjectList(objects, selectedFields);
if (!objects.size()) if (!objects.size())
{ {
@ -231,6 +228,9 @@ void Foam::vtkPV3Foam::convertLagrangianFields
vtkMultiBlockDataSet* output vtkMultiBlockDataSet* output
) )
{ {
partInfo& selector = partInfoLagrangian_;
const fvMesh& mesh = *meshPtr_;
wordHashSet selectedFields = getSelected wordHashSet selectedFields = getSelected
( (
reader_->GetLagrangianFieldSelection() reader_->GetLagrangianFieldSelection()
@ -241,35 +241,22 @@ void Foam::vtkPV3Foam::convertLagrangianFields
return; return;
} }
const fvMesh& mesh = *meshPtr_;
selectionInfo& selector = regionInfoLagrangian_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertLagrangianFields" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertLagrangianFields" << endl;
printMemory(); printMemory();
} }
for for (int partId = selector.start(); partId < selector.end(); ++partId)
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
const label datasetNo = regionDataset_[regionId]; const word cloudName = getPartName(partId);
const label datasetNo = partDataset_[partId];
if (!regionStatus_[regionId] || datasetNo < 0) if (!partStatus_[partId] || datasetNo < 0)
{ {
continue; continue;
} }
word cloudName = getFirstWord
(
regionSelection->GetArrayName(regionId)
);
// Get the Lagrangian fields for this time and this cloud // Get the Lagrangian fields for this time and this cloud
// but only keep selected fields // but only keep selected fields
IOobjectList objects IOobjectList objects
@ -278,7 +265,7 @@ void Foam::vtkPV3Foam::convertLagrangianFields
dbPtr_().timeName(), dbPtr_().timeName(),
"lagrangian"/cloudName "lagrangian"/cloudName
); );
subsetObjectList(objects, selectedFields); pruneObjectList(objects, selectedFields);
if (!objects.size()) if (!objects.size())
{ {

View File

@ -40,21 +40,16 @@ void Foam::vtkPV3Foam::convertLagrangianFields
const label datasetNo const label datasetNo
) )
{ {
const selectionInfo& selector = regionInfoLagrangian_; const partInfo& selector = partInfoLagrangian_;
// field subset based on type forAllConstIter(IOobjectList, objects, iter)
IOobjectList fieldObjects
(
objects.lookupClass
(
IOField<Type>::typeName
)
);
forAllIter(IOobjectList, fieldObjects, iter)
{ {
IOField<Type> tf(*iter()); // restrict to this IOField<Type>
convertLagrangianField(tf, output, selector, datasetNo); if (iter()->headerClassName() == IOField<Type>::typeName)
{
IOField<Type> tf(*iter());
convertLagrangianField(tf, output, selector, datasetNo);
}
} }
} }
@ -64,17 +59,12 @@ void Foam::vtkPV3Foam::convertLagrangianField
( (
const IOField<Type>& tf, const IOField<Type>& tf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo const label datasetNo
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New(); vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples( tf.size() ); pointData->SetNumberOfTuples( tf.size() );
pointData->SetNumberOfComponents( nComp ); pointData->SetNumberOfComponents( nComp );
@ -102,11 +92,16 @@ void Foam::vtkPV3Foam::convertLagrangianField
pointData->InsertTuple(i, vec); pointData->InsertTuple(i, vec);
} }
vtkmesh->GetPointData()->AddArray(pointData);
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete(); pointData->Delete();
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -49,54 +49,47 @@ void Foam::vtkPV3Foam::convertMeshVolume
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoVolume_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
regionPolyDecomp_.setSize(selector.size());
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshVolume" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; // Convert the internalMesh
selectionInfo& selector = regionInfoVolume_; // TODO: multiple mesh regions
for (int partId = selector.start(); partId < selector.end(); ++partId)
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
// Create the internalMesh
// TODO: multiple regions
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
if (!regionStatus_[regionId]) const word partName = "internalMesh";
if (!partStatus_[partId])
{ {
continue; continue;
} }
if (debug)
{
Info<< "Creating VTK internalMesh" << endl;
}
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
( (
mesh, mesh,
superCells_ regionPolyDecomp_[datasetNo]
); );
if (vtkmesh) if (vtkmesh)
{ {
AddToBlock(output, selector, datasetNo, vtkmesh, "internalMesh"); AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete(); vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++; partDataset_[partId] = datasetNo++;
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -116,49 +109,38 @@ void Foam::vtkPV3Foam::convertMeshLagrangian
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoLagrangian_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; for (int partId = selector.start(); partId < selector.end(); ++partId)
selectionInfo& selector = regionInfoLagrangian_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
// Create Lagrangian meshes
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
if (!regionStatus_[regionId]) const word cloudName = getPartName(partId);
if (!partStatus_[partId])
{ {
continue; continue;
} }
word cloudName = getFirstWord
(
regionSelection->GetArrayName(regionId)
);
vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName); vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName);
if (vtkmesh) if (vtkmesh)
{ {
AddToBlock(output, selector, datasetNo, vtkmesh, cloudName); AddToBlock(output, vtkmesh, selector, datasetNo, cloudName);
vtkmesh->Delete(); vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++; partDataset_[partId] = datasetNo++;
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -178,61 +160,46 @@ void Foam::vtkPV3Foam::convertMeshPatches
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoPatches_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& patches = mesh.boundaryMesh();
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPatches" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshPatches" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; for (int partId = selector.start(); partId < selector.end(); ++partId)
selectionInfo& selector = regionInfoPatches_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
if (selector.size())
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const word patchName = getPartName(partId);
const label patchId = patches.findPatchID(patchName);
for if (!partStatus_[partId] || patchId < 0)
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
word patchName = getFirstWord continue;
( }
regionSelection->GetArrayName(regionId)
);
label patchId = patches.findPatchID(patchName); if (debug)
{
Info<< "Creating VTK mesh for patch[" << patchId <<"] "
<< patchName << endl;
}
if (!regionStatus_[regionId] || patchId < 0) vtkPolyData* vtkmesh = patchVTKMesh(patches[patchId]);
{
continue;
}
if (debug) if (vtkmesh)
{ {
Info<< "Creating VTK mesh for patch: " << patchName AddToBlock(output, vtkmesh, selector, datasetNo, patchName);
<< " patch index: " << patchId << endl; vtkmesh->Delete();
}
vtkPolyData* vtkmesh = patchVTKMesh(patches[patchId]); partDataset_[partId] = datasetNo++;
if (vtkmesh)
{
AddToBlock(output, selector, datasetNo, vtkmesh, patchName);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -252,80 +219,77 @@ void Foam::vtkPV3Foam::convertMeshCellZones
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoCellZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
zonePolyDecomp_.setSize(selector.size());
if (!selector.size())
{
return;
}
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; const cellZoneMesh& zMesh = mesh.cellZones();
selectionInfo& selector = regionInfoCellZones_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0 for (int partId = selector.start(); partId < selector.end(); ++partId)
selector.block(blockNo);
label datasetNo = 0;
if (selector.size())
{ {
const cellZoneMesh& zMesh = mesh.cellZones(); const word zoneName = getPartName(partId);
const label zoneId = zMesh.findZoneID(zoneName);
for if (!partStatus_[partId] || zoneId < 0)
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
word zoneName = getFirstWord continue;
}
if (debug)
{
Info<< "Creating VTK mesh for cellZone[" << zoneId << "] "
<< zoneName << endl;
}
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(zMesh[zoneId]);
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
subsetter.subMesh(),
zonePolyDecomp_[datasetNo]
);
if (vtkmesh)
{
// superCells + addPointCellLabels must contain global cell ids
inplaceRenumber
( (
regionSelection->GetArrayName(regionId) subsetter.cellMap(),
zonePolyDecomp_[datasetNo].superCells()
);
inplaceRenumber
(
subsetter.cellMap(),
zonePolyDecomp_[datasetNo].addPointCellLabels()
); );
label zoneId = zMesh.findZoneID(zoneName); // copy pointMap as well, otherwise pointFields fail
zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
if (!regionStatus_[regionId] || zoneId < 0) AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
{ vtkmesh->Delete();
continue;
}
if (debug) partDataset_[partId] = datasetNo++;
{
Info<< "Creating VTK mesh for cellZone: "
<< zoneId << endl;
}
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(zMesh[zoneId]);
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
subsetter.subMesh(),
zoneSuperCells_[datasetNo]
);
if (vtkmesh)
{
// renumber - superCells must contain global cell ids
inplaceRenumber
(
subsetter.cellMap(),
zoneSuperCells_[datasetNo]
);
AddToBlock
(
output, selector, datasetNo, vtkmesh,
zMesh[zoneId].name() + ":cellZone"
);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -345,77 +309,69 @@ void Foam::vtkPV3Foam::convertMeshCellSets
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoCellSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
csetPolyDecomp_.setSize(selector.size());
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; for (int partId = selector.start(); partId < selector.end(); ++partId)
selectionInfo& selector = regionInfoCellSets_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
// Create the cell sets and add as dataset
if (selector.size())
{ {
for const word partName = getPartName(partId);
(
int regionId = selector.start(); if (!partStatus_[partId])
regionId < selector.end();
++regionId)
{ {
if (!regionStatus_[regionId]) continue;
{ }
continue;
}
word selectedName = getFirstWord if (debug)
{
Info<< "Creating VTK mesh for cellSet=" << partName << endl;
}
const cellSet cSet(mesh, partName);
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(cSet);
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
subsetter.subMesh(),
csetPolyDecomp_[datasetNo]
);
if (vtkmesh)
{
// superCells + addPointCellLabels must contain global cell ids
inplaceRenumber
( (
regionSelection->GetArrayName(regionId) subsetter.cellMap(),
csetPolyDecomp_[datasetNo].superCells()
);
inplaceRenumber
(
subsetter.cellMap(),
csetPolyDecomp_[datasetNo].addPointCellLabels()
); );
if (debug) // copy pointMap as well, otherwise pointFields fail
{ csetPolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
Info<< "Creating VTK mesh for cellSet: " << selectedName
<< " region index: " << regionId << endl;
}
const cellSet cSet(mesh, selectedName); AddToBlock(output, vtkmesh, selector, datasetNo, partName);
fvMeshSubset subsetter(mesh); vtkmesh->Delete();
subsetter.setLargeCellSubset(cSet);
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh partDataset_[partId] = datasetNo++;
(
subsetter.subMesh(),
csetSuperCells_[datasetNo]
);
if (vtkmesh)
{
// renumber - superCells must contain global cell ids
inplaceRenumber
(
subsetter.cellMap(),
csetSuperCells_[datasetNo]
);
AddToBlock
(
output, selector, datasetNo, vtkmesh,
selectedName + ":cellSet"
);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -435,71 +391,51 @@ void Foam::vtkPV3Foam::convertMeshFaceZones
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoFaceZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (!selector.size())
{
return;
}
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; const faceZoneMesh& zMesh = mesh.faceZones();
selectionInfo& selector = regionInfoFaceZones_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0 for (int partId = selector.start(); partId < selector.end(); ++partId)
selector.block(blockNo);
label datasetNo = 0;
// Create the cell zone(s)
if (selector.size())
{ {
const faceZoneMesh& zMesh = mesh.faceZones(); const word zoneName = getPartName(partId);
const label zoneId = zMesh.findZoneID(zoneName);
for if (!partStatus_[partId] || zoneId < 0)
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
word zoneName = getFirstWord continue;
( }
regionSelection->GetArrayName(regionId)
);
const label zoneId = zMesh.findZoneID(zoneName); if (debug)
{
Info<< "Creating VTKmesh for faceZone[" << zoneId << "] "
<< zoneName << endl;
}
if (!regionStatus_[regionId] || zoneId < 0) vtkPolyData* vtkmesh = faceZoneVTKMesh(mesh, zMesh[zoneId]);
{ if (vtkmesh)
continue; {
} AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
vtkmesh->Delete();
if (debug) partDataset_[partId] = datasetNo++;
{
Info<< "Creating VTK mesh for faceZone[" << zoneId
<< "] " << zoneName << endl;
}
vtkPolyData* vtkmesh = faceZoneVTKMesh
(
mesh,
zMesh[zoneId]
);
if (vtkmesh)
{
AddToBlock
(
output, selector, datasetNo, vtkmesh,
zMesh[zoneId].name() + ":faceZone"
);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -519,69 +455,44 @@ void Foam::vtkPV3Foam::convertMeshFaceSets
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoFaceSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceSets" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceSets" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; for (int partId = selector.start(); partId < selector.end(); ++partId)
selectionInfo& selector = regionInfoFaceSets_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
// Create the face sets and add as dataset
if (selector.size())
{ {
for const word partName = getPartName(partId);
(
int regionId = selector.start(); if (!partStatus_[partId])
regionId < selector.end();
++regionId
)
{ {
if (!regionStatus_[regionId]) continue;
{ }
continue;
}
word selectedName = getFirstWord if (debug)
( {
regionSelection->GetArrayName(regionId) Info<< "Creating VTK mesh for faceSet=" << partName << endl;
); }
if (debug) const faceSet fSet(mesh, partName);
{
Info<< "Creating VTK mesh for faceSet: " << selectedName
<< " region index: " << regionId << endl;
}
const faceSet fSet(mesh, selectedName); vtkPolyData* vtkmesh = faceSetVTKMesh(mesh, fSet);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
vtkPolyData* vtkmesh = faceSetVTKMesh partDataset_[partId] = datasetNo++;
(
mesh,
fSet
);
if (vtkmesh)
{
AddToBlock
(
output, selector, datasetNo, vtkmesh,
selectedName + ":faceSet"
);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -601,6 +512,10 @@ void Foam::vtkPV3Foam::convertMeshPointZones
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoPointZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
@ -608,53 +523,33 @@ void Foam::vtkPV3Foam::convertMeshPointZones
} }
const fvMesh& mesh = *meshPtr_; const fvMesh& mesh = *meshPtr_;
selectionInfo& selector = regionInfoPointZones_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
if (selector.size()) if (selector.size())
{ {
const pointZoneMesh& zMesh = mesh.pointZones(); const pointZoneMesh& zMesh = mesh.pointZones();
for for (int partId = selector.start(); partId < selector.end(); ++partId)
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{ {
word zoneName = getFirstWord word zoneName = getPartName(partId);
(
regionSelection->GetArrayName(regionId)
);
label zoneId = zMesh.findZoneID(zoneName); label zoneId = zMesh.findZoneID(zoneName);
if (!regionStatus_[regionId] || zoneId < 0) if (!partStatus_[partId] || zoneId < 0)
{ {
continue; continue;
} }
vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]); vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]);
if (vtkmesh) if (vtkmesh)
{ {
AddToBlock AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
(
output, selector, datasetNo, vtkmesh,
zMesh[zoneId].name() + ":pointZone"
);
vtkmesh->Delete(); vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++; partDataset_[partId] = datasetNo++;
} }
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;
@ -675,63 +570,44 @@ void Foam::vtkPV3Foam::convertMeshPointSets
int& blockNo int& blockNo
) )
{ {
partInfo& selector = partInfoPointSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug) if (debug)
{ {
Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl; Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
printMemory(); printMemory();
} }
const fvMesh& mesh = *meshPtr_; for (int partId = selector.start(); partId < selector.end(); ++partId)
selectionInfo& selector = regionInfoPointSets_;
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
// set output block, restart at dataset 0
selector.block(blockNo);
label datasetNo = 0;
if (selector.size())
{ {
for word partName = getPartName(partId);
(
int regionId = selector.start(); if (!partStatus_[partId])
regionId < selector.end();
++regionId
)
{ {
if (!regionStatus_[regionId]) continue;
{ }
continue;
}
word selectedName = getFirstWord if (debug)
( {
regionSelection->GetArrayName(regionId) Info<< "Creating VTK mesh for pointSet=" << partName << endl;
); }
if (debug) const pointSet pSet(mesh, partName);
{
Info<< "Creating VTK mesh for pointSet: " << selectedName
<< " region index: " << regionId << endl;
}
const pointSet pSet(mesh, selectedName); vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet); partDataset_[partId] = datasetNo++;
if (vtkmesh)
{
AddToBlock
(
output, selector, datasetNo, vtkmesh,
selectedName + ":pointSet"
);
vtkmesh->Delete();
regionDataset_[regionId] = datasetNo++;
}
} }
} }
// was anything added? // anything added?
if (datasetNo) if (datasetNo)
{ {
++blockNo; ++blockNo;

View File

@ -42,7 +42,7 @@ Description
vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
( (
const fvMesh& mesh, const fvMesh& mesh,
labelList& superCells polyDecomp& decompInfo
) )
{ {
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
@ -59,6 +59,9 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// Number of additional cells generated by the decomposition of polyhedra // Number of additional cells generated by the decomposition of polyhedra
label nAddCells = 0; label nAddCells = 0;
labelList& superCells = decompInfo.superCells();
labelList& addPointCellLabels = decompInfo.addPointCellLabels();
const cellModel& tet = *(cellModeller::lookup("tet")); const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr")); const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism")); const cellModel& prism = *(cellModeller::lookup("prism"));
@ -112,7 +115,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// Set size of additional point addressing array // Set size of additional point addressing array
// (from added point to original cell) // (from added point to original cell)
addPointCellLabels_.setSize(nAddPoints); addPointCellLabels.setSize(nAddPoints);
// Set size of additional cells mapping array // Set size of additional cells mapping array
// (from added cell to original cell) // (from added cell to original cell)
@ -260,7 +263,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// Polyhedral cell. Decompose into tets + prisms. // Polyhedral cell. Decompose into tets + prisms.
// Mapping from additional point to cell // Mapping from additional point to cell
addPointCellLabels_[addPointI] = cellI; addPointCellLabels[addPointI] = cellI;
// Insert the new vertex from the cell-centre // Insert the new vertex from the cell-centre
label newVertexLabel = mesh.nPoints() + addPointI; label newVertexLabel = mesh.nPoints() + addPointI;

View File

@ -45,17 +45,12 @@ void Foam::vtkPV3Foam::convertPatchField
const word& name, const word& name,
const Field<Type>& ptf, const Field<Type>& ptf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo const label datasetNo
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray* cellData = vtkFloatArray::New(); vtkFloatArray* cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples( ptf.size() ); cellData->SetNumberOfTuples( ptf.size() );
cellData->SetNumberOfComponents( nComp ); cellData->SetNumberOfComponents( nComp );
@ -70,11 +65,15 @@ void Foam::vtkPV3Foam::convertPatchField
{ {
vec[d] = component(t, d); vec[d] = component(t, d);
} }
cellData->InsertTuple(i, vec); cellData->InsertTuple(i, vec);
} }
vtkmesh->GetCellData()->AddArray(cellData); vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete(); cellData->Delete();
} }
@ -86,17 +85,12 @@ void Foam::vtkPV3Foam::convertPatchPointField
const word& name, const word& name,
const Field<Type>& pptf, const Field<Type>& pptf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo const label datasetNo
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New(); vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples( pptf.size() ); pointData->SetNumberOfTuples( pptf.size() );
pointData->SetNumberOfComponents( nComp ); pointData->SetNumberOfComponents( nComp );
@ -115,7 +109,12 @@ void Foam::vtkPV3Foam::convertPatchPointField
pointData->InsertTuple(i, vec); pointData->InsertTuple(i, vec);
} }
vtkmesh->GetPointData()->AddArray(pointData); vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete(); pointData->Delete();
} }

View File

@ -44,21 +44,20 @@ void Foam::vtkPV3Foam::convertPointFields
vtkMultiBlockDataSet* output vtkMultiBlockDataSet* output
) )
{ {
// field subset based on type
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, pointPatchField, pointMesh>::typeName
)
);
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh.boundaryMesh();
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
forAllIter(IOobjectList, fieldObjects, iter) forAllConstIter(IOobjectList, objects, iter)
{ {
word fieldName = iter()->name(); const word& fieldName = iter()->name();
// restrict to this GeometricField<Type, ...>
if
(
iter()->headerClassName()
!= GeometricField<Type, pointPatchField, pointMesh>::typeName
)
{
continue;
}
if (debug) if (debug)
{ {
@ -73,52 +72,49 @@ void Foam::vtkPV3Foam::convertPointFields
); );
// // Convert activated internalMesh regions
// Convert internal mesh - if activated convertPointFieldBlock
//
for
( (
int regionId = regionInfoVolume_.start(); ptf,
regionId < regionInfoVolume_.end(); output,
++regionId partInfoVolume_,
) regionPolyDecomp_
{ );
const label datasetNo = regionDataset_[regionId];
if (!regionStatus_[regionId] || datasetNo < 0) // Convert activated cellZones
{ convertPointFieldBlock
continue; (
} ptf,
output,
partInfoCellZones_,
zonePolyDecomp_
);
// Convert activated cellSets
convertPointFieldBlock
(
ptf,
output,
partInfoCellSets_,
csetPolyDecomp_
);
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null(),
output,
regionInfoVolume_,
datasetNo
);
}
// //
// Convert patches - if activated // Convert patches - if activated
// //
for for
( (
int regionId = regionInfoPatches_.start(); int partId = partInfoPatches_.start();
regionId < regionInfoPatches_.end(); partId < partInfoPatches_.end();
++regionId ++partId
) )
{ {
word patchName = getFirstWord const word patchName = getPartName(partId);
( const label datasetNo = partDataset_[partId];
regionSelection->GetArrayName(regionId) const label patchId = patches.findPatchID(patchName);
);
const label datasetNo = regionDataset_[regionId]; if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
const label patchId = patches.findPatchID(patchName);
if (!regionStatus_[regionId] || datasetNo < 0 || patchId < 0)
{ {
continue; continue;
} }
@ -128,7 +124,7 @@ void Foam::vtkPV3Foam::convertPointFields
fieldName, fieldName,
ptf.boundaryField()[patchId].patchInternalField()(), ptf.boundaryField()[patchId].patchInternalField()(),
output, output,
regionInfoPatches_, partInfoPatches_,
datasetNo datasetNo
); );
} }
@ -136,27 +132,67 @@ void Foam::vtkPV3Foam::convertPointFields
} }
template<class Type>
void Foam::vtkPV3Foam::convertPointFieldBlock
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
)
{
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const label datasetNo = partDataset_[partId];
if (datasetNo >= 0 && partStatus_[partId])
{
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null(),
output,
selector,
datasetNo,
decompLst[datasetNo]
);
}
}
}
template<class Type> template<class Type>
void Foam::vtkPV3Foam::convertPointField void Foam::vtkPV3Foam::convertPointField
( (
const GeometricField<Type, pointPatchField, pointMesh>& ptf, const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf, const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo const label datasetNo,
const polyDecomp& decomp
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
const labelList& addPointCellLabels = decomp.addPointCellLabels();
const labelList& pointMap = decomp.pointMap();
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::SafeDownCast // use a pointMap or address directly into mesh
( label nPoints;
GetDataSetFromBlock(output, selector, datasetNo) if (pointMap.size())
); {
nPoints = pointMap.size();
}
else
{
nPoints = ptf.size();
}
vtkFloatArray *pointData = vtkFloatArray::New(); vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples( ptf.size() + addPointCellLabels_.size() ); pointData->SetNumberOfTuples( nPoints + addPointCellLabels.size() );
pointData->SetNumberOfComponents( nComp ); pointData->SetNumberOfComponents( nComp );
pointData->Allocate( nComp*(ptf.size() + addPointCellLabels_.size()) ); pointData->Allocate( nComp*(nPoints + addPointCellLabels.size()) );
pointData->SetName( tf.name().c_str() ); pointData->SetName( tf.name().c_str() );
@ -164,56 +200,73 @@ void Foam::vtkPV3Foam::convertPointField
{ {
Info<< "convert convertPointField: " Info<< "convert convertPointField: "
<< tf.name() << tf.name()
<< " size = " << ptf.size() << " size = " << nPoints
<< " nComp=" << nComp << " nComp=" << nComp
<< " nTuples = " << (ptf.size() + addPointCellLabels_.size()) << " nTuples = " << (nPoints + addPointCellLabels.size())
<< endl; << endl;
} }
float vec[nComp]; float vec[nComp];
forAll(ptf, i)
if (pointMap.size())
{ {
const Type& t = ptf[i]; forAll(pointMap, i)
for (direction d=0; d<nComp; d++)
{ {
vec[d] = component(t, d); const Type& t = ptf[pointMap[i]];
}
pointData->InsertTuple(i, vec);
}
// continue insertion from here
label i = ptf.size();
if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
const Type& t = tf[addPointCellLabels_[api]];
for (direction d=0; d<nComp; d++) for (direction d=0; d<nComp; d++)
{ {
vec[d] = component(t, d); vec[d] = component(t, d);
} }
pointData->InsertTuple(i, vec);
}
}
else
{
forAll(ptf, i)
{
const Type& t = ptf[i];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
pointData->InsertTuple(i, vec);
}
}
// continue insertion from here
label i = nPoints;
if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels, apI)
{
const Type& t = tf[addPointCellLabels[apI]];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
pointData->InsertTuple(i++, vec); pointData->InsertTuple(i++, vec);
} }
} }
else else
{ {
forAll(addPointCellLabels_, api) forAll(addPointCellLabels, apI)
{ {
Type t = interpolatePointToCell(ptf, addPointCellLabels_[api]); Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]);
for (direction d=0; d<nComp; d++) for (direction d=0; d<nComp; d++)
{ {
vec[d] = component(t, d); vec[d] = component(t, d);
} }
pointData->InsertTuple(i++, vec); pointData->InsertTuple(i++, vec);
} }
} }
vtkmesh->GetPointData()->AddArray(pointData); vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete(); pointData->Delete();
} }

View File

@ -124,22 +124,22 @@ void Foam::vtkPV3Foam::updateInfoInternalMesh()
Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl; Info<< "<beg> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
} }
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
// Determine number of meshes available // Determine number of meshes available
HashTable<const fvMesh*> meshObjects = dbPtr_().lookupClass<const fvMesh>(); HashTable<const fvMesh*> meshObjects = dbPtr_().lookupClass<const fvMesh>();
nMesh_ = meshObjects.size(); nMesh_ = meshObjects.size();
// Determine regions (internal mesh and patches...) // Determine mesh parts (internalMesh, patches...)
//- Add internal mesh as first entry //- Add internal mesh as first entry
regionInfoVolume_ = regionSelection->GetNumberOfArrays(); partInfoVolume_ = partSelection->GetNumberOfArrays();
regionSelection->AddArray("internalMesh"); partSelection->AddArray("internalMesh");
regionInfoVolume_ += 1; partInfoVolume_ += 1;
if (debug) if (debug)
{ {
// just for debug info // just for debug info
getSelectedArrayEntries(regionSelection); getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl; Info<< "<end> Foam::vtkPV3Foam::updateInfoInternalMesh" << endl;
} }
@ -161,14 +161,14 @@ void Foam::vtkPV3Foam::updateInfoLagrangian()
readDir(dbPtr_->timePath()/"lagrangian", fileName::DIRECTORY) readDir(dbPtr_->timePath()/"lagrangian", fileName::DIRECTORY)
); );
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
regionInfoLagrangian_ = regionSelection->GetNumberOfArrays(); partInfoLagrangian_ = partSelection->GetNumberOfArrays();
int nClouds = 0; int nClouds = 0;
forAll(cloudDirs, cloudI) forAll(cloudDirs, cloudI)
{ {
// Add cloud to GUI list // Add cloud to GUI list
regionSelection->AddArray partSelection->AddArray
( (
(cloudDirs[cloudI] + " - lagrangian").c_str() (cloudDirs[cloudI] + " - lagrangian").c_str()
); );
@ -176,12 +176,12 @@ void Foam::vtkPV3Foam::updateInfoLagrangian()
++nClouds; ++nClouds;
} }
regionInfoLagrangian_ += nClouds; partInfoLagrangian_ += nClouds;
if (debug) if (debug)
{ {
// just for debug info // just for debug info
getSelectedArrayEntries(regionSelection); getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl; Info<< "<end> Foam::vtkPV3Foam::updateInfoLagrangian" << endl;
} }
@ -196,8 +196,8 @@ void Foam::vtkPV3Foam::updateInfoPatches()
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl; << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
} }
vtkDataArraySelection *regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
regionInfoPatches_ = regionSelection->GetNumberOfArrays(); partInfoPatches_ = partSelection->GetNumberOfArrays();
int nPatches = 0; int nPatches = 0;
if (meshPtr_) if (meshPtr_)
@ -210,7 +210,7 @@ void Foam::vtkPV3Foam::updateInfoPatches()
if (pp.size()) if (pp.size())
{ {
// Add patch to GUI list // Add patch to GUI list
regionSelection->AddArray partSelection->AddArray
( (
(pp.name() + " - patch").c_str() (pp.name() + " - patch").c_str()
); );
@ -236,7 +236,7 @@ void Foam::vtkPV3Foam::updateInfoPatches()
) )
); );
// Start regions at patches // Add (non-zero) patches to the list of mesh parts
forAll(patchEntries, entryI) forAll(patchEntries, entryI)
{ {
label nFaces label nFaces
@ -248,7 +248,7 @@ void Foam::vtkPV3Foam::updateInfoPatches()
if (nFaces) if (nFaces)
{ {
// Add patch to GUI list // Add patch to GUI list
regionSelection->AddArray partSelection->AddArray
( (
(patchEntries[entryI].keyword() + " - patch").c_str() (patchEntries[entryI].keyword() + " - patch").c_str()
); );
@ -258,12 +258,12 @@ void Foam::vtkPV3Foam::updateInfoPatches()
} }
} }
regionInfoPatches_ += nPatches; partInfoPatches_ += nPatches;
if (debug) if (debug)
{ {
// just for debug info // just for debug info
getSelectedArrayEntries(regionSelection); getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl; Info<< "<end> Foam::vtkPV3Foam::updateInfoPatches" << endl;
} }
@ -283,8 +283,7 @@ void Foam::vtkPV3Foam::updateInfoZones()
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl; << " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
} }
vtkDataArraySelection *regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
wordList namesLst; wordList namesLst;
// //
@ -299,13 +298,12 @@ void Foam::vtkPV3Foam::updateInfoZones()
namesLst = readZoneNames("cellZones"); namesLst = readZoneNames("cellZones");
} }
regionInfoCellZones_ = regionSelection->GetNumberOfArrays(); partInfoCellZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI) forAll(namesLst, elemI)
{ {
regionSelection->AddArray((namesLst[elemI] + " - cellZone").c_str()); partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
} }
regionInfoCellZones_ += namesLst.size(); partInfoCellZones_ += namesLst.size();
zoneSuperCells_.setSize(regionInfoCellZones_.size());
// //
@ -320,15 +318,15 @@ void Foam::vtkPV3Foam::updateInfoZones()
namesLst = readZoneNames("faceZones"); namesLst = readZoneNames("faceZones");
} }
regionInfoFaceZones_ = regionSelection->GetNumberOfArrays(); partInfoFaceZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI) forAll(namesLst, elemI)
{ {
regionSelection->AddArray partSelection->AddArray
( (
(namesLst[elemI] + " - faceZone").c_str() (namesLst[elemI] + " - faceZone").c_str()
); );
} }
regionInfoFaceZones_ += namesLst.size(); partInfoFaceZones_ += namesLst.size();
// //
@ -343,21 +341,21 @@ void Foam::vtkPV3Foam::updateInfoZones()
namesLst = readZoneNames("pointZones"); namesLst = readZoneNames("pointZones");
} }
regionInfoPointZones_ = regionSelection->GetNumberOfArrays(); partInfoPointZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI) forAll(namesLst, elemI)
{ {
regionSelection->AddArray partSelection->AddArray
( (
(namesLst[elemI] + " - pointZone").c_str() (namesLst[elemI] + " - pointZone").c_str()
); );
} }
regionInfoPointZones_ += namesLst.size(); partInfoPointZones_ += namesLst.size();
if (debug) if (debug)
{ {
// just for debug info // just for debug info
getSelectedArrayEntries(regionSelection); getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl; Info<< "<end> Foam::vtkPV3Foam::updateInfoZones" << endl;
} }
@ -376,7 +374,7 @@ void Foam::vtkPV3Foam::updateInfoSets()
Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl; Info<< "<beg> Foam::vtkPV3Foam::updateInfoSets" << endl;
} }
vtkDataArraySelection *regionSelection = reader_->GetRegionSelection(); vtkDataArraySelection* partSelection = reader_->GetPartSelection();
// Add names of sets // Add names of sets
IOobjectList objects IOobjectList objects
@ -387,27 +385,26 @@ void Foam::vtkPV3Foam::updateInfoSets()
); );
regionInfoCellSets_ = regionSelection->GetNumberOfArrays(); partInfoCellSets_ = partSelection->GetNumberOfArrays();
regionInfoCellSets_ += addToSelection<cellSet> partInfoCellSets_ += addToSelection<cellSet>
( (
regionSelection, partSelection,
objects, objects,
" - cellSet" " - cellSet"
); );
csetSuperCells_.setSize(regionInfoCellSets_.size());
regionInfoFaceSets_ = regionSelection->GetNumberOfArrays(); partInfoFaceSets_ = partSelection->GetNumberOfArrays();
regionInfoFaceSets_ += addToSelection<faceSet> partInfoFaceSets_ += addToSelection<faceSet>
( (
regionSelection, partSelection,
objects, objects,
" - faceSet" " - faceSet"
); );
regionInfoPointSets_ = regionSelection->GetNumberOfArrays(); partInfoPointSets_ = partSelection->GetNumberOfArrays();
regionInfoPointSets_ += addToSelection<pointSet> partInfoPointSets_ += addToSelection<pointSet>
( (
regionSelection, partSelection,
objects, objects,
" - pointSet" " - pointSet"
); );
@ -415,7 +412,7 @@ void Foam::vtkPV3Foam::updateInfoSets()
if (debug) if (debug)
{ {
// just for debug info // just for debug info
getSelectedArrayEntries(regionSelection); getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl; Info<< "<end> Foam::vtkPV3Foam::updateInfoSets" << endl;
} }
@ -433,35 +430,24 @@ void Foam::vtkPV3Foam::updateInfoLagrangianFields()
vtkDataArraySelection *fieldSelection = vtkDataArraySelection *fieldSelection =
reader_->GetLagrangianFieldSelection(); reader_->GetLagrangianFieldSelection();
vtkDataArraySelection *regionSelection =
reader_->GetRegionSelection();
// preserve the enabled selections // preserve the enabled selections
stringList selectedEntries = getSelectedArrayEntries stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
(
fieldSelection,
true
);
fieldSelection->RemoveAllArrays(); fieldSelection->RemoveAllArrays();
//
// TODO - can currently only get fields from ONE cloud
// //
// TODO - currently only get fields from ONE cloud
// have to decide if the second set of fields get mixed in
// or dealt with separately
const selectionInfo& selector = regionInfoLagrangian_; const partInfo& selector = partInfoLagrangian_;
int regionId = selector.start(); int partId = selector.start();
if (!selector.size() || regionId < 0) if (!selector.size() || partId < 0)
{ {
return; return;
} }
word cloudName = getFirstWord word cloudName = getPartName(partId);
(
regionSelection->GetArrayName(regionId)
);
IOobjectList objects IOobjectList objects
( (
@ -488,6 +474,7 @@ void Foam::vtkPV3Foam::updateInfoLagrangianFields()
addToSelection<IOField<sphericalTensor> > addToSelection<IOField<sphericalTensor> >
( (
fieldSelection, fieldSelection,
objects objects
); );
addToSelection<IOField<symmTensor> > addToSelection<IOField<symmTensor> >
@ -502,11 +489,7 @@ void Foam::vtkPV3Foam::updateInfoLagrangianFields()
); );
// restore the enabled selections // restore the enabled selections
setSelectedArrayEntries setSelectedArrayEntries(fieldSelection, enabledEntries);
(
fieldSelection,
selectedEntries
);
if (debug) if (debug)
{ {
@ -517,5 +500,4 @@ void Foam::vtkPV3Foam::updateInfoLagrangianFields()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

@ -43,18 +43,18 @@ void Foam::vtkPV3Foam::updateInfoFields
Info<< "<beg> Foam::vtkPV3Foam::updateInfoFields" << endl; Info<< "<beg> Foam::vtkPV3Foam::updateInfoFields" << endl;
} }
stringList selectedEntries; stringList enabledEntries;
// enable 'p' and 'U' on the first call // enable 'p' and 'U' on the first call
if (select->GetNumberOfArrays() == 0 && !meshPtr_) if (select->GetNumberOfArrays() == 0 && !meshPtr_)
{ {
selectedEntries.setSize(2); enabledEntries.setSize(2);
selectedEntries[0] = "p"; enabledEntries[0] = "p";
selectedEntries[1] = "U"; enabledEntries[1] = "U";
} }
else else
{ {
// preserve the enabled selections // preserve the enabled selections
selectedEntries = getSelectedArrayEntries(select); enabledEntries = getSelectedArrayEntries(select);
} }
select->RemoveAllArrays(); select->RemoveAllArrays();
@ -90,11 +90,7 @@ void Foam::vtkPV3Foam::updateInfoFields
); );
// restore the enabled selections // restore the enabled selections
setSelectedArrayEntries setSelectedArrayEntries(select, enabledEntries);
(
select,
selectedEntries
);
if (debug) if (debug)
{ {

View File

@ -0,0 +1,341 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Misc helper methods and utilities
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
#include "vtkPV3FoamReader.h"
// Foam includes
#include "fvMesh.H"
#include "Time.H"
#include "IFstream.H"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV3Foam::AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const partInfo& selector,
const label datasetNo,
const string& datasetName
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (!block)
{
if (blockDO)
{
FatalErrorIn("Foam::vtkPV3Foam::AddToBlock")
<< "Block already has a vtkDataSet assigned to it"
<< endl;
return;
}
block = vtkMultiBlockDataSet::New();
output->SetBlock(blockNo, block);
block->Delete();
}
if (debug)
{
Info<< "block[" << blockNo << "] has "
<< block->GetNumberOfBlocks()
<< " datasets prior to adding set " << datasetNo
<< " with name: " << datasetName << endl;
}
block->SetBlock(datasetNo, dataset);
// name the block when assigning dataset 0
if (datasetNo == 0)
{
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
selector.name()
);
}
if (datasetName.size())
{
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(),
datasetName.c_str()
);
}
}
vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
}
return 0;
}
// ununsed at the moment
Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const partInfo& selector
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return block->GetNumberOfBlocks();
}
return 0;
}
Foam::word Foam::vtkPV3Foam::getPartName(int partId)
{
return getFirstWord(reader_->GetPartArrayName(partId));
}
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))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::wordHashSet Foam::vtkPV3Foam::getSelected
(
vtkDataArraySelection* select,
const partInfo& selector
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
(
vtkDataArraySelection* select
)
{
stringList selections(select->GetNumberOfArrays());
label nElem = 0;
forAll(selections, elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
label nElem = select->GetNumberOfArrays();
Info<< "available(";
for (int elemI = 0; elemI < nElem; ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
Foam::stringList Foam::vtkPV3Foam::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const partInfo& selector
)
{
stringList selections(selector.size());
label nElem = 0;
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
Info<< "available(";
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
void Foam::vtkPV3Foam::setSelectedArrayEntries
(
vtkDataArraySelection* select,
const stringList& selections
)
{
const int nElem = select->GetNumberOfArrays();
select->DisableAllArrays();
// Loop through entries, setting values from selectedEntries
for (int elemI=0; elemI < nElem; ++elemI)
{
string arrayName(select->GetArrayName(elemI));
forAll(selections, elemI)
{
if (selections[elemI] == arrayName)
{
select->EnableArray(arrayName.c_str());
break;
}
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// parse these bits of info from /proc/meminfo (Linux)
//
// MemTotal: 2062660 kB
// MemFree: 1124400 kB
//
// used = MemTotal - MemFree is what the free(1) uses.
//
void Foam::vtkPV3Foam::printMemory()
{
const char* meminfo = "/proc/meminfo";
if (exists(meminfo))
{
IFstream is(meminfo);
label memTotal = 0;
label memFree = 0;
string line;
while (is.getLine(line).good())
{
char tag[32];
int value;
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
{
if (!strcmp(tag, "MemTotal:"))
{
memTotal = value;
}
else if (!strcmp(tag, "MemFree:"))
{
memFree = value;
}
}
}
Info << "memUsed: " << (memTotal - memFree) << " kB\n";
}
}
// ************************************************************************* //

View File

@ -49,21 +49,19 @@ void Foam::vtkPV3Foam::convertVolFields
vtkMultiBlockDataSet* output vtkMultiBlockDataSet* output
) )
{ {
// field subset based on type
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, fvPatchField, volMesh>::typeName
)
);
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh.boundaryMesh();
vtkDataArraySelection* regionSelection = reader_->GetRegionSelection();
forAllIter(IOobjectList, fieldObjects, iter) forAllConstIter(IOobjectList, objects, iter)
{ {
word fieldName = iter()->name(); // restrict to GeometricField<Type, ...>
if
(
iter()->headerClassName()
!= GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
continue;
}
GeometricField<Type, fvPatchField, volMesh> tf GeometricField<Type, fvPatchField, volMesh> tf
( (
@ -77,60 +75,52 @@ void Foam::vtkPV3Foam::convertVolFields
); );
// // Convert activated internalMesh regions
// Convert internal mesh - if activated convertVolFieldBlock
//
for
( (
int regionId = regionInfoVolume_.start(); tf,
regionId < regionInfoVolume_.end(); tptf(),
++regionId output,
) partInfoVolume_,
{ regionPolyDecomp_
const label datasetNo = regionDataset_[regionId]; );
if (!regionStatus_[regionId] || datasetNo < 0) // Convert activated cellZones
{ convertVolFieldBlock
continue; (
} tf,
tptf(),
output,
partInfoCellZones_,
zonePolyDecomp_
);
// Convert activated cellSets
convertVolFieldBlock
(
tf,
tptf(),
output,
partInfoCellSets_,
csetPolyDecomp_
);
convertVolField
(
tf,
output,
regionInfoVolume_,
datasetNo,
superCells_
);
convertPointField
(
tptf(),
tf,
output,
regionInfoVolume_,
datasetNo
);
}
// //
// Convert patches - if activated // Convert patches - if activated
// //
for for
( (
int regionId = regionInfoPatches_.start(); int partId = partInfoPatches_.start();
regionId < regionInfoPatches_.end(); partId < partInfoPatches_.end();
++regionId ++partId
) )
{ {
word patchName = getFirstWord const word patchName = getPartName(partId);
( const label datasetNo = partDataset_[partId];
regionSelection->GetArrayName(regionId)
);
const label datasetNo = regionDataset_[regionId];
const label patchId = patches.findPatchID(patchName); const label patchId = patches.findPatchID(patchName);
if (!regionStatus_[regionId] || datasetNo < 0 || patchId < 0) if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
{ {
continue; continue;
} }
@ -147,18 +137,28 @@ void Foam::vtkPV3Foam::convertVolFields
) )
) )
{ {
fvPatch p fvPatch p(ptf.patch().patch(), tf.mesh().boundary());
tmp<Field<Type> > tpptf
( (
ptf.patch().patch(), fvPatchField<Type>(p, tf).patchInternalField()
tf.mesh().boundary()
); );
convertPatchField convertPatchField
( (
tf.name(), tf.name(),
fvPatchField<Type>(p, tf).patchInternalField()(), tpptf(),
output, output,
regionInfoPatches_, partInfoPatches_,
datasetNo
);
convertPatchPointField
(
tf.name(),
ppInterpList[patchId].faceToPointInterpolate(tpptf)(),
output,
partInfoPatches_,
datasetNo datasetNo
); );
} }
@ -169,91 +169,19 @@ void Foam::vtkPV3Foam::convertVolFields
tf.name(), tf.name(),
ptf, ptf,
output, output,
regionInfoPatches_, partInfoPatches_,
datasetNo
);
convertPatchPointField
(
tf.name(),
ppInterpList[patchId].faceToPointInterpolate(ptf)(),
output,
partInfoPatches_,
datasetNo datasetNo
); );
} }
convertPatchPointField
(
tf.name(),
ppInterpList[patchId].faceToPointInterpolate(ptf)(),
output,
regionInfoPatches_,
datasetNo
);
}
//
// Convert cell zones - if activated
//
for
(
int regionId = regionInfoCellZones_.start();
regionId < regionInfoCellZones_.end();
++regionId
)
{
const label datasetNo = regionDataset_[regionId];
if (!regionStatus_[regionId] || datasetNo < 0)
{
continue;
}
if (debug)
{
Info<< "wish to convert cellzone: "
<< getFirstWord(regionSelection->GetArrayName(regionId))
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
convertVolField
(
tf,
output,
regionInfoCellZones_,
datasetNo,
zoneSuperCells_[datasetNo]
);
}
//
// Convert cell sets - if activated
//
for
(
int regionId = regionInfoCellSets_.start();
regionId < regionInfoCellSets_.end();
++regionId
)
{
const label datasetNo = regionDataset_[regionId];
if (!regionStatus_[regionId] || datasetNo < 0)
{
continue;
}
if (debug)
{
Info<< "wish to convert cellset: "
<< getFirstWord(regionSelection->GetArrayName(regionId))
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
convertVolField
(
tf,
output,
regionInfoCellSets_,
datasetNo,
csetSuperCells_[datasetNo]
);
} }
// //
@ -261,18 +189,15 @@ void Foam::vtkPV3Foam::convertVolFields
// //
for for
( (
int regionId = regionInfoFaceZones_.start(); int partId = partInfoFaceZones_.start();
regionId < regionInfoFaceZones_.end(); partId < partInfoFaceZones_.end();
++regionId ++partId
) )
{ {
word zoneName = getFirstWord const word zoneName = getPartName(partId);
( const label datasetNo = partDataset_[partId];
regionSelection->GetArrayName(regionId)
);
const label datasetNo = regionDataset_[regionId];
if (!regionStatus_[regionId] || datasetNo < 0) if (!partStatus_[partId] || datasetNo < 0)
{ {
continue; continue;
} }
@ -285,24 +210,17 @@ void Foam::vtkPV3Foam::convertVolFields
continue; continue;
} }
if (debug)
{
Info<< "wish to convert facezone: "
<< zoneName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
convertFaceField convertFaceField
( (
tf, tf,
output, output,
regionInfoFaceZones_, partInfoFaceZones_,
datasetNo, datasetNo,
mesh, mesh,
zMesh[zoneId] zMesh[zoneId]
); );
// TODO: points
} }
// //
@ -310,62 +228,88 @@ void Foam::vtkPV3Foam::convertVolFields
// //
for for
( (
int regionId = regionInfoFaceSets_.start(); int partId = partInfoFaceSets_.start();
regionId < regionInfoFaceSets_.end(); partId < partInfoFaceSets_.end();
++regionId ++partId
) )
{ {
const label datasetNo = regionDataset_[regionId]; const word selectName = getPartName(partId);
if (!regionStatus_[regionId] || datasetNo < 0) const label datasetNo = partDataset_[partId];
if (!partStatus_[partId] || datasetNo < 0)
{ {
continue; continue;
} }
word selectName = getFirstWord
(
regionSelection->GetArrayName(regionId)
);
if (debug)
{
Info<< "wish to convert faceset: " << selectName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
const faceSet fSet(mesh, selectName); const faceSet fSet(mesh, selectName);
convertFaceField convertFaceField
( (
tf, tf,
output, output,
regionInfoFaceSets_, partInfoFaceSets_,
datasetNo, datasetNo,
mesh, mesh,
fSet fSet
); );
// TODO: points
} }
} }
} }
template<class Type>
void Foam::vtkPV3Foam::convertVolFieldBlock
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
)
{
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const label datasetNo = partDataset_[partId];
if (datasetNo >= 0 && partStatus_[partId])
{
convertVolField
(
tf,
output,
selector,
datasetNo,
decompLst[datasetNo]
);
convertPointField
(
ptf,
tf,
output,
selector,
datasetNo,
decompLst[datasetNo]
);
}
}
}
template<class Type> template<class Type>
void Foam::vtkPV3Foam::convertVolField void Foam::vtkPV3Foam::convertVolField
( (
const GeometricField<Type, fvPatchField, volMesh>& tf, const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output, vtkMultiBlockDataSet* output,
const selectionInfo& selector, const partInfo& selector,
const label datasetNo, const label datasetNo,
labelList& superCells const polyDecomp& decompInfo
) )
{ {
const label nComp = pTraits<Type>::nComponents; const label nComp = pTraits<Type>::nComponents;
const labelList& superCells = decompInfo.superCells();
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray* celldata = vtkFloatArray::New(); vtkFloatArray* celldata = vtkFloatArray::New();
celldata->SetNumberOfTuples( superCells.size() ); celldata->SetNumberOfTuples( superCells.size() );
@ -390,11 +334,15 @@ void Foam::vtkPV3Foam::convertVolField
{ {
vec[d] = component(t, d); vec[d] = component(t, d);
} }
celldata->InsertTuple(i, vec); celldata->InsertTuple(i, vec);
} }
vtkmesh->GetCellData()->AddArray(celldata); vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(celldata);
celldata->Delete(); celldata->Delete();
} }