Commit ba611a7a authored by Mark Olesen's avatar Mark Olesen

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.

STYLE: adjust style of HashTable iterator pointer dereference
parent d06d0e8f
...@@ -68,7 +68,6 @@ file(GLOB SOURCE_FILES ...@@ -68,7 +68,6 @@ file(GLOB SOURCE_FILES
volMesh/catalystFvMesh.C volMesh/catalystFvMesh.C
volMesh/foamVtkFvMeshAdaptor.C volMesh/foamVtkFvMeshAdaptor.C
volMesh/foamVtkFvMeshAdaptorGeom.C volMesh/foamVtkFvMeshAdaptorGeom.C
volMesh/foamVtkFvMeshAdaptorGeomVtu.C
volMesh/foamVtkFvMeshAdaptorFields.C volMesh/foamVtkFvMeshAdaptorFields.C
) )
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -67,7 +67,7 @@ void Foam::catalyst::faMeshInput::update() ...@@ -67,7 +67,7 @@ void Foam::catalyst::faMeshInput::update()
if (!backends_.found(areaName)) if (!backends_.found(areaName))
{ {
auto backend = auto backend =
autoPtr<Foam::vtk::faMeshAdaptor>::New(*(iter.object())); autoPtr<Foam::vtk::faMeshAdaptor>::New(*(iter.val()));
// Apply any configuration options // Apply any configuration options
// ... // ...
...@@ -187,7 +187,7 @@ Foam::label Foam::catalyst::faMeshInput::addChannels(dataQuery& dataq) ...@@ -187,7 +187,7 @@ Foam::label Foam::catalyst::faMeshInput::addChannels(dataQuery& dataq)
wordHashSet allFields; wordHashSet allFields;
forAllConstIters(backends_, iter) forAllConstIters(backends_, iter)
{ {
allFields += iter.object()->knownFields(selectFields_); allFields += iter.val()->knownFields(selectFields_);
} }
dataq.set(name(), allFields); dataq.set(name(), allFields);
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -75,8 +75,8 @@ void Foam::vtk::faMeshAdaptor::updateContent(const wordRes& selectFields) ...@@ -75,8 +75,8 @@ void Foam::vtk::faMeshAdaptor::updateContent(const wordRes& selectFields)
// Eliminate cached values that would be unreliable // Eliminate cached values that would be unreliable
forAllIters(cachedVtp_, iter) forAllIters(cachedVtp_, iter)
{ {
iter.object().clearGeom(); iter.val().clearGeom();
iter.object().clear(); iter.val().clear();
} }
} }
...@@ -111,9 +111,9 @@ Foam::vtk::faMeshAdaptor::output(const wordRes& select) ...@@ -111,9 +111,9 @@ Foam::vtk::faMeshAdaptor::output(const wordRes& select)
{ {
const auto& longName = internalName; const auto& longName = internalName;
auto iter = cachedVtp_.find(longName); auto iter = cachedVtp_.find(longName);
if (iter.found() && iter.object().dataset) if (iter.found() && iter.val().dataset)
{ {
vtkmesh = iter.object().dataset; vtkmesh = iter.val().dataset;
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -66,12 +66,12 @@ void Foam::vtk::faMeshAdaptor::convertAreaField ...@@ -66,12 +66,12 @@ void Foam::vtk::faMeshAdaptor::convertAreaField
const auto& longName = internalName; const auto& longName = internalName;
auto iter = cachedVtp_.find(longName); auto iter = cachedVtp_.find(longName);
if (!iter.found() || !iter.object().dataset) if (!iter.found() || !iter.val().dataset)
{ {
// Should not happen, but for safety require a vtk geometry // Should not happen, but for safety require a vtk geometry
return; return;
} }
foamVtpData& vtpData = iter.object(); foamVtpData& vtpData = iter.val();
auto dataset = vtpData.dataset; auto dataset = vtpData.dataset;
vtkSmartPointer<vtkFloatArray> cdata = convertAreaFieldToVTK vtkSmartPointer<vtkFloatArray> cdata = convertAreaFieldToVTK
......
...@@ -53,7 +53,7 @@ Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields ...@@ -53,7 +53,7 @@ Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields
if (fieldTypes::area.found(clsName)) if (fieldTypes::area.found(clsName))
{ {
allFields += iter.object(); allFields += iter.val();
} }
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA \\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA \\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -149,7 +151,7 @@ bool Foam::functionObjects::catalystFunctionObject::read(const dictionary& dict) ...@@ -149,7 +151,7 @@ bool Foam::functionObjects::catalystFunctionObject::read(const dictionary& dict)
{ {
functionObject::read(dict); functionObject::read(dict);
const dictionary* inputDictPtr = dict.subDictPtr("inputs"); const dictionary* inputDictPtr = dict.findDict("inputs");
if (!inputDictPtr || inputDictPtr->empty()) if (!inputDictPtr || inputDictPtr->empty())
{ {
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA \\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -46,33 +46,6 @@ namespace vtk ...@@ -46,33 +46,6 @@ namespace vtk
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
vtkSmartPointer<vtkPolyData>
Foam::vtk::cloudAdaptor::startLagrangian
(
const pointField& points
)
{
auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(points.size());
vtkIdType particleId = 0;
for (const vector& p : points)
{
vtkpoints->SetPoint(particleId, p.v_);
++particleId;
}
vtkmesh->SetPoints(vtkpoints);
vtkmesh->SetVerts(vtk::Tools::identityVertices(points.size()));
return vtkmesh;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class UnaryMatchPredicate> template<class UnaryMatchPredicate>
...@@ -124,7 +97,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl ...@@ -124,7 +97,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl
vtkSmartPointer<vtkPolyData> vtkmesh; vtkSmartPointer<vtkPolyData> vtkmesh;
if (pointsPtr) if (pointsPtr)
{ {
vtkmesh = startLagrangian(*pointsPtr); vtkmesh = vtk::Tools::Vertices(*pointsPtr);
// Prevent any possible conversion of positions as a field // Prevent any possible conversion of positions as a field
obrTmp.filterKeys obrTmp.filterKeys
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA \\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -67,7 +69,7 @@ void Foam::catalyst::fvMeshInput::update() ...@@ -67,7 +69,7 @@ void Foam::catalyst::fvMeshInput::update()
auto backend = auto backend =
autoPtr<Foam::vtk::fvMeshAdaptor>::New autoPtr<Foam::vtk::fvMeshAdaptor>::New
( (
*(iter.object()), *(iter.val()),
channelOpt_, channelOpt_,
selectPatches_ selectPatches_
); );
...@@ -203,7 +205,7 @@ Foam::label Foam::catalyst::fvMeshInput::addChannels(dataQuery& dataq) ...@@ -203,7 +205,7 @@ Foam::label Foam::catalyst::fvMeshInput::addChannels(dataQuery& dataq)
wordHashSet allFields; wordHashSet allFields;
forAllConstIters(backends_, iter) forAllConstIters(backends_, iter)
{ {
allFields += iter.object()->knownFields(selectFields_); allFields += iter.val()->knownFields(selectFields_);
} }
dataq.set(name(), allFields); dataq.set(name(), allFields);
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA \\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
......
...@@ -2,7 +2,7 @@ ...@@ -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
...@@ -251,13 +251,13 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields) ...@@ -251,13 +251,13 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields)
// Eliminate cached values that would be unreliable // Eliminate cached values that would be unreliable
forAllIters(cachedVtp_, iter) forAllIters(cachedVtp_, iter)
{ {
iter.object().clearGeom(); iter.val().clearGeom();
iter.object().clear(); iter.val().clear();
} }
forAllIters(cachedVtu_, iter) forAllIters(cachedVtu_, iter)
{ {
iter.object().clearGeom(); iter.val().clearGeom();
iter.object().clear(); iter.val().clear();
} }
definePatchIds(); definePatchIds();
...@@ -267,8 +267,8 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields) ...@@ -267,8 +267,8 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields)
// poly-decompose changed - dispose of cached values // poly-decompose changed - dispose of cached values
forAllIters(cachedVtu_, iter) forAllIters(cachedVtu_, iter)
{ {
iter.object().clearGeom(); iter.val().clearGeom();
iter.object().clear(); iter.val().clear();
} }
} }
...@@ -310,13 +310,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select) ...@@ -310,13 +310,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select)
{ {
const auto& longName = internalName(); const auto& longName = internalName();
auto iter = cachedVtu_.find(longName); auto iter = cachedVtu_.find(longName);
if (!iter.found() || !iter.object().dataset) if (!iter.found() || !iter.val().dataset)
{ {
Pout<<"Cache miss for VTU " << longName << endl; Pout<<"Cache miss for VTU " << longName << endl;
break; // Should never happen break; // Should never happen
} }
foamVtuData& vtuData = iter.object(); foamVtuData& vtuData = iter.val();
auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New(); auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New();
...@@ -350,13 +350,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select) ...@@ -350,13 +350,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select)
const word& longName = pp.name(); const word& longName = pp.name();
auto iter = cachedVtp_.find(longName); auto iter = cachedVtp_.find(longName);
if (!iter.found() || !iter.object().dataset) if (!iter.found() || !iter.val().dataset)
{ {
Pout<<"Cache miss for VTP patch " << longName << endl; Pout<<"Cache miss for VTP patch " << longName << endl;
break; // Should never happen break; // Should never happen
} }
foamVtpData& vtpData = iter.object(); foamVtpData& vtpData = iter.val();
auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New(); auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New();
......
...@@ -58,14 +58,7 @@ SourceFiles ...@@ -58,14 +58,7 @@ SourceFiles
#include "PrimitivePatchInterpolation.H" #include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
#include "foamVtkTools.H" #include "foamVtkVtuAdaptor.H"
#include "foamVtkMeshMaps.H"
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkMultiBlockDataSet.h>
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
...@@ -136,30 +129,8 @@ private: ...@@ -136,30 +129,8 @@ private:
//- 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
);
};
// Private Data // Private Data
...@@ -225,15 +196,6 @@ private: ...@@ -225,15 +196,6 @@ private:
//- Convert specified volume fields //- Convert specified volume fields
void convertVolFields(const wordRes& selectFields); void convertVolFields(const wordRes& selectFields);
//- Volume field
template<class Type>
vtkSmartPointer<vtkFloatArray> convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const;
//- Volume field - all types //- Volume field - all types
template<class Type> template<class Type>
void convertVolField void convertVolField
......
...@@ -75,14 +75,14 @@ void Foam::vtk::fvMeshAdaptor::convertVolField ...@@ -75,14 +75,14 @@ void Foam::vtk::fvMeshAdaptor::convertVolField
const word& longName = pp.name(); const word& longName = pp.name();
auto iter = cachedVtp_.find(longName); auto iter = cachedVtp_.find(longName);
if (!iter.found() || !iter.object().dataset) if (!iter.found() || !iter.val().dataset)
{ {
// Should not happen, but for safety require a vtk geometry // Should not happen, but for safety require a vtk geometry
Pout<<"Cache miss for VTP patch " << longName << endl; Pout<<"Cache miss for VTP patch " << longName << endl;
continue; continue;
} }
foamVtpData& vtpData = iter.object(); foamVtpData& vtpData = iter.val();
auto dataset = vtpData.dataset; auto dataset = vtpData.dataset;
// This is slightly roundabout, but we deal with groups and with // This is slightly roundabout, but we deal with groups and with
...@@ -207,39 +207,26 @@ void Foam::vtk::fvMeshAdaptor::convertVolFieldInternal ...@@ -207,39 +207,26 @@ void Foam::vtk::fvMeshAdaptor::convertVolFieldInternal
const auto& longName = internalName(); const auto& longName = internalName();
auto iter = cachedVtu_.find(longName); auto iter = cachedVtu_.find(longName);
if (!iter.found() || !iter.object().dataset) if (!iter.found() || !iter.val().dataset)
{ {
// Should not happen, but for safety require a vtk geometry // Should not happen, but for safety require a vtk geometry
Pout<<"Cache miss for VTU " << longName << endl; Pout<<"Cache miss for VTU " << longName << endl;
return; return;
} }
foamVtuData& vtuData = iter.object(); 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);
// double cbound[2];
// cdata->GetRange(cbound);
// Info<< "range cdata: " << cbound[0] << " - " << cbound[1] << nl;
if (ptfPtr.valid()) if (ptfPtr.valid())
{ {
vtkSmartPointer<vtkFloatArray> pdata = convertPointField dataset->GetPointData()->AddArray
( (
ptfPtr(), convertPointField(ptfPtr(), fld, vtuData)
fld,
vtuData
); );
dataset->GetPointData()->AddArray(pdata);
// double bound[2];
// pdata->GetRange(bound);
// Info<< "range pdata: " << bound[0] << " - " << bound[1] << nl;
} }
} }
...@@ -331,49 +318,6 @@ vtkSmartPointer<vtkFloatArray> Foam::vtk::fvMeshAdaptor::convertPointField ...@@ -331,49 +318,6 @@ vtkSmartPointer<vtkFloatArray> Foam::vtk::fvMeshAdaptor::convertPointField
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
// low-level conversions
//
template<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::fvMeshAdaptor::convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const
{
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());