Commit be0cc59a authored by Mark Olesen's avatar Mark Olesen

ENH: finiteArea support for paraview reader plugin (paraFoam)

parent 984f8f00
......@@ -13,6 +13,7 @@ include_directories(
$ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude
$ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude
$ENV{WM_PROJECT_DIR}/src/conversion/lnInclude
$ENV{WM_PROJECT_DIR}/src/finiteArea/lnInclude
$ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude
${PROJECT_SOURCE_DIR}/../foamPv
${PROJECT_SOURCE_DIR}/../vtkPVFoam
......@@ -66,6 +67,7 @@ target_link_libraries(
vtkPVFoam-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}
foamPv-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}
conversion
finiteArea
finiteVolume
OpenFOAM
)
......
......@@ -309,16 +309,16 @@ int vtkPVFoamReader::RequestData
// Get the requested time step.
// We only support requests for a single time step
int nRequestTime = 0;
double requestTime[nInfo];
std::vector<double> requestTime;
requestTime.reserve(nInfo);
// taking port0 as the lead for other outputs would be nice, but fails when
// a filter is added - we need to check everything
// but since PREVIOUS_UPDATE_TIME_STEPS() is protected, relay the logic
// to the vtkPVFoam::setTime() method
for (int infoI = 0; infoI < nInfo; ++infoI)
for (int infoi = 0; infoi < nInfo; ++infoi)
{
vtkInformation *outInfo = outputVector->GetInformationObject(infoI);
vtkInformation *outInfo = outputVector->GetInformationObject(infoi);
const int nsteps =
outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
......@@ -329,7 +329,7 @@ int vtkPVFoamReader::RequestData
&& nsteps > 0
)
{
requestTime[nRequestTime] =
const double timeValue =
(
1 == nsteps
// Only one time-step available, UPDATE_TIME_STEP is unreliable
......@@ -337,16 +337,13 @@ int vtkPVFoamReader::RequestData
: outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
);
// outInfo->Set(vtkDataObject::DATA_TIME_STEP(), requestTime[nRequestTime]);
// this->SetTimeValue(requestedTimeValue);
++nRequestTime;
// outInfo->Set(vtkDataObject::DATA_TIME_STEP(), timeValue);
// this->SetTimeValue(timeValue);
requestTime.push_back(timeValue);
}
}
if (nRequestTime)
{
backend_->setTime(nRequestTime, requestTime);
}
backend_->setTime(requestTime);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
......
......@@ -25,9 +25,9 @@ Class
vtkPVFoamReader
Description
reads a dataset in OpenFOAM format
Reads a dataset in OpenFOAM format
vtkPVblockMeshReader creates an multiblock dataset.
vtkPVFoamReader creates an multiblock dataset.
It uses the OpenFOAM infrastructure (fvMesh, etc) to handle mesh and
field data.
......
......@@ -43,6 +43,35 @@ namespace Foam
defineTypeNameAndDebug(foamPvCore, 0);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::Ostream& Foam::foamPvCore::printDataArraySelection
(
Ostream& os,
vtkDataArraySelection* select
)
{
if (!select)
{
return os;
}
const int n = select->GetNumberOfArrays();
os << n << '(';
for (int i=0; i < n; ++i)
{
if (i) os << ' ';
os << select->GetArrayName(i) << '='
<< (select->GetArraySetting(i) ? 1 : 0);
}
os << ')';
return os;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamPvCore::addToBlock
......@@ -229,10 +258,8 @@ Foam::word Foam::foamPvCore::getFoamName(const std::string& str)
// Already checked for valid/invalid chars
return word(str.substr(beg, beg+end), false);
}
else
{
return word::null;
}
return word::null;
}
......
......@@ -119,13 +119,51 @@ public:
setStart(startAt);
}
//- Increment the size
void operator+=(label n)
{
setSize(size() + n);
}
//- True if the labelRange intersects any key in the Map
template<class T>
bool intersects(const Map<T>& map) const
{
for (const label idx : *this)
{
if (map.found(idx))
{
return true;
}
}
return false;
}
//- The intersection ids with keys in the Map
template<class T>
List<label> intersection(const Map<T>& map) const
{
List<label> indices(Foam::min(map.size(), this->size()));
if (indices.size())
{
label n = 0;
for (const label idx : *this)
{
if (map.found(idx))
{
indices[n++] = idx;
}
}
indices.setSize(n);
}
return indices;
}
}; // End class arrayRange
......@@ -139,6 +177,7 @@ private:
//- Disallow default bitwise assignment
void operator=(const foamPvCore&) = delete;
public:
//- Static data members
......@@ -146,8 +185,15 @@ public:
//- Construct null
foamPvCore()
{}
foamPvCore() = default;
//- Print information about vtkDataArraySelection
static Ostream& printDataArraySelection
(
Ostream& os,
vtkDataArraySelection* select
);
//- Convenience method for the VTK multiblock API
......
......@@ -152,7 +152,8 @@ void Foam::foamPvCore::setSelectedArrayEntries
)
{
const int n = select->GetNumberOfArrays();
// disable everything not explicitly enabled
// Disable everything not explicitly enabled
select->DisableAllArrays();
// Loop through entries, enabling as required
......
......@@ -29,7 +29,7 @@ Description
#ifndef foamPvFields_H
#define foamPvFields_H
#include "volFields.H"
#include "symmTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -40,27 +40,17 @@ namespace Foam
Class foamPvFields Declaration
\*---------------------------------------------------------------------------*/
class foamPvFields
struct foamPvFields
{
// Private Member Functions
//- Disallow default bitwise copy construct
foamPvFields(const foamPvFields&) = delete;
//- Disallow default bitwise assignment
void operator=(const foamPvFields&) = delete;
public:
//- Remapping for some data types
template<class Type>
inline static void remapTuple(float vec[])
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
};
}; // End class foamPvFields
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Template specialization for symmTensor
template<>
......
......@@ -4,6 +4,7 @@ EXE_INC = \
${c++LESSWARN} \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
......@@ -14,6 +15,7 @@ EXE_INC = \
-I../PVFoamReader
LIB_LIBS = \
-lfiniteArea \
-ldynamicMesh \
-lconversion \
-lgenericPatchFields \
......
This diff is collapsed.
......@@ -99,6 +99,7 @@ namespace Foam
// OpenFOAM class forward declarations
class argList;
class Time;
class faMesh;
class fvMesh;
class IOobjectList;
class polyPatch;
......@@ -127,9 +128,8 @@ class vtkPVFoam
// with the output fields.
// The original copy is reused for different timestep
template<class DataType>
class foamVtkCaching
struct foamVtkCaching
{
public:
typedef DataType dataType;
//- The geometry, without any cell/point data
......@@ -208,7 +208,7 @@ class vtkPVFoam
//- Bookkeeping for vtkPolyData
class foamVtpData
struct foamVtpData
:
public foamVtkCaching<vtkPolyData>,
public foamVtkMeshMaps
......@@ -216,7 +216,7 @@ class vtkPVFoam
//- Bookkeeping for vtkUnstructuredGrid
class foamVtuData
struct foamVtuData
:
public foamVtkCaching<vtkUnstructuredGrid>,
public foamVtkMeshMaps
......@@ -231,8 +231,11 @@ class vtkPVFoam
//- OpenFOAM time control
autoPtr<Time> dbPtr_;
//- OpenFOAM mesh
fvMesh* meshPtr_;
//- OpenFOAM finite volume mesh
fvMesh* volMeshPtr_;
//- OpenFOAM finite area mesh
faMesh* areaMeshPtr_;
//- The mesh region
word meshRegion_;
......@@ -262,8 +265,9 @@ class vtkPVFoam
// used to index into selectedPartIds and thus indirectly into
// cachedVtp, cachedVtu
arrayRange rangeVolume_;
arrayRange rangeArea_;
arrayRange rangePatches_;
arrayRange rangeLagrangian_;
arrayRange rangeClouds_;
arrayRange rangeCellZones_;
arrayRange rangeFaceZones_;
arrayRange rangePointZones_;
......@@ -295,6 +299,9 @@ class vtkPVFoam
//- Internal mesh info
void updateInfoInternalMesh(vtkDataArraySelection* select);
//- Finite area mesh info
void updateInfoAreaMesh(vtkDataArraySelection* select);
//- Lagrangian info
void updateInfoLagrangian(vtkDataArraySelection* select);
......@@ -326,18 +333,28 @@ class vtkPVFoam
template<template<class> class patchType, class meshType>
void updateInfoFields
(
vtkDataArraySelection* select
vtkDataArraySelection* select,
const IOobjectList& objects
);
//- Volume/Area field info
void updateInfoContinuumFields(vtkDataArraySelection* select);
//- Point field info
void updateInfoPointFields(vtkDataArraySelection* select);
//- Lagrangian field info
void updateInfoLagrangianFields(vtkDataArraySelection* select);
// Mesh conversion functions
//- Convert InternalMesh
//- Convert internalMesh
void convertMeshVolume();
//- Convert areaMesh
void convertMeshArea();
//- Convert Lagrangian points
void convertMeshLagrangian();
......@@ -490,9 +507,12 @@ class vtkPVFoam
) const;
//- Convert volume fields
//- Convert finite volume fields
void convertVolFields();
//- Convert finite area fields
void convertAreaFields();
//- Convert point fields
void convertPointFields();
......@@ -528,6 +548,14 @@ class vtkPVFoam
const IOobjectList& objects
);
//- Area fields - all types
template<class Type>
void convertAreaFields
(
const faMesh& mesh,
const IOobjectList& objects
);
//- Volume field - all selected parts
template<class Type>
void convertVolFieldBlock
......@@ -631,7 +659,7 @@ public:
//- Set the runTime to the first plausible request time,
// returns the timeIndex
// sets to "constant" on error
int setTime(int count, const double requestTimes[]);
int setTime(const std::vector<double>& requestTimes);
//- The current time index
int timeIndex() const
......
......@@ -38,6 +38,8 @@ InClass
#include "zeroGradientFvPatchField.H"
#include "interpolatePointToCell.H"
#include "foamPvFields.H"
#include "areaFaMesh.H"
#include "areaFields.H"
// vtk includes
#include "vtkFloatArray.h"
......@@ -69,7 +71,7 @@ void Foam::vtkPVFoam::convertVolField
{
if (debug)
{
Info<< "convertVolField interpolating:" << fld.name() << endl;
Info<< "convertVolField interpolating:" << fld.name() << nl;
}
ptfPtr.reset
......@@ -83,12 +85,12 @@ void Foam::vtkPVFoam::convertVolField
convertVolFieldBlock(fld, ptfPtr, rangeCellSets_); // cellSets
// Patches - currently skip field conversion for groups
for (auto partId : rangePatches_)
for
(
const auto partId
: rangePatches_.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
auto iter = cachedVtp_.find(longName);
......@@ -97,10 +99,12 @@ void Foam::vtkPVFoam::convertVolField
// Should not happen, but for safety require a vtk geometry
continue;
}
foamVtpData& vtpData = iter.object();
auto dataset = vtpData.dataset;
const labelList& patchIds = vtpData.additionalIds();
if (patchIds.empty())
{
continue;
......@@ -184,12 +188,12 @@ void Foam::vtkPVFoam::convertVolField
// Face Zones
for (auto partId : rangeFaceZones_)
for
(
const auto partId
: rangeFaceZones_.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
const word zoneName = getFoamName(longName);
......@@ -199,6 +203,7 @@ void Foam::vtkPVFoam::convertVolField
// Should not happen, but for safety require a vtk geometry
continue;
}
foamVtpData& vtpData = iter.object();
auto dataset = vtpData.dataset;
......@@ -224,12 +229,12 @@ void Foam::vtkPVFoam::convertVolField
// Face Sets
for (auto partId : rangeFaceSets_)
for
(
const auto partId
: rangeFaceSets_.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
const word selectName = getFoamName(longName);
......@@ -349,12 +354,12 @@ void Foam::vtkPVFoam::convertVolFieldBlock
const arrayRange& range
)
{
for (auto partId : range)
for
(
const auto partId
: range.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
auto iter = cachedVtu_.find(longName);
......@@ -363,6 +368,7 @@ void Foam::vtkPVFoam::convertVolFieldBlock
// Should not happen, but for safety require a vtk geometry
continue;
}
foamVtuData& vtuData = iter.object();
auto dataset = vtuData.dataset;
......@@ -387,6 +393,65 @@ void Foam::vtkPVFoam::convertVolFieldBlock
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
// area-fields
//
template<class Type>
void Foam::vtkPVFoam::convertAreaFields
(
const faMesh& mesh,
const IOobjectList& objects
)
{
typedef GeometricField<Type, faPatchField, areaMesh> FieldType;
const List<label> partIds =
rangeArea_.intersection(selectedPartIds_);
if (partIds.empty())
{
return;
}
forAllConstIters(objects, iter)
{
// Restrict to GeometricField<Type, ...>
const auto& ioobj = *(iter.object());
if (ioobj.headerClassName() == FieldType::typeName)
{
// Load field
FieldType fld(ioobj, mesh);
// Convert
for (const auto partId : partIds)
{
const auto& longName = selectedPartIds_[partId];
auto iter = cachedVtp_.find(longName);
if (!iter.found() || !iter.object().dataset)
{
// Should not happen, but for safety require a vtk geometry
continue;
}
foamVtpData& vtpData = iter.object();
auto dataset = vtpData.dataset;
vtkSmartPointer<vtkFloatArray> cdata = convertFieldToVTK
(
fld.name(),
fld
);
dataset->GetCellData()->AddArray(cdata);
}
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
......@@ -416,7 +481,7 @@ void Foam::vtkPVFoam::convertPointFields
if (debug)
{
Info<< "convertPointFields : " << fieldName << endl;
Info<< "convertPointFields : " << fieldName << nl;
}
FieldType pfld(ioobj, pMesh);
......@@ -426,12 +491,12 @@ void Foam::vtkPVFoam::convertPointFields
convertPointFieldBlock(pfld, rangeCellSets_); // cellSets
// Patches - currently skip field conversion for groups
for (auto partId : rangePatches_)
for
(
const auto partId
: rangePatches_.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
auto iter = cachedVtp_.find(longName);
......@@ -440,6 +505,7 @@ void Foam::vtkPVFoam::convertPointFields
// Should not happen, but for safety require a vtk geometry
continue;
}
foamVtpData& vtpData = iter.object();
auto dataset = vtpData.dataset;
......@@ -461,12 +527,12 @@ void Foam::vtkPVFoam::convertPointFields
}
// Face Zones
for (auto partId : rangeFaceZones_)
for
(
const auto partId
: rangeFaceZones_.intersection(selectedPartIds_)
)
{
if (!selectedPartIds_.found(partId))
{
continue;
}
const auto& longName = selectedPartIds_[partId];
const word zoneName = getFoamName(longName);
......@@ -476,6 +542,7 @@ void Foam::vtkPVFoam::convertPointFields
// Should not happen, but for safety require a vtk geometry