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
volMesh/catalystFvMesh.C
volMesh/foamVtkFvMeshAdaptor.C
volMesh/foamVtkFvMeshAdaptorGeom.C
volMesh/foamVtkFvMeshAdaptorGeomVtu.C
volMesh/foamVtkFvMeshAdaptorFields.C
)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -67,7 +67,7 @@ void Foam::catalyst::faMeshInput::update()
if (!backends_.found(areaName))
{
auto backend =
autoPtr<Foam::vtk::faMeshAdaptor>::New(*(iter.object()));
autoPtr<Foam::vtk::faMeshAdaptor>::New(*(iter.val()));
// Apply any configuration options
// ...
......@@ -187,7 +187,7 @@ Foam::label Foam::catalyst::faMeshInput::addChannels(dataQuery& dataq)
wordHashSet allFields;
forAllConstIters(backends_, iter)
{
allFields += iter.object()->knownFields(selectFields_);
allFields += iter.val()->knownFields(selectFields_);
}
dataq.set(name(), allFields);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -75,8 +75,8 @@ void Foam::vtk::faMeshAdaptor::updateContent(const wordRes& selectFields)
// Eliminate cached values that would be unreliable
forAllIters(cachedVtp_, iter)
{
iter.object().clearGeom();
iter.object().clear();
iter.val().clearGeom();
iter.val().clear();
}
}
......@@ -111,9 +111,9 @@ Foam::vtk::faMeshAdaptor::output(const wordRes& select)
{
const auto& longName = internalName;
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 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -66,12 +66,12 @@ void Foam::vtk::faMeshAdaptor::convertAreaField
const auto& longName = internalName;
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
return;
}
foamVtpData& vtpData = iter.object();
foamVtpData& vtpData = iter.val();
auto dataset = vtpData.dataset;
vtkSmartPointer<vtkFloatArray> cdata = convertAreaFieldToVTK
......
......@@ -53,7 +53,7 @@ Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields
if (fieldTypes::area.found(clsName))
{
allFields += iter.object();
allFields += iter.val();
}
}
......
......@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......
......@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -149,7 +151,7 @@ bool Foam::functionObjects::catalystFunctionObject::read(const dictionary& dict)
{
functionObject::read(dict);
const dictionary* inputDictPtr = dict.subDictPtr("inputs");
const dictionary* inputDictPtr = dict.findDict("inputs");
if (!inputDictPtr || inputDictPtr->empty())
{
......
......@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -46,33 +46,6 @@ namespace vtk
} // 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 * * * * * * * * * * * //
template<class UnaryMatchPredicate>
......@@ -124,7 +97,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl
vtkSmartPointer<vtkPolyData> vtkmesh;
if (pointsPtr)
{
vtkmesh = startLagrangian(*pointsPtr);
vtkmesh = vtk::Tools::Vertices(*pointsPtr);
// Prevent any possible conversion of positions as a field
obrTmp.filterKeys
......
......@@ -2,8 +2,10 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -67,7 +69,7 @@ void Foam::catalyst::fvMeshInput::update()
auto backend =
autoPtr<Foam::vtk::fvMeshAdaptor>::New
(
*(iter.object()),
*(iter.val()),
channelOpt_,
selectPatches_
);
......@@ -203,7 +205,7 @@ Foam::label Foam::catalyst::fvMeshInput::addChannels(dataQuery& dataq)
wordHashSet allFields;
forAllConstIters(backends_, iter)
{
allFields += iter.object()->knownFields(selectFields_);
allFields += iter.val()->knownFields(selectFields_);
}
dataq.set(name(), allFields);
......
......@@ -3,7 +3,9 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 CINECA
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2018 CINECA
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -251,13 +251,13 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields)
// Eliminate cached values that would be unreliable
forAllIters(cachedVtp_, iter)
{
iter.object().clearGeom();
iter.object().clear();
iter.val().clearGeom();
iter.val().clear();
}
forAllIters(cachedVtu_, iter)
{
iter.object().clearGeom();
iter.object().clear();
iter.val().clearGeom();
iter.val().clear();
}
definePatchIds();
......@@ -267,8 +267,8 @@ void Foam::vtk::fvMeshAdaptor::updateContent(const wordRes& selectFields)
// poly-decompose changed - dispose of cached values
forAllIters(cachedVtu_, iter)
{
iter.object().clearGeom();
iter.object().clear();
iter.val().clearGeom();
iter.val().clear();
}
}
......@@ -310,13 +310,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select)
{
const auto& longName = internalName();
auto iter = cachedVtu_.find(longName);
if (!iter.found() || !iter.object().dataset)
if (!iter.found() || !iter.val().dataset)
{
Pout<<"Cache miss for VTU " << longName << endl;
break; // Should never happen
}
foamVtuData& vtuData = iter.object();
foamVtuData& vtuData = iter.val();
auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New();
......@@ -350,13 +350,13 @@ Foam::vtk::fvMeshAdaptor::output(const wordRes& select)
const word& longName = pp.name();
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;
break; // Should never happen
}
foamVtpData& vtpData = iter.object();
foamVtpData& vtpData = iter.val();
auto pieces = vtkSmartPointer<vtkMultiPieceDataSet>::New();
......
......@@ -58,14 +58,7 @@ SourceFiles
#include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H"
#include "foamVtkTools.H"
#include "foamVtkMeshMaps.H"
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkMultiBlockDataSet.h>
#include "foamVtkVtuAdaptor.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
......@@ -136,30 +129,8 @@ private:
//- Bookkeeping for vtkUnstructuredGrid
struct foamVtuData
:
public vtk::Caching<vtkUnstructuredGrid>,
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
);
};
public vtk::vtuAdaptor
{};
// Private Data
......@@ -225,15 +196,6 @@ private:
//- Convert specified volume fields
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
template<class Type>
void convertVolField
......
......@@ -75,14 +75,14 @@ void Foam::vtk::fvMeshAdaptor::convertVolField
const word& longName = pp.name();
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
Pout<<"Cache miss for VTP patch " << longName << endl;
continue;
}
foamVtpData& vtpData = iter.object();
foamVtpData& vtpData = iter.val();
auto dataset = vtpData.dataset;
// This is slightly roundabout, but we deal with groups and with
......@@ -207,39 +207,26 @@ void Foam::vtk::fvMeshAdaptor::convertVolFieldInternal
const auto& longName = internalName();
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
Pout<<"Cache miss for VTU " << longName << endl;
return;
}
foamVtuData& vtuData = iter.object();
foamVtuData& vtuData = iter.val();
auto dataset = vtuData.dataset;
vtkSmartPointer<vtkFloatArray> cdata = convertVolFieldToVTK
dataset->GetCellData()->AddArray
(
fld,
vtuData
vtuData.convertField(fld)
);
dataset->GetCellData()->AddArray(cdata);
// double cbound[2];
// cdata->GetRange(cbound);
// Info<< "range cdata: " << cbound[0] << " - " << cbound[1] << nl;
if (ptfPtr.valid())
{
vtkSmartPointer<vtkFloatArray> pdata = convertPointField
dataset->GetPointData()->AddArray
(
ptfPtr(),
fld,
vtuData
convertPointField(ptfPtr(), 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
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
// 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());
DebugInfo
<< "convert volField: " << 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;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -56,7 +56,7 @@ Foam::wordHashSet Foam::vtk::fvMeshAdaptor::knownFields
// || fieldTypes::internal.found(clsName)
)
{
allFields += iter.object();
allFields += iter.val();
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,10 +27,10 @@ License
#include "cellCellStencilObject.H"
// VTK includes
#include <vtkMultiBlockDataSet.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkSmartPointer.h>
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkSmartPointer.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -155,13 +155,13 @@ void Foam::vtk::fvMeshAdaptor::applyGhostingInternal(const labelUList& types)
const auto& longName = internalName();
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
Pout<<"Cache miss for VTU " << longName << endl;
return;
}
foamVtuData& vtuData = iter.object();
foamVtuData& vtuData = iter.val();
auto dataset = vtuData.dataset;
const labelUList& cellMap = vtuData.cellMap();
......@@ -231,14 +231,14 @@ void Foam::vtk::fvMeshAdaptor::applyGhostingBoundary(const labelUList& types)
const word& longName = pp.name();
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
Pout<<"Cache miss for VTP patch " << longName << endl;
continue;
}
foamVtpData& vtpData = iter.object();
foamVtpData& vtpData = iter.val();
auto dataset = vtpData.dataset;
auto vtkgcell = dataset->GetCellGhostArray();
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 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/>.
\*---------------------------------------------------------------------------*/
#include "foamVtkFvMeshAdaptor.H"
// OpenFOAM includes
#include "fvMesh.H"
#include "foamVtkTools.H"
#include "foamVtuSizing.H"
// VTK includes
#include <vtkUnstructuredGrid.h>
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkSmartPointer<vtkPoints>
Foam::vtk::fvMeshAdaptor::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::vtk::fvMeshAdaptor::foamVtuData::points
(
const fvMesh& mesh,
const labelUList& pointMap
) const