ENH: additional vtk::Tools methods for handling faces, points etc.

- includes initial relocation of low-level vtu handling.
  Extracted, refactored from the Catalyst function object.
This commit is contained in:
Mark Olesen
2019-02-03 17:24:26 +01:00
committed by Andrew Heather
parent 966fc4c503
commit ff54ef8299
17 changed files with 731 additions and 620 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2005-2010, 2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -251,13 +251,11 @@ int Foam::vtkPVFoam::setTime(const std::vector<double>& requestTimes)
updateInfo(); updateInfo();
} }
if (debug) DebugInfo
{ << "<end> setTime() - selectedTime="
Info<< "<end> setTime() - selectedTime=" << Times[nearestIndex].name() << " index=" << timeIndex_
<< Times[nearestIndex].name() << " index=" << timeIndex_ << "/" << Times.size()
<< "/" << Times.size() << " meshUpdateState=" << updateStateName(meshState_) << nl;
<< " meshUpdateState=" << updateStateName(meshState_) << nl;
}
return nearestIndex; return nearestIndex;
} }
@ -376,13 +374,11 @@ Foam::vtkPVFoam::vtkPVFoam
} }
} }
if (debug) DebugInfo
{ << "fullCasePath=" << fullCasePath << nl
Info<< "fullCasePath=" << fullCasePath << nl << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl << "region=" << meshRegion_ << nl;
<< "region=" << meshRegion_ << nl;
}
// Create time object // Create time object
dbPtr_.reset dbPtr_.reset
@ -405,10 +401,7 @@ Foam::vtkPVFoam::vtkPVFoam
Foam::vtkPVFoam::~vtkPVFoam() Foam::vtkPVFoam::~vtkPVFoam()
{ {
if (debug) DebugInfo << "~vtkPVFoam" << nl;
{
Info<< "~vtkPVFoam" << nl;
}
delete volMeshPtr_; delete volMeshPtr_;
delete areaMeshPtr_; delete areaMeshPtr_;
@ -419,13 +412,11 @@ Foam::vtkPVFoam::~vtkPVFoam()
void Foam::vtkPVFoam::updateInfo() void Foam::vtkPVFoam::updateInfo()
{ {
if (debug) DebugInfo
{ << "<beg> updateInfo"
Info<< "<beg> updateInfo" << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "nullptr")
<< " [volMeshPtr=" << (volMeshPtr_ ? "set" : "nullptr") << "] timeIndex="
<< "] timeIndex=" << timeIndex_ << nl;
<< timeIndex_ << nl;
}
resetCounters(); resetCounters();
@ -475,10 +466,7 @@ void Foam::vtkPVFoam::updateInfo()
// Lagrangian fields - includes save/restore of selected // Lagrangian fields - includes save/restore of selected
updateInfoLagrangianFields(reader_->GetLagrangianFieldSelection()); updateInfoLagrangianFields(reader_->GetLagrangianFieldSelection());
if (debug) DebugInfo << "<end> updateInfo" << nl;
{
Info<< "<end> updateInfo" << nl;
}
} }
@ -584,11 +572,9 @@ void Foam::vtkPVFoam::Update
// Check to see if the OpenFOAM mesh has been created // Check to see if the OpenFOAM mesh has been created
if (!volMeshPtr_) if (!volMeshPtr_)
{ {
if (debug) DebugInfo
{ << "Creating OpenFOAM mesh for region " << meshRegion_
Info<< "Creating OpenFOAM mesh for region " << meshRegion_ << " at time=" << dbPtr_().timeName() << nl;
<< " at time=" << dbPtr_().timeName() << nl;
}
volMeshPtr_ = new fvMesh volMeshPtr_ = new fvMesh
( (
@ -605,10 +591,7 @@ void Foam::vtkPVFoam::Update
} }
else else
{ {
if (debug) DebugInfo << "Using existing OpenFOAM mesh" << nl;
{
Info<< "Using existing OpenFOAM mesh" << nl;
}
} }
if (rangeArea_.intersects(selectedPartIds_)) if (rangeArea_.intersects(selectedPartIds_))
@ -684,10 +667,7 @@ void Foam::vtkPVFoam::Update
rangeClouds_ rangeClouds_
); );
if (debug) DebugInfo << "done reader part" << nl << nl;
{
Info<< "done reader part" << nl << nl;
}
reader_->UpdateProgress(0.95); reader_->UpdateProgress(0.95);
meshState_ = polyMesh::UNCHANGED; meshState_ = polyMesh::UNCHANGED;
@ -902,19 +882,14 @@ void Foam::vtkPVFoam::renderPatchNames
displayZoneI += min(MAXPATCHZONES, nZones[patchi]); displayZoneI += min(MAXPATCHZONES, nZones[patchi]);
} }
if (debug) DebugInfo
{ << "displayed zone centres = " << displayZoneI << nl
Info<< "displayed zone centres = " << displayZoneI << nl << "zones per patch = " << nZones << nl;
<< "zones per patch = " << nZones << nl;
}
// Set the size of the patch labels to max number of zones // Set the size of the patch labels to max number of zones
patchTextActors_.setSize(displayZoneI); patchTextActors_.setSize(displayZoneI);
if (debug) DebugInfo << "constructing patch labels" << nl;
{
Info<< "constructing patch labels" << nl;
}
// Actor index // Actor index
displayZoneI = 0; displayZoneI = 0;
@ -934,12 +909,10 @@ void Foam::vtkPVFoam::renderPatchNames
label globalZoneI = 0; label globalZoneI = 0;
for (label i = 0; i < nDisplayZones; ++i, globalZoneI += increment) for (label i = 0; i < nDisplayZones; ++i, globalZoneI += increment)
{ {
if (debug) DebugInfo
{ << "patch name = " << pp.name() << nl
Info<< "patch name = " << pp.name() << nl << "anchor = " << zoneCentre[patchi][globalZoneI] << nl
<< "anchor = " << zoneCentre[patchi][globalZoneI] << nl << "globalZoneI = " << globalZoneI << nl;
<< "globalZoneI = " << globalZoneI << nl;
}
// Into a list for later removal // Into a list for later removal
patchTextActors_[displayZoneI++] = createTextActor patchTextActors_[displayZoneI++] = createTextActor

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\ / A nd | Copyright (C) 2005-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -74,13 +74,7 @@ SourceFiles
#include "PrimitivePatchInterpolation.H" #include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
#include "foamPvCore.H" #include "foamPvCore.H"
#include "foamVtkTools.H" #include "foamVtkVtuAdaptor.H"
#include "foamVtkMeshMaps.H"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
@ -89,7 +83,6 @@ class vtkDataArraySelection;
class vtkDataSet; class vtkDataSet;
class vtkFloatArray; class vtkFloatArray;
class vtkIndent; class vtkIndent;
class vtkMultiBlockDataSet;
class vtkPVFoamReader; class vtkPVFoamReader;
class vtkRenderer; class vtkRenderer;
class vtkTextActor; class vtkTextActor;
@ -99,7 +92,7 @@ class vtkTextActor;
namespace Foam namespace Foam
{ {
// OpenFOAM class forward declarations // Forward declarations (OpenFOAM)
class argList; class argList;
class Time; class Time;
class faMesh; class faMesh;
@ -133,35 +126,13 @@ class vtkPVFoam
//- Bookkeeping for vtkUnstructuredGrid //- Bookkeeping for vtkUnstructuredGrid
struct foamVtuData struct foamVtuData
: :
public vtk::Caching<vtkUnstructuredGrid>, public vtk::vtuAdaptor
public foamVtkMeshMaps
{ {
//- The vtk points for the mesh (and decomposition)
vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh
) const;
//- The vtk points for the mesh (and decomposition),
//- using the provided pointMap
vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh,
const labelUList& pointMap
) const;
//- Internal mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> internal
(
const fvMesh& mesh,
const bool decompPoly
);
//- Subsetted mesh as vtkUnstructuredGrid //- Subsetted mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> subset vtkSmartPointer<vtkUnstructuredGrid> subset
( (
const fvMeshSubset& subsetter, const fvMeshSubset& subsetter,
const bool decompPoly bool decompPoly = false
); );
}; };
@ -348,14 +319,6 @@ class vtkPVFoam
const labelUList& faceLabels const labelUList& faceLabels
) const; ) const;
//- Volume field
template<class Type>
vtkSmartPointer<vtkFloatArray> convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const;
//- Convert finite volume fields //- Convert finite volume fields
void convertVolFields(); void convertVolFields();

View File

@ -68,8 +68,7 @@ void Foam::vtkPVFoam::convertVolField
autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr; autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr;
if (interpField) if (interpField)
{ {
DebugInfo DebugInfo << "convertVolField interpolating:" << fld.name() << nl;
<< "convertVolField interpolating:" << fld.name() << nl;
ptfPtr.reset ptfPtr.reset
( (
@ -415,22 +414,17 @@ void Foam::vtkPVFoam::convertVolFieldBlock
foamVtuData& vtuData = iter.val(); foamVtuData& vtuData = iter.val();
auto dataset = vtuData.dataset; auto dataset = vtuData.dataset;
vtkSmartPointer<vtkFloatArray> cdata = convertVolFieldToVTK dataset->GetCellData()->AddArray
( (
fld, vtuData.convertField(fld)
vtuData
); );
dataset->GetCellData()->AddArray(cdata);
if (ptfPtr.valid()) if (ptfPtr.valid())
{ {
vtkSmartPointer<vtkFloatArray> pdata = convertPointField dataset->GetPointData()->AddArray
( (
ptfPtr(), convertPointField(*ptfPtr, fld, vtuData)
fld,
vtuData
); );
dataset->GetPointData()->AddArray(pdata);
} }
} }
} }
@ -547,8 +541,7 @@ void Foam::vtkPVFoam::convertPointFields
continue; continue;
} }
DebugInfo DebugInfo << "convertPointFields : " << fieldName << nl;
<< "convertPointFields : " << fieldName << nl;
// Throw FatalError, FatalIOError as exceptions // Throw FatalError, FatalIOError as exceptions
const bool throwingError = FatalError.throwExceptions(); const bool throwingError = FatalError.throwExceptions();
@ -899,40 +892,6 @@ Foam::vtkPVFoam::convertFaceFieldToVTK
} }
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtkPVFoam::convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const
{
const labelUList& cellMap = vtuData.cellMap();
auto data = vtkSmartPointer<vtkFloatArray>::New();
data->SetName(fld.name().c_str());
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
data->SetNumberOfTuples(cellMap.size());
DebugInfo
<< "Convert volField: " << fld.name() << " size="
<< cellMap.size() << " (field "
<< fld.size() << ") nComp="
<< static_cast<int>(pTraits<Type>::nComponents) << nl;
float scratch[pTraits<Type>::nComponents];
vtkIdType celli = 0;
for (const label meshCelli : cellMap)
{
vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]);
data->SetTuple(celli++, scratch);
}
return data;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2005-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -130,10 +130,7 @@ void Foam::vtkPVFoam::convertPointFields()
if (selectedFields.empty()) if (selectedFields.empty())
{ {
if (debug) DebugInfo << "no point fields selected" << nl;
{
Info<< "no point fields selected" << nl;
}
return; return;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2005-2010, 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -69,19 +69,13 @@ void Foam::vtkPVFoam::convertMeshVolume()
{ {
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
if (debug) DebugInfo << "reuse " << longName << nl;
{
Info<< "reuse " << longName << nl;
}
vtuData.reuse(); // reuse vtuData.reuse(); // reuse
continue; continue;
} }
else if (meshState_ == polyMesh::POINTS_MOVED) else if (meshState_ == polyMesh::POINTS_MOVED)
{ {
if (debug) DebugInfo << "move points " << longName << nl;
{
Info<< "move points " << longName << nl;
}
vtkgeom = vtuData.getCopy(); vtkgeom = vtuData.getCopy();
vtkgeom->SetPoints(vtuData.points(mesh)); vtkgeom->SetPoints(vtuData.points(mesh));
} }
@ -163,10 +157,7 @@ void Foam::vtkPVFoam::convertMeshPatches()
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
// Without movement is easy. // Without movement is easy.
if (debug) DebugInfo << "reuse " << longName << nl;
{
Info<< "reuse " << longName << nl;
}
vtpData.reuse(); vtpData.reuse();
continue; continue;
} }
@ -196,11 +187,9 @@ void Foam::vtkPVFoam::convertMeshPatches()
const labelList& patchIds = const labelList& patchIds =
patches.groupPatchIDs().lookup(partName, labelList()); patches.groupPatchIDs().lookup(partName, labelList());
if (debug) DebugInfo
{ << "Creating VTK mesh for patches [" << patchIds <<"] "
Info<< "Creating VTK mesh for patches [" << patchIds <<"] " << longName << nl;
<< longName << nl;
}
// Store good patch ids as additionalIds // Store good patch ids as additionalIds
vtpData.additionalIds().reserve(patchIds.size()); vtpData.additionalIds().reserve(patchIds.size());
@ -250,11 +239,9 @@ void Foam::vtkPVFoam::convertMeshPatches()
const label patchId = patches.findPatchID(partName); const label patchId = patches.findPatchID(partName);
if (debug) DebugInfo
{ << "Creating VTK mesh for patch [" << patchId <<"] "
Info<< "Creating VTK mesh for patch [" << patchId <<"] " << partName << nl;
<< partName << nl;
}
if (patchId >= 0) if (patchId >= 0)
{ {
@ -324,19 +311,13 @@ void Foam::vtkPVFoam::convertMeshArea()
// { // {
// if (meshState_ == polyMesh::UNCHANGED) // if (meshState_ == polyMesh::UNCHANGED)
// { // {
// if (debug) // DebugInfo << "reuse " << longName << nl;
// {
// Info<< "reuse " << longName << nl;
// }
// vtpData.reuse(); // reuse // vtpData.reuse(); // reuse
// continue; // continue;
// } // }
// else if (meshState_ == polyMesh::POINTS_MOVED) // else if (meshState_ == polyMesh::POINTS_MOVED)
// { // {
// if (debug) // DebugInfo << "move points " << longName << nl;
// {
// Info<< "move points " << longName << nl;
// }
// vtkgeom = vtpData.getCopy(); // vtkgeom = vtpData.getCopy();
// vtkgeom->SetPoints(movePoints(mesh, vtpData)); // vtkgeom->SetPoints(movePoints(mesh, vtpData));
// } // }
@ -392,11 +373,9 @@ void Foam::vtkPVFoam::convertMeshCellZones()
continue; continue;
} }
if (debug) DebugInfo
{ << "Creating VTK mesh for cellZone[" << zoneId << "] "
Info<< "Creating VTK mesh for cellZone[" << zoneId << "] " << zoneName << nl;
<< zoneName << nl;
}
foamVtuData& vtuData = cachedVtu_(longName); foamVtuData& vtuData = cachedVtu_(longName);
@ -405,19 +384,13 @@ void Foam::vtkPVFoam::convertMeshCellZones()
{ {
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
if (debug) DebugInfo << "reuse " << longName << nl;
{
Info<< "reuse " << longName << nl;
}
vtuData.reuse(); vtuData.reuse();
continue; continue;
} }
else if (meshState_ == polyMesh::POINTS_MOVED) else if (meshState_ == polyMesh::POINTS_MOVED)
{ {
if (debug) DebugInfo << "move points " << longName << nl;
{
Info<< "move points " << longName << nl;
}
vtkgeom = vtuData.getCopy(); vtkgeom = vtuData.getCopy();
vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap()));
} }
@ -459,10 +432,7 @@ void Foam::vtkPVFoam::convertMeshCellSets()
const auto& longName = selectedPartIds_[partId]; const auto& longName = selectedPartIds_[partId];
const word partName = getFoamName(longName); const word partName = getFoamName(longName);
if (debug) DebugInfo << "Creating VTK mesh for cellSet=" << partName << nl;
{
Info<< "Creating VTK mesh for cellSet=" << partName << nl;
}
foamVtuData& vtuData = cachedVtu_(longName); foamVtuData& vtuData = cachedVtu_(longName);
@ -471,19 +441,13 @@ void Foam::vtkPVFoam::convertMeshCellSets()
{ {
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
if (debug) DebugInfo << "reuse " << longName << nl;
{
Info<< "reuse " << longName << nl;
}
vtuData.reuse(); vtuData.reuse();
continue; continue;
} }
else if (meshState_ == polyMesh::POINTS_MOVED) else if (meshState_ == polyMesh::POINTS_MOVED)
{ {
if (debug) DebugInfo << "move points " << longName << nl;
{
Info<< "move points " << longName << nl;
}
vtkgeom = vtuData.getCopy(); vtkgeom = vtuData.getCopy();
vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap()));
} }
@ -536,11 +500,9 @@ void Foam::vtkPVFoam::convertMeshFaceZones()
{ {
continue; continue;
} }
if (debug) DebugInfo
{ << "Creating VTKmesh for faceZone[" << zoneId << "] "
Info<< "Creating VTKmesh for faceZone[" << zoneId << "] " << zoneName << nl;
<< zoneName << nl;
}
foamVtpData& vtpData = cachedVtp_(longName); foamVtpData& vtpData = cachedVtp_(longName);
@ -550,10 +512,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones()
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
// Without movement is easy. // Without movement is easy.
if (debug) DebugInfo <<"reuse " << longName << nl;
{
Info<<"reuse " << longName << nl;
}
vtpData.reuse(); vtpData.reuse();
continue; continue;
} }
@ -600,10 +559,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets()
const auto& longName = selectedPartIds_[partId]; const auto& longName = selectedPartIds_[partId];
const word partName = getFoamName(longName); const word partName = getFoamName(longName);
if (debug) DebugInfo << "Creating VTK mesh for faceSet=" << partName << nl;
{
Info<< "Creating VTK mesh for faceSet=" << partName << nl;
}
foamVtpData& vtpData = cachedVtp_(longName); foamVtpData& vtpData = cachedVtp_(longName);
@ -613,10 +569,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets()
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
// Without movement is easy. // Without movement is easy.
if (debug) DebugInfo <<"reuse " << longName << nl;
{
Info<<"reuse " << longName << nl;
}
vtpData.reuse(); vtpData.reuse();
continue; continue;
} }
@ -700,19 +653,13 @@ void Foam::vtkPVFoam::convertMeshPointZones()
{ {
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
if (debug) DebugInfo << "reusing " << longName << nl;
{
Info<< "reusing " << longName << nl;
}
vtpData.reuse(); vtpData.reuse();
continue; continue;
} }
else if (meshState_ == polyMesh::POINTS_MOVED) else if (meshState_ == polyMesh::POINTS_MOVED)
{ {
if (debug) DebugInfo << "move points " << longName << nl;
{
Info<< "move points " << longName << nl;
}
vtkgeom = vtpData.getCopy(); vtkgeom = vtpData.getCopy();
} }
} }
@ -772,19 +719,13 @@ void Foam::vtkPVFoam::convertMeshPointSets()
{ {
if (meshState_ == polyMesh::UNCHANGED) if (meshState_ == polyMesh::UNCHANGED)
{ {
if (debug) DebugInfo << "reusing " << longName << nl;
{
Info<< "reusing " << longName << nl;
}
vtpData.reuse(); vtpData.reuse();
continue; continue;
} }
else if (meshState_ == polyMesh::POINTS_MOVED) else if (meshState_ == polyMesh::POINTS_MOVED)
{ {
if (debug) DebugInfo << "move points " << longName << nl;
{
Info<< "move points " << longName << nl;
}
vtkgeom = vtpData.getCopy(); vtkgeom = vtpData.getCopy();
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2008-2011, 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -73,10 +73,7 @@ vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::lagrangianVTKMesh
{ {
Cloud<passiveParticle> parcels(mesh, cloudName, false); Cloud<passiveParticle> parcels(mesh, cloudName, false);
if (debug) DebugInfo << "cloud with " << parcels.size() << " parcels" << nl;
{
Info<< "cloud with " << parcels.size() << " parcels" << nl;
}
auto vtkpoints = vtkSmartPointer<vtkPoints>::New(); auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(parcels.size()); vtkpoints->SetNumberOfPoints(parcels.size());

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,198 +24,23 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "vtkPVFoam.H" #include "vtkPVFoam.H"
#include "vtkPVFoamReader.h"
// OpenFOAM includes
#include "fvMesh.H"
#include "fvMeshSubset.H" #include "fvMeshSubset.H"
#include "foamVtkTools.H"
#include "foamVtuSizing.H"
// VTK includes
#include <vtkUnstructuredGrid.h>
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
(
const fvMesh& mesh
) const
{
// Convert OpenFOAM mesh vertices to VTK
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
// Normal points
const pointField& pts = mesh.points();
// Additional cell centres
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
// Normal points
vtkIdType pointId = 0;
for (const point& p : pts)
{
vtkpoints->SetPoint(pointId++, p.v_);
}
// Cell centres
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
}
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
(
const fvMesh& mesh,
const labelUList& pointMap
) const
{
// Convert OpenFOAM mesh vertices to VTK
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
// Normal points
const pointField& pts = mesh.points();
// Additional cell centres
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
// Normal points
vtkIdType pointId = 0;
for (const label meshPointi : pointMap)
{
vtkpoints->SetPoint(pointId++, pts[meshPointi].v_);
}
// Cell centres
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
}
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::foamVtuData::internal
(
const fvMesh& mesh,
const bool decompPoly
)
{
vtk::vtuSizing sizing(mesh, decompPoly);
auto cellTypes = vtkSmartPointer<vtkUnsignedCharArray>::New();
auto cells = vtkSmartPointer<vtkCellArray>::New();
auto faces = vtkSmartPointer<vtkIdTypeArray>::New();
auto cellLocations = vtkSmartPointer<vtkIdTypeArray>::New();
auto faceLocations = vtkSmartPointer<vtkIdTypeArray>::New();
UList<uint8_t> cellTypesUL =
vtk::Tools::asUList
(
cellTypes,
sizing.nFieldCells()
);
UList<vtkIdType> cellsUL =
vtk::Tools::asUList
(
cells,
sizing.nFieldCells(),
sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS)
);
UList<vtkIdType> cellLocationsUL =
vtk::Tools::asUList
(
cellLocations,
sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS)
);
UList<vtkIdType> facesUL =
vtk::Tools::asUList
(
faces,
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES)
);
UList<vtkIdType> faceLocationsUL =
vtk::Tools::asUList
(
faceLocations,
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS)
);
sizing.populateInternal
(
mesh,
cellTypesUL,
cellsUL,
cellLocationsUL,
facesUL,
faceLocationsUL,
static_cast<foamVtkMeshMaps&>(*this)
);
auto vtkmesh = vtkSmartPointer<vtkUnstructuredGrid>::New();
// Convert OpenFOAM mesh vertices to VTK
// - can only do this *after* populating the decompInfo with cell-ids
// for any additional points (ie, mesh cell-centres)
vtkmesh->SetPoints(this->points(mesh));
if (facesUL.size())
{
vtkmesh->SetCells
(
cellTypes,
cellLocations,
cells,
faceLocations,
faces
);
}
else
{
vtkmesh->SetCells
(
cellTypes,
cellLocations,
cells,
nullptr,
nullptr
);
}
return vtkmesh;
}
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::foamVtuData::subset vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::foamVtuData::subset
( (
const fvMeshSubset& subsetter, const fvMeshSubset& subsetter,
const bool decompPoly bool decompPoly
) )
{ {
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh = auto vtkmesh = internal(subsetter.subMesh(), decompPoly);
this->internal(subsetter.subMesh(), decompPoly);
// Convert cellMap, addPointCellLabels to global cell ids // Convert cellMap, addPointCellLabels to global cell ids
this->renumberCells(subsetter.cellMap()); renumberCells(subsetter.cellMap());
// Copy pointMap as well, otherwise pointFields fail // Copy pointMap as well, otherwise pointFields fail
this->pointMap() = subsetter.pointMap(); pointMap() = subsetter.pointMap();
return vtkmesh; return vtkmesh;
} }

View File

@ -148,20 +148,14 @@ void Foam::vtkPVFoam::updateInfoInternalMesh
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
// Determine mesh parts (internalMesh, patches...) // Determine mesh parts (internalMesh, patches...)
// Add internal mesh as first entry // Add internal mesh as first entry
rangeVolume_.reset(select->GetNumberOfArrays(), 1); rangeVolume_.reset(select->GetNumberOfArrays(), 1);
select->AddArray("internalMesh"); select->AddArray("internalMesh");
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -170,10 +164,7 @@ void Foam::vtkPVFoam::updateInfoAreaMesh
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
rangeArea_.reset(select->GetNumberOfArrays(), 0); rangeArea_.reset(select->GetNumberOfArrays(), 0);
@ -198,10 +189,7 @@ void Foam::vtkPVFoam::updateInfoAreaMesh
select->AddArray("areaMesh"); select->AddArray("areaMesh");
} }
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -210,11 +198,9 @@ void Foam::vtkPVFoam::updateInfoLagrangian
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo
{ << "<beg> " << FUNCTION_NAME << nl
Info<< "<beg> " << FUNCTION_NAME << nl << " " << dbPtr_->timePath()/cloud::prefix << nl;
<< " " << dbPtr_->timePath()/cloud::prefix << nl;
}
// Use the db directly since this might be called without a mesh, // Use the db directly since this might be called without a mesh,
// but the region must get added back in // but the region must get added back in
@ -245,10 +231,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian
rangeClouds_.reset(select->GetNumberOfArrays()); rangeClouds_.reset(select->GetNumberOfArrays());
rangeClouds_ += addToArray(select, "lagrangian/", names.sortedToc()); rangeClouds_ += addToArray(select, "lagrangian/", names.sortedToc());
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -258,11 +241,9 @@ void Foam::vtkPVFoam::updateInfoPatches
HashSet<string>& enabledEntries HashSet<string>& enabledEntries
) )
{ {
if (debug) DebugInfo
{ << "<beg> " << FUNCTION_NAME
Info<< "<beg> " << FUNCTION_NAME << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl;
<< " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl;
}
rangePatches_.reset(select->GetNumberOfArrays()); rangePatches_.reset(select->GetNumberOfArrays());
@ -436,10 +417,7 @@ void Foam::vtkPVFoam::updateInfoPatches
} }
} }
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -453,11 +431,9 @@ void Foam::vtkPVFoam::updateInfoZones
return; return;
} }
if (debug) DebugInfo
{ << "<beg> " << FUNCTION_NAME
Info<< "<beg> " << FUNCTION_NAME << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl;
<< " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl;
}
// cellZones // cellZones
{ {
@ -498,10 +474,7 @@ void Foam::vtkPVFoam::updateInfoZones
rangePointZones_ += addToArray(select, "pointZone/", names); rangePointZones_ += addToArray(select, "pointZone/", names);
} }
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -515,10 +488,7 @@ void Foam::vtkPVFoam::updateInfoSets
return; return;
} }
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
// Add names of sets. Search for last time directory with a sets // Add names of sets. Search for last time directory with a sets
// subdirectory. Take care not to search beyond the last mesh. // subdirectory. Take care not to search beyond the last mesh.
@ -540,11 +510,9 @@ void Foam::vtkPVFoam::updateInfoSets
const IOobjectList objects(dbPtr_(), setsInstance, meshDir_/"sets"); const IOobjectList objects(dbPtr_(), setsInstance, meshDir_/"sets");
if (debug) DebugInfo
{ << " updateInfoSets read "
Info<< " updateInfoSets read " << objects.names() << " from " << setsInstance << nl;
<< objects.names() << " from " << setsInstance << nl;
}
rangeCellSets_.reset(select->GetNumberOfArrays()); rangeCellSets_.reset(select->GetNumberOfArrays());
@ -571,10 +539,7 @@ void Foam::vtkPVFoam::updateInfoSets
objects objects
); );
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -583,10 +548,7 @@ void Foam::vtkPVFoam::updateInfoContinuumFields
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
// Preserve the enabled selections // Preserve the enabled selections
HashSet<string> enabled; HashSet<string> enabled;
@ -618,10 +580,7 @@ void Foam::vtkPVFoam::updateInfoContinuumFields
setSelectedArrayEntries(select, enabled); // Adjust/restore selected setSelectedArrayEntries(select, enabled); // Adjust/restore selected
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -630,10 +589,7 @@ void Foam::vtkPVFoam::updateInfoPointFields
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
// Preserve the enabled selections // Preserve the enabled selections
HashSet<string> enabled = getSelectedArraySet(select); HashSet<string> enabled = getSelectedArraySet(select);
@ -655,10 +611,7 @@ void Foam::vtkPVFoam::updateInfoPointFields
setSelectedArrayEntries(select, enabled); // Adjust/restore selected setSelectedArrayEntries(select, enabled); // Adjust/restore selected
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }
@ -667,10 +620,7 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << nl;
{
Info<< "<beg> " << FUNCTION_NAME << nl;
}
// Preserve the enabled selections // Preserve the enabled selections
HashSet<string> enabled = getSelectedArraySet(select); HashSet<string> enabled = getSelectedArraySet(select);
@ -733,10 +683,7 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields
// Restore the enabled selections // Restore the enabled selections
setSelectedArrayEntries(select, enabled); setSelectedArrayEntries(select, enabled);
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << nl;
{
Info<< "<end> " << FUNCTION_NAME << nl;
}
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -40,13 +40,11 @@ void Foam::vtkPVFoam::updateInfoFields
const IOobjectList& objects const IOobjectList& objects
) )
{ {
if (debug) DebugInfo
{ << "<beg> updateInfoFields <"
Info<< "<beg> updateInfoFields <" << meshType::Mesh::typeName
<< meshType::Mesh::typeName << "> [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]"
<< "> [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl;
<< nl;
}
// Add geometric fields (volume/area) to GUI // Add geometric fields (volume/area) to GUI
addToSelection<GeometricField<scalar, patchType, meshType>> addToSelection<GeometricField<scalar, patchType, meshType>>
@ -102,10 +100,7 @@ void Foam::vtkPVFoam::updateInfoFields
objects objects
); );
if (debug) DebugInfo << "<end> updateInfoFields" << nl;
{
Info<< "<end> updateInfoFields" << nl;
}
} }

View File

@ -101,11 +101,9 @@ void Foam::vtkPVblockMesh::updateInfoBlocks
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo
{ << "<beg> updateInfoBlocks"
Info<< "<beg> updateInfoBlocks" << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl;
<< " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl;
}
rangeBlocks_.reset(select->GetNumberOfArrays()); rangeBlocks_.reset(select->GetNumberOfArrays());
@ -132,10 +130,7 @@ void Foam::vtkPVblockMesh::updateInfoBlocks
++rangeBlocks_; ++rangeBlocks_;
} }
if (debug) DebugInfo << "<end> updateInfoBlocks" << endl;
{
Info<< "<end> updateInfoBlocks" << endl;
}
} }
@ -144,11 +139,9 @@ void Foam::vtkPVblockMesh::updateInfoEdges
vtkDataArraySelection* select vtkDataArraySelection* select
) )
{ {
if (debug) DebugInfo
{ << "<beg> updateInfoEdges"
Info<< "<beg> updateInfoEdges" << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl;
<< " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl;
}
rangeEdges_.reset(select->GetNumberOfArrays()); rangeEdges_.reset(select->GetNumberOfArrays());
@ -168,10 +161,7 @@ void Foam::vtkPVblockMesh::updateInfoEdges
++rangeEdges_; ++rangeEdges_;
} }
if (debug) DebugInfo << "<end> updateInfoEdges" << endl;
{
Info<< "<end> updateInfoEdges" << endl;
}
} }
@ -192,10 +182,7 @@ Foam::vtkPVblockMesh::vtkPVblockMesh
rangeEdges_("edges"), rangeEdges_("edges"),
rangeCorners_("corners") rangeCorners_("corners")
{ {
if (debug) DebugInfo << "vtkPVblockMesh - " << FileName << endl;
{
Info<< "vtkPVblockMesh - " << FileName << endl;
}
// avoid argList and get rootPath/caseName directly from the file // avoid argList and get rootPath/caseName directly from the file
fileName fullCasePath(fileName(FileName).path()); fileName fullCasePath(fileName(FileName).path());
@ -256,12 +243,10 @@ Foam::vtkPVblockMesh::vtkPVblockMesh
} }
} }
if (debug) DebugInfo
{ << "fullCasePath=" << fullCasePath << nl
Info<< "fullCasePath=" << fullCasePath << nl << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl;
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl;
}
// Create time object // Create time object
dbPtr_.reset dbPtr_.reset
@ -284,10 +269,7 @@ Foam::vtkPVblockMesh::vtkPVblockMesh
Foam::vtkPVblockMesh::~vtkPVblockMesh() Foam::vtkPVblockMesh::~vtkPVblockMesh()
{ {
if (debug) DebugInfo << "~vtkPVblockMesh" << endl;
{
Info<< "~vtkPVblockMesh" << endl;
}
delete meshPtr_; delete meshPtr_;
} }
@ -297,11 +279,9 @@ Foam::vtkPVblockMesh::~vtkPVblockMesh()
void Foam::vtkPVblockMesh::updateInfo() void Foam::vtkPVblockMesh::updateInfo()
{ {
if (debug) DebugInfo
{ << "<beg> updateInfo"
Info<< "<beg> updateInfo" << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "] " << endl;
<< " [meshPtr=" << (meshPtr_ ? "set" : "null") << "] " << endl;
}
resetCounters(); resetCounters();
@ -339,19 +319,13 @@ void Foam::vtkPVblockMesh::updateInfo()
setSelectedArrayEntries(edgeSelection, enabledEdges); setSelectedArrayEntries(edgeSelection, enabledEdges);
} }
if (debug) DebugInfo << "<end> updateInfo" << endl;
{
Info<< "<end> updateInfo" << endl;
}
} }
void Foam::vtkPVblockMesh::updateFoamMesh() void Foam::vtkPVblockMesh::updateFoamMesh()
{ {
if (debug) DebugInfo << "<beg> updateFoamMesh" << endl;
{
Info<< "<beg> updateFoamMesh" << endl;
}
// Check to see if the OpenFOAM mesh has been created // Check to see if the OpenFOAM mesh has been created
if (!meshPtr_) if (!meshPtr_)
@ -398,10 +372,7 @@ void Foam::vtkPVblockMesh::updateFoamMesh()
} }
if (debug) DebugInfo << "<end> updateFoamMesh" << endl;
{
Info<< "<end> updateFoamMesh" << endl;
}
} }

View File

@ -51,10 +51,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
int& blockNo int& blockNo
) )
{ {
if (debug) DebugInfo << "<beg> convertMeshBlocks" << endl;
{
Info<< "<beg> convertMeshBlocks" << endl;
}
const Map<string> blockStatus = getSelectedArrayMap const Map<string> blockStatus = getSelectedArrayMap
( (
@ -118,10 +115,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
++blockNo; ++blockNo;
} }
if (debug) DebugInfo << "<end> convertMeshBlocks" << endl;
{
Info<< "<end> convertMeshBlocks" << endl;
}
} }
@ -220,11 +214,7 @@ void Foam::vtkPVblockMesh::convertMeshEdges
++blockNo; ++blockNo;
} }
if (debug) DebugInfo << "<end> convertMeshEdges" << endl;
{
Info<< "<end> convertMeshEdges" << endl;
}
} }
@ -240,10 +230,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners
const pointField blkPoints(meshPtr_->vertices() * meshPtr_->scaleFactor()); const pointField blkPoints(meshPtr_->vertices() * meshPtr_->scaleFactor());
if (debug) DebugInfo << "<beg> " << FUNCTION_NAME << endl;
{
Info<< "<beg> " << FUNCTION_NAME << endl;
}
if (true) // Or some flag or other condition if (true) // Or some flag or other condition
{ {
@ -270,10 +257,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners
++blockNo; ++blockNo;
} }
if (debug) DebugInfo << "<end> " << FUNCTION_NAME << endl;
{
Info<< "<end> " << FUNCTION_NAME << endl;
}
} }

View File

@ -48,6 +48,7 @@ SourceFiles
#include "faceList.H" #include "faceList.H"
#include "pointField.H" #include "pointField.H"
#include "symmTensor.H" #include "symmTensor.H"
#include "MinMax.H"
// VTK includes // VTK includes
#include "vtkCellArray.h" #include "vtkCellArray.h"
@ -63,7 +64,7 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward declarations // Forward Declarations
class vtkDataSet; class vtkDataSet;
class vtkCellData; class vtkCellData;
class vtkPointData; class vtkPointData;
@ -192,6 +193,27 @@ namespace Tools
); );
//- Return a list of points as vtkPoints
inline vtkSmartPointer<vtkPoints> Points
(
const UList<point>& pts
);
//- Return an indirect list of points as vtkPoints
inline vtkSmartPointer<vtkPoints> Points
(
const UList<point>& pts,
const labelUList& addr
);
//- Convert a list of faces (or triFaces) to vtk polygon cells
template<class Face>
vtkSmartPointer<vtkCellArray> Faces(const UList<Face>& faces);
//- Min/Max of scalar, or mag() of non-scalars. Includes nullptr check.
inline scalarMinMax rangeOf(vtkDataArray* data);
//- Convert OpenFOAM patch to vtkPolyData //- Convert OpenFOAM patch to vtkPolyData
struct Patch struct Patch
{ {
@ -214,6 +236,14 @@ namespace Tools
//- Return patch face centres as vtkPoints //- Return patch face centres as vtkPoints
template<class PatchType> template<class PatchType>
static vtkSmartPointer<vtkPoints> faceCentres(const PatchType& p); static vtkSmartPointer<vtkPoints> faceCentres(const PatchType& p);
//- Convert points/faces component to vtkPolyData
template<class Face>
static vtkSmartPointer<vtkPolyData> mesh
(
const UList<point>& pts,
const UList<Face>& fcs
);
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -64,6 +64,61 @@ inline Foam::UList<vtkIdType> Foam::vtk::Tools::asUList
} }
inline vtkSmartPointer<vtkPoints>
Foam::vtk::Tools::Points(const UList<point>& pts)
{
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(pts.size());
vtkIdType pointId = 0;
for (const point& pt : pts)
{
vtkpoints->SetPoint(pointId++, pt.v_);
}
return vtkpoints;
}
inline vtkSmartPointer<vtkPoints>
Foam::vtk::Tools::Points(const UList<point>& pts, const labelUList& addr)
{
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(addr.size());
vtkIdType pointId = 0;
for (const label pointi : addr)
{
vtkpoints->SetPoint(pointId++, pts[pointi].v_);
}
return vtkpoints;
}
inline Foam::scalarMinMax Foam::vtk::Tools::rangeOf(vtkDataArray* data)
{
double range[2]{GREAT, -GREAT};
if (data)
{
if (data->GetNumberOfComponents() == 1)
{
data->GetRange(range);
}
else
{
// Mag
data->GetRange(range, -1);
}
}
return scalarMinMax(range[0], range[1]);
}
inline vtkSmartPointer<vtkCellArray> Foam::vtk::Tools::identityVertices inline vtkSmartPointer<vtkCellArray> Foam::vtk::Tools::identityVertices
( (
const label size const label size

View File

@ -37,48 +37,24 @@ InNamespace
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class PatchType> template<class Face>
vtkSmartPointer<vtkPoints>
Foam::vtk::Tools::Patch::points(const PatchType& p)
{
// Local patch points to vtkPoints
const pointField& pts = p.localPoints();
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(pts.size());
vtkIdType pointId = 0;
for (const point& pt : pts)
{
vtkpoints->SetPoint(pointId++, pt.v_);
}
return vtkpoints;
}
template<class PatchType>
vtkSmartPointer<vtkCellArray> vtkSmartPointer<vtkCellArray>
Foam::vtk::Tools::Patch::faces(const PatchType& p) Foam::vtk::Tools::Faces(const UList<Face>& faces)
{ {
// List of faces or triFaces label nAlloc = faces.size();
const auto& fcs = p.localFaces(); for (const auto& f : faces)
label nAlloc = fcs.size();
for (const auto& f : fcs)
{ {
nAlloc += f.size(); nAlloc += f.size();
} }
auto vtkcells = vtkSmartPointer<vtkCellArray>::New(); auto vtkcells = vtkSmartPointer<vtkCellArray>::New();
UList<vtkIdType> list = asUList(vtkcells, fcs.size(), nAlloc); UList<vtkIdType> list = asUList(vtkcells, faces.size(), nAlloc);
// Cell connectivity for polygons // Cell connectivity for polygons
// [size, verts..., size, verts... ] // [size, verts..., size, verts... ]
auto iter = list.begin(); auto iter = list.begin();
for (const auto& f : fcs) for (const auto& f : faces)
{ {
*(iter++) = f.size(); *(iter++) = f.size();
@ -92,6 +68,23 @@ Foam::vtk::Tools::Patch::faces(const PatchType& p)
} }
template<class PatchType>
vtkSmartPointer<vtkPoints>
Foam::vtk::Tools::Patch::points(const PatchType& p)
{
// Local patch points to vtkPoints
return Tools::Points(p.localPoints());
}
template<class PatchType>
vtkSmartPointer<vtkCellArray>
Foam::vtk::Tools::Patch::faces(const PatchType& p)
{
return Tools::Faces(p.localFaces());
}
template<class PatchType> template<class PatchType>
vtkSmartPointer<vtkPolyData> vtkSmartPointer<vtkPolyData>
Foam::vtk::Tools::Patch::mesh(const PatchType& p) Foam::vtk::Tools::Patch::mesh(const PatchType& p)
@ -105,6 +98,23 @@ Foam::vtk::Tools::Patch::mesh(const PatchType& p)
} }
template<class Face>
vtkSmartPointer<vtkPolyData>
Foam::vtk::Tools::Patch::mesh
(
const UList<point>& pts,
const UList<Face>& fcs
)
{
auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
vtkmesh->SetPoints(Tools::Points(pts));
vtkmesh->SetPolys(Tools::Faces(fcs));
return vtkmesh;
}
template<class PatchType> template<class PatchType>
vtkSmartPointer<vtkFloatArray> vtkSmartPointer<vtkFloatArray>
Foam::vtk::Tools::Patch::faceNormals(const PatchType& p) Foam::vtk::Tools::Patch::faceNormals(const PatchType& p)

View File

@ -0,0 +1,167 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2019 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::vtk::vtuAdaptor
Description
A low-level backend adaptor for converting OpenFOAM volume meshes/fields
to VTK internal representation.
The output is a single piece vtkUnstructuredGrid dataset.
Multiblock composition is done by the caller.
Note
This was originally part of the catalystFvMesh function object backend,
which was prototyped in the ParaView reader module.
This adaptor unifies many common elements of both.
SourceFiles
foamVtkVtuAdaptorI.H
foamVtkVtuAdaptorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef foamVtk_vtuAdaptor_H
#define foamVtk_vtuAdaptor_H
#include "fvMesh.H"
#include "volFieldsFwd.H"
#include "foamVtkTools.H"
#include "foamVtkMeshMaps.H"
#include "foamVtuSizing.H"
#include "vtkSmartPointer.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkMultiBlockDataSet.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkCellArray;
class vtkDataSet;
class vtkFloatArray;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace vtk
{
/*---------------------------------------------------------------------------*\
Class vtk::vtuAdaptor Declaration
\*---------------------------------------------------------------------------*/
//- Bookkeeping for vtkUnstructuredGrid
struct vtuAdaptor
:
public vtk::Caching<vtkUnstructuredGrid>,
public foamVtkMeshMaps
{
// Member Functions
// Mesh Conversion
//- The vtk points for the mesh (and decomposition)
inline vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh
) const;
//- The vtk points for the mesh (and decomposition)
//- using the provided pointMap
inline vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh,
const labelUList& pointMap
) const;
//- Internal mesh as vtkUnstructuredGrid.
// Calling this automatically populates the sizing and vtk::Caching
inline vtkSmartPointer<vtkUnstructuredGrid> internal
(
const fvMesh& mesh,
const bool decompPoly = false
);
// Field Conversion
//- Convert internal volume field (CellData)
template<class Type>
static vtkSmartPointer<vtkFloatArray>
convertField
(
const DimensionedField<Type, volMesh>& fld,
const vtuAdaptor& vtuData
);
//- Convert internal volume field (CellData)
template<class Type>
static vtkSmartPointer<vtkFloatArray>
convertField
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const vtuAdaptor& vtuData
);
//- Convert internal volume field (CellData)
template<class Type>
vtkSmartPointer<vtkFloatArray>
convertField
(
const DimensionedField<Type, volMesh>& fld
) const;
//- Convert internal volume field (CellData)
template<class Type>
vtkSmartPointer<vtkFloatArray>
convertField
(
const GeometricField<Type, fvPatchField, volMesh>& fld
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace vtk
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "foamVtkVtuAdaptorI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "foamVtkVtuAdaptorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,192 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2019 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline vtkSmartPointer<vtkPoints>
Foam::vtk::vtuAdaptor::points
(
const fvMesh& mesh
) const
{
// Convert OpenFOAM mesh vertices to VTK
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
// Normal points
const pointField& pts = mesh.points();
// Additional cell centres
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
// Normal points
vtkIdType pointId = 0;
for (const point& p : pts)
{
vtkpoints->SetPoint(pointId++, p.v_);
}
// Cell centres
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
}
inline vtkSmartPointer<vtkPoints>
Foam::vtk::vtuAdaptor::points
(
const fvMesh& mesh,
const labelUList& pointMap
) const
{
// Convert OpenFOAM mesh vertices to VTK
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
// Normal points
const pointField& pts = mesh.points();
// Additional cell centres
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
// Normal points
vtkIdType pointId = 0;
for (const label meshPointi : pointMap)
{
vtkpoints->SetPoint(pointId++, pts[meshPointi].v_);
}
// Cell centres
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
}
inline vtkSmartPointer<vtkUnstructuredGrid>
Foam::vtk::vtuAdaptor::internal
(
const fvMesh& mesh,
const bool decompPoly
)
{
vtk::vtuSizing sizing(mesh, decompPoly);
auto cellTypes = vtkSmartPointer<vtkUnsignedCharArray>::New();
auto cells = vtkSmartPointer<vtkCellArray>::New();
auto faces = vtkSmartPointer<vtkIdTypeArray>::New();
auto cellLocations = vtkSmartPointer<vtkIdTypeArray>::New();
auto faceLocations = vtkSmartPointer<vtkIdTypeArray>::New();
UList<uint8_t> cellTypesUL =
vtk::Tools::asUList(cellTypes, sizing.nFieldCells());
UList<vtkIdType> cellsUL =
vtk::Tools::asUList
(
cells,
sizing.nFieldCells(),
sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS)
);
UList<vtkIdType> cellLocationsUL =
vtk::Tools::asUList
(
cellLocations,
sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS)
);
UList<vtkIdType> facesUL =
vtk::Tools::asUList
(
faces,
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES)
);
UList<vtkIdType> faceLocationsUL =
vtk::Tools::asUList
(
faceLocations,
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS)
);
sizing.populateInternal
(
mesh,
cellTypesUL,
cellsUL,
cellLocationsUL,
facesUL,
faceLocationsUL,
static_cast<foamVtkMeshMaps&>(*this)
);
auto vtkmesh = vtkSmartPointer<vtkUnstructuredGrid>::New();
// Convert OpenFOAM mesh vertices to VTK
// - can only do this *after* populating the decompInfo with cell-ids
// for any additional points (ie, mesh cell-centres)
vtkmesh->SetPoints(this->points(mesh));
if (facesUL.size())
{
vtkmesh->SetCells
(
cellTypes,
cellLocations,
cells,
faceLocations,
faces
);
}
else
{
vtkmesh->SetCells
(
cellTypes,
cellLocations,
cells,
nullptr,
nullptr
);
}
return vtkmesh;
}
// ************************************************************************* //

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2019 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// VTK includes
#include "vtkFloatArray.h"
#include "vtkCellData.h"
#include "vtkPointData.h"
#include "vtkSmartPointer.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::vtuAdaptor::convertField
(
const DimensionedField<Type, volMesh>& fld,
const vtuAdaptor& vtuData
)
{
const int nComp(pTraits<Type>::nComponents);
const labelUList& cellMap = vtuData.cellMap();
auto data = vtkSmartPointer<vtkFloatArray>::New();
data->SetName(fld.name().c_str());
data->SetNumberOfComponents(nComp);
data->SetNumberOfTuples(cellMap.size());
// DebugInfo
// << "Convert field: " << fld.name()
// << " size=" << cellMap.size()
// << " (" << fld.size() << " + "
// << (cellMap.size() - fld.size())
// << ") nComp=" << nComp << endl;
float scratch[pTraits<Type>::nComponents];
vtkIdType celli = 0;
for (const label meshCelli : cellMap)
{
vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]);
data->SetTuple(celli++, scratch);
}
return data;
}
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::vtuAdaptor::convertField
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const vtuAdaptor& vtuData
)
{
return convertField<Type>(fld.internalField(), vtuData);
}
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::vtuAdaptor::convertField
(
const DimensionedField<Type, volMesh>& fld
) const
{
return convertField<Type>(fld, *this);
}
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::vtuAdaptor::convertField
(
const GeometricField<Type, fvPatchField, volMesh>& fld
) const
{
return convertField<Type>(fld, *this);
}
// ************************************************************************* //