Commit 157fa025 authored by Mark Olesen's avatar Mark Olesen

ENH: consolidate some common methods for paraview + catalyst

parent f2a7200c
......@@ -2,6 +2,7 @@ sinclude $(GENERAL_RULES)/paraview
EXE_INC = \
${c++LESSWARN} \
-I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(ParaView_INCLUDE_DIR) \
-I$(ParaView_INCLUDE_DIR)/vtkkwiml
......
......@@ -34,16 +34,6 @@ License
#include "vtkInformation.h"
#include "vtkSmartPointer.h"
#include "foamVtkAdaptors.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(foamPvCore, 0);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::Ostream& Foam::foamPvCore::printDataArraySelection
......@@ -103,13 +93,14 @@ void Foam::foamPvCore::addToBlock
output->SetBlock(blockNo, block);
}
if (debug)
#ifdef FULLDEBUG
{
Info<< "block[" << blockNo << "] has "
<< block->GetNumberOfBlocks()
<< " datasets prior to adding set " << datasetNo
<< " with name: " << datasetName << endl;
}
#endif
block->SetBlock(datasetNo, dataset);
......@@ -192,9 +183,8 @@ Foam::foamPvCore::getSelectedArraySet
}
}
if (debug > 1)
#ifdef FULLDEBUG
{
const int n = select->GetNumberOfArrays();
Info<< "available(";
for (int i=0; i < n; ++i)
{
......@@ -208,6 +198,7 @@ Foam::foamPvCore::getSelectedArraySet
}
Info<< " )\n";
}
#endif
return enabled;
}
......@@ -238,7 +229,7 @@ Foam::word Foam::foamPvCore::getFoamName(const std::string& str)
{
if (str.size())
{
std::string::size_type beg = str.rfind('/');
auto beg = str.rfind('/');
if (beg == std::string::npos)
{
beg = 0;
......@@ -248,7 +239,7 @@ Foam::word Foam::foamPvCore::getFoamName(const std::string& str)
++beg;
}
std::string::size_type end = beg;
auto end = beg;
while (str[end] && word::valid(str[end]))
{
......@@ -274,29 +265,4 @@ void Foam::foamPvCore::printMemory()
}
vtkSmartPointer<vtkCellArray> Foam::foamPvCore::identityVertices
(
const label size
)
{
// VTK_VERTEX
auto cells = vtkSmartPointer<vtkCellArray>::New();
UList<vtkIdType> cellsUL = vtkUList(cells, size, 2*size);
// Cell connectivity for vertex
// [size, ids.., size, ids...]
// which means
// [1, id, 1, id, ...]
label idx = 0;
for (label id=0; id < size; ++id)
{
cellsUL[idx++] = 1;
cellsUL[idx++] = id;
}
return cells;
}
// ************************************************************************* //
......@@ -26,13 +26,13 @@ Description
SourceFiles
foamPvCore.C
foamPvCoreTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef foamPvCore_H
#define foamPvCore_H
#include "className.H"
#include "fileName.H"
#include "stringList.H"
#include "boolList.H"
......@@ -167,25 +167,10 @@ public:
}; // End class arrayRange
private:
// Private Member Functions
//- Disallow default bitwise copy construct
foamPvCore(const foamPvCore&) = delete;
//- Disallow default bitwise assignment
void operator=(const foamPvCore&) = delete;
public:
//- Static data members
ClassName("foamPvCore");
//- Construct null
foamPvCore() = default;
constexpr foamPvCore() noexcept {}
//- Print information about vtkDataArraySelection
......@@ -308,13 +293,6 @@ public:
static void printMemory();
//- Return an identity list of VTK_VERTEX
static vtkSmartPointer<vtkCellArray> identityVertices
(
const label size
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}; // End class foamPvCore
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
Description
Helpers for OpenFOAM reader interfaces in ParaView.
\*---------------------------------------------------------------------------*/
#ifndef foamPvFields_H
#define foamPvFields_H
#include "symmTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class foamPvFields Declaration
\*---------------------------------------------------------------------------*/
struct foamPvFields
{
//- Remapping for some data types
template<class Type>
inline static void remapTuple(float vec[])
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Template specialization for symmTensor
template<>
inline void Foam::foamPvFields::remapTuple<Foam::symmTensor>(float vec[])
{
Foam::Swap(vec[1], vec[3]); // swap XY <-> YY
Foam::Swap(vec[2], vec[5]); // swap XZ <-> ZZ
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#ifndef foamVtkAdaptors_H
#define foamVtkAdaptors_H
// OpenFOAM includes
#include "labelList.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkIdTypeArray.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedCharArray.h"
#include "vtkAOSDataArrayTemplate.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//- Attach a smart pointer, or generate a non-null one.
template<class T>
inline vtkSmartPointer<T> nonNullSmartPointer(T* ptr)
{
return vtkSmartPointer<T>(ptr ? ptr : T::New());
}
//- Helper to wrap vtkUnsignedCharArray as a UList
inline UList<uint8_t> vtkUList
(
vtkUnsignedCharArray* array,
const label size
)
{
array->SetNumberOfComponents(1);
array->SetNumberOfTuples(size);
UList<uint8_t> list
(
array->WritePointer(0, size),
size
);
return list;
}
//- Helper to wrap vtkIdTypeArray as a UList
inline UList<vtkIdType> vtkUList
(
vtkIdTypeArray* array,
const label size
)
{
array->SetNumberOfComponents(1);
array->SetNumberOfTuples(size);
UList<vtkIdType> list
(
array->WritePointer(0, size),
size
);
return list;
}
//- Special helper to wrap vtkCellArray as a UList
inline UList<vtkIdType> vtkUList
(
vtkCellArray* cells,
const label nCells,
const label size
)
{
cells->GetData()->SetNumberOfTuples(size);
UList<vtkIdType> list
(
cells->WritePointer(nCells, size),
size
);
return list;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -72,6 +72,7 @@ SourceFiles
#include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H"
#include "foamPvCore.H"
#include "foamVtkTools.H"
#include "foamVtkMeshMaps.H"
#include "vtkPoints.h"
......@@ -115,112 +116,53 @@ template<class Type> class List;
class vtkPVFoam
:
private foamPvCore
private foamPvCore,
protected vtk::Tools
{
// Convenience typedefs
typedef PrimitivePatchInterpolation<primitivePatch> patchInterpolator;
// Private classes
//- Bookkeeping for internal caching.
// Retain an original copy of the geometry as well as a shallow copy
// with the output fields.
// The original copy is reused for different timestep
template<class DataType>
struct foamVtkCaching
{
typedef DataType dataType;
//- The geometry, without any cell/point data
vtkSmartPointer<dataType> vtkgeom;
//- The shallow-copy of geometry, plus additional data
vtkSmartPointer<dataType> dataset;
//- Number of points associated with geometry
inline uint64_t nPoints() const
{
return vtkgeom ? vtkgeom->GetNumberOfPoints() : 0;
}
//- Clear geometry and dataset
void clearGeom()
{
vtkgeom = nullptr;
dataset = nullptr;
}
//- Return a shallow copy of vtkgeom for manipulation
vtkSmartPointer<dataType> getCopy() const
{
auto copy = vtkSmartPointer<dataType>::New();
if (vtkgeom)
{
copy->ShallowCopy(vtkgeom);
}
return copy;
}
//- Make a shallow copy of vtkgeom into dataset
void reuse()
{
dataset = vtkSmartPointer<dataType>::New();
if (vtkgeom)
{
dataset->ShallowCopy(vtkgeom);
}
}
//- Set the geometry and make a shallow copy to dataset
void set(vtkSmartPointer<dataType> geom)
{
vtkgeom = geom;
reuse();
}
//- Report basic information to output
void PrintSelf(std::ostream& os) const
{
os << "geom" << nl;
if (vtkgeom)
{
vtkgeom->PrintSelf(std::cout, vtkIndent(2));
}
else
{
os << "nullptr";
}
os << nl;
os << "copy" << nl;
if (dataset)
{
dataset->PrintSelf(std::cout, vtkIndent(2));
}
else
{
os << "nullptr";
}
os << nl;
}
};
//- Bookkeeping for vtkPolyData
struct foamVtpData
:
public foamVtkCaching<vtkPolyData>,
public vtk::Caching<vtkPolyData>,
public foamVtkMeshMaps
{};
//- Bookkeeping for vtkUnstructuredGrid
struct foamVtuData
:
public foamVtkCaching<vtkUnstructuredGrid>,
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
);
//- Subsetted mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> subset
(
const fvMeshSubset& subsetter,
const bool decompPoly
);
};
// Private Data
......@@ -294,7 +236,7 @@ class vtkPVFoam
//- Reset data counters
void resetCounters();
// Update information helper functions
// Update information helper functions
//- Internal mesh info
void updateInfoInternalMesh(vtkDataArraySelection* select);
......@@ -347,7 +289,7 @@ class vtkPVFoam
void updateInfoLagrangianFields(vtkDataArraySelection* select);
// Mesh conversion functions
// Mesh conversion functions
//- Convert internalMesh
void convertMeshVolume();
......@@ -385,53 +327,7 @@ class vtkPVFoam
void convertMeshPointSets();
// Add mesh functions
//- Generate vtk points for the current mesh points/decomposition
static vtkSmartPointer<vtkPoints> movePoints
(
const fvMesh& mesh,
const foamVtuData& vtuData
);
//- Generate vtk points for the current mesh points/decomposition,
// using the provided pointMap
static vtkSmartPointer<vtkPoints> movePoints
(
const fvMesh& mesh,
const foamVtuData& vtuData,
const labelUList& pointMap
);
//- Volume mesh as vtkUnstructuredGrid
static vtkSmartPointer<vtkUnstructuredGrid> volumeVTKMesh
(
const fvMesh& mesh,
foamVtuData& vtuData,
const bool decompPoly
);
//- Subsetted mesh as vtkUnstructuredGrid
static vtkSmartPointer<vtkUnstructuredGrid> volumeVTKSubsetMesh
(
const fvMeshSubset& subsetter,
foamVtuData& vtuData,
const bool decompPoly
);
//- Volume mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> volumeVTKMesh
(
const fvMesh& mesh,
foamVtuData& vtuData
) const;
//- Subsetted mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> volumeVTKSubsetMesh
(
const fvMeshSubset& subsetter,
foamVtuData& vtuData
) const;
// Add mesh functions
//- Lagrangian positions as vtkPolyData
vtkSmartPointer<vtkPolyData> lagrangianVTKMesh
......@@ -440,55 +336,8 @@ class vtkPVFoam
const word& cloudName
) const;
//- Patch points
template<class PatchType>
static vtkSmartPointer<vtkPoints> movePatchPoints
(
const PatchType& p
);
//- Patch faces as vtk-cells
template<class PatchType>
static vtkSmartPointer<vtkCellArray> patchFacesVTKCells
(
const PatchType& p
);
//- Patches (mesh or primitive) as vtkPolyData
template<class PatchType>
static vtkSmartPointer<vtkPolyData> patchVTKMesh
(
const PatchType& p
);
// Field conversion functions
//- Copy list to pre-allocated vtk array.
// \return number of input items copied
template<class Type>
static label transcribeFloatData
(
vtkFloatArray* array,
const UList<Type>& input,
const label start = 0
);
//- Create named field initialized to zero
template<class Type>
static vtkSmartPointer<vtkFloatArray> zeroVTKField
(
const word& name,
const label size
);
//- Convert float data to VTK field
template<class Type>
vtkSmartPointer<vtkFloatArray> convertFieldToVTK
(
const word& name,
const UList<Type>& fld
) const;
// Field conversion functions
//- Face set/zone field
template<class Type>
......@@ -520,7 +369,7 @@ class vtkPVFoam
void convertLagrangianFields();
// Convert OpenFOAM fields
// Convert OpenFOAM fields
//- Volume field - all types
template<class Type>
......@@ -599,7 +448,7 @@ class vtkPVFoam
);