From c0498e731a87867d8d76eddcbffb14cd8355a88b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 3 Apr 2018 18:42:35 +0200 Subject: [PATCH 1/2] ENH: consolidate some common methods for paraview + catalyst --- .../graphics/PVReaders/foamPv/Make/options | 1 + .../graphics/PVReaders/foamPv/foamPvCore.C | 46 +-- .../graphics/PVReaders/foamPv/foamPvCore.H | 26 +- .../graphics/PVReaders/foamPv/foamPvFields.H | 70 ----- .../PVReaders/foamPv/foamVtkAdaptors.H | 115 ------- .../graphics/PVReaders/vtkPVFoam/vtkPVFoam.H | 243 +++------------ .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 128 +------- .../PVReaders/vtkPVFoam/vtkPVFoamMesh.C | 35 +-- .../vtkPVFoam/vtkPVFoamMeshLagrangian.C | 2 +- .../PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C | 118 +++----- .../PVReaders/vtkPVFoam/vtkPVFoamTemplates.C | 119 -------- .../PVReaders/vtkPVblockMesh/Make/options | 1 + .../vtkPVblockMesh/vtkPVblockMeshConvert.C | 5 +- src/conversion/vtk/adaptor/foamVtkTools.H | 285 ++++++++++++++++++ src/conversion/vtk/adaptor/foamVtkToolsI.H | 90 ++++++ .../vtk/adaptor/foamVtkToolsTemplates.C | 229 ++++++++++++++ 16 files changed, 725 insertions(+), 788 deletions(-) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamVtkAdaptors.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamTemplates.C create mode 100644 src/conversion/vtk/adaptor/foamVtkTools.H create mode 100644 src/conversion/vtk/adaptor/foamVtkToolsI.H create mode 100644 src/conversion/vtk/adaptor/foamVtkToolsTemplates.C diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options index a5276c021d..bf52ca3659 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options @@ -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 diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C index 347ebf4383..7abf88a24f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C @@ -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 Foam::foamPvCore::identityVertices -( - const label size -) -{ - // VTK_VERTEX - auto cells = vtkSmartPointer::New(); - - UList 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; -} - - // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H index 59ca049ea5..e416ec8baa 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H @@ -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 identityVertices - ( - const label size - ); - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // }; // End class foamPvCore diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H deleted file mode 100644 index 725c8cf29d..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H +++ /dev/null @@ -1,70 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / 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 . - -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 - inline static void remapTuple(float vec[]) - {} - -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// Template specialization for symmTensor -template<> -inline void Foam::foamPvFields::remapTuple(float vec[]) -{ - Foam::Swap(vec[1], vec[3]); // swap XY <-> YY - Foam::Swap(vec[2], vec[5]); // swap XZ <-> ZZ -} - - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamVtkAdaptors.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamVtkAdaptors.H deleted file mode 100644 index 89146bc889..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamVtkAdaptors.H +++ /dev/null @@ -1,115 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / 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 . - -\*---------------------------------------------------------------------------*/ - -#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 - inline vtkSmartPointer nonNullSmartPointer(T* ptr) - { - return vtkSmartPointer(ptr ? ptr : T::New()); - } - - - //- Helper to wrap vtkUnsignedCharArray as a UList - inline UList vtkUList - ( - vtkUnsignedCharArray* array, - const label size - ) - { - array->SetNumberOfComponents(1); - array->SetNumberOfTuples(size); - - UList list - ( - array->WritePointer(0, size), - size - ); - - return list; - } - - - //- Helper to wrap vtkIdTypeArray as a UList - inline UList vtkUList - ( - vtkIdTypeArray* array, - const label size - ) - { - array->SetNumberOfComponents(1); - array->SetNumberOfTuples(size); - - UList list - ( - array->WritePointer(0, size), - size - ); - - return list; - } - - - //- Special helper to wrap vtkCellArray as a UList - inline UList vtkUList - ( - vtkCellArray* cells, - const label nCells, - const label size - ) - { - cells->GetData()->SetNumberOfTuples(size); - - UList list - ( - cells->WritePointer(nCells, size), - size - ); - - return list; - } -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H index 3eb7194993..ce9565ad32 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H @@ -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 List; class vtkPVFoam : - private foamPvCore + private foamPvCore, + protected vtk::Tools { // Convenience typedefs typedef PrimitivePatchInterpolation 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 - struct foamVtkCaching - { - typedef DataType dataType; - - //- The geometry, without any cell/point data - vtkSmartPointer vtkgeom; - - //- The shallow-copy of geometry, plus additional data - vtkSmartPointer 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 getCopy() const - { - auto copy = vtkSmartPointer::New(); - if (vtkgeom) - { - copy->ShallowCopy(vtkgeom); - } - return copy; - } - - //- Make a shallow copy of vtkgeom into dataset - void reuse() - { - dataset = vtkSmartPointer::New(); - if (vtkgeom) - { - dataset->ShallowCopy(vtkgeom); - } - } - - //- Set the geometry and make a shallow copy to dataset - void set(vtkSmartPointer 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, + public vtk::Caching, public foamVtkMeshMaps {}; - //- Bookkeeping for vtkUnstructuredGrid struct foamVtuData : - public foamVtkCaching, + public vtk::Caching, public foamVtkMeshMaps - {}; + { + //- The vtk points for the mesh (and decomposition) + vtkSmartPointer points + ( + const fvMesh& mesh + ) const; + + //- The vtk points for the mesh (and decomposition), + //- using the provided pointMap + vtkSmartPointer points + ( + const fvMesh& mesh, + const labelUList& pointMap + ) const; + + //- Internal mesh as vtkUnstructuredGrid + vtkSmartPointer internal + ( + const fvMesh& mesh, + const bool decompPoly + ); + + //- Subsetted mesh as vtkUnstructuredGrid + vtkSmartPointer 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 movePoints - ( - const fvMesh& mesh, - const foamVtuData& vtuData - ); - - //- Generate vtk points for the current mesh points/decomposition, - // using the provided pointMap - static vtkSmartPointer movePoints - ( - const fvMesh& mesh, - const foamVtuData& vtuData, - const labelUList& pointMap - ); - - //- Volume mesh as vtkUnstructuredGrid - static vtkSmartPointer volumeVTKMesh - ( - const fvMesh& mesh, - foamVtuData& vtuData, - const bool decompPoly - ); - - //- Subsetted mesh as vtkUnstructuredGrid - static vtkSmartPointer volumeVTKSubsetMesh - ( - const fvMeshSubset& subsetter, - foamVtuData& vtuData, - const bool decompPoly - ); - - //- Volume mesh as vtkUnstructuredGrid - vtkSmartPointer volumeVTKMesh - ( - const fvMesh& mesh, - foamVtuData& vtuData - ) const; - - //- Subsetted mesh as vtkUnstructuredGrid - vtkSmartPointer volumeVTKSubsetMesh - ( - const fvMeshSubset& subsetter, - foamVtuData& vtuData - ) const; + // Add mesh functions //- Lagrangian positions as vtkPolyData vtkSmartPointer lagrangianVTKMesh @@ -440,55 +336,8 @@ class vtkPVFoam const word& cloudName ) const; - //- Patch points - template - static vtkSmartPointer movePatchPoints - ( - const PatchType& p - ); - //- Patch faces as vtk-cells - template - static vtkSmartPointer patchFacesVTKCells - ( - const PatchType& p - ); - - //- Patches (mesh or primitive) as vtkPolyData - template - static vtkSmartPointer patchVTKMesh - ( - const PatchType& p - ); - - - // Field conversion functions - - //- Copy list to pre-allocated vtk array. - // \return number of input items copied - template - static label transcribeFloatData - ( - vtkFloatArray* array, - const UList& input, - const label start = 0 - ); - - //- Create named field initialized to zero - template - static vtkSmartPointer zeroVTKField - ( - const word& name, - const label size - ); - - //- Convert float data to VTK field - template - vtkSmartPointer convertFieldToVTK - ( - const word& name, - const UList& fld - ) const; + // Field conversion functions //- Face set/zone field template @@ -520,7 +369,7 @@ class vtkPVFoam void convertLagrangianFields(); - // Convert OpenFOAM fields + // Convert OpenFOAM fields //- Volume field - all types template @@ -599,7 +448,7 @@ class vtkPVFoam ); - // GUI selection helper functions + // GUI selection helper functions //- Get the first word from the reader 'parts' selection word getReaderPartName(const int partId) const; @@ -607,10 +456,10 @@ class vtkPVFoam // Constructors - //- Disallow default bitwise copy construct + //- No copy construct vtkPVFoam(const vtkPVFoam&) = delete; - //- Disallow default bitwise assignment + //- No copy assignment void operator=(const vtkPVFoam&) = delete; @@ -684,12 +533,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "vtkPVFoamTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C index 5a2ddfcb50..1b8b94735a 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -37,7 +37,6 @@ InClass #include "volPointInterpolation.H" #include "zeroGradientFvPatchField.H" #include "interpolatePointToCell.H" -#include "foamPvFields.H" #include "areaFaMesh.H" #include "areaFields.H" @@ -119,7 +118,7 @@ void Foam::vtkPVFoam::convertVolField // To improve code reuse, we allocate the CellData as a zeroed-field // ahead of time. - vtkSmartPointer cdata = zeroVTKField + vtkSmartPointer cdata = zeroField ( fld.name(), dataset->GetNumberOfPolys() @@ -662,7 +661,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField { vec[d] = component(t, d); } - foamPvFields::remapTuple(vec); + remapTuple(vec); data->SetTuple(pointi++, vec); } @@ -676,7 +675,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField { vec[d] = component(t, d); } - foamPvFields::remapTuple(vec); + remapTuple(vec); data->SetTuple(pointi++, vec); } @@ -693,7 +692,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField { vec[d] = component(t, d); } - foamPvFields::remapTuple(vec); + remapTuple(vec); data->SetTuple(pointi++, vec); } @@ -707,7 +706,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField { vec[d] = component(t, d); } - foamPvFields::remapTuple(vec); + remapTuple(vec); data->SetTuple(pointi++, vec); } @@ -758,119 +757,6 @@ void Foam::vtkPVFoam::convertLagrangianFields // low-level conversions // -template -vtkSmartPointer -Foam::vtkPVFoam::zeroVTKField -( - const word& name, - const label size -) -{ - auto data = vtkSmartPointer::New(); - - data->SetName(name.c_str()); - data->SetNumberOfComponents(int(pTraits::nComponents)); - data->SetNumberOfTuples(size); - - data->Fill(0); - - return data; -} - - -template -Foam::label Foam::vtkPVFoam::transcribeFloatData -( - vtkFloatArray* array, - const UList& input, - const label start -) -{ - const int nComp(pTraits::nComponents); - - if (array->GetNumberOfComponents() != nComp) - { - FatalErrorInFunction - << "vtk array '" << array->GetName() - << "' has mismatch in number of components for type '" - << pTraits::typeName - << "' : target array has " << array->GetNumberOfComponents() - << " components instead of " << nComp - << nl; - } - - const vtkIdType maxSize = array->GetNumberOfTuples(); - const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size()); - - if (start < 0 || vtkIdType(start) >= maxSize) - { - WarningInFunction - << "vtk array '" << array->GetName() - << "' copy with out-of-range (0-" << long(maxSize-1) << ")" - << " starting location" - << nl; - - return 0; - } - else if (endPos > maxSize) - { - WarningInFunction - << "vtk array '" << array->GetName() - << "' copy ends out-of-range (" << long(maxSize) << ")" - << " using sizing (start,size) = (" - << start << "," << input.size() << ")" - << nl; - - return 0; - } - - float scratch[nComp]; - forAll(input, idx) - { - const Type& t = input[idx]; - for (direction d=0; d(scratch); - - array->SetTuple(start+idx, scratch); - } - - return input.size(); -} - - -template -vtkSmartPointer -Foam::vtkPVFoam::convertFieldToVTK -( - const word& name, - const UList& fld -) const -{ - const int nComp(pTraits::nComponents); - - if (debug) - { - Info<< "convert UList<" << pTraits::typeName << "> " - << name - << " size=" << fld.size() - << " nComp=" << nComp << nl; - } - - auto data = vtkSmartPointer::New(); - - data->SetName(name.c_str()); - data->SetNumberOfComponents(nComp); - data->SetNumberOfTuples(fld.size()); - - transcribeFloatData(data, fld); - - return data; -} - - template vtkSmartPointer Foam::vtkPVFoam::convertFaceFieldToVTK @@ -923,7 +809,7 @@ Foam::vtkPVFoam::convertFaceFieldToVTK scratch[d] = component(t, d); } } - foamPvFields::remapTuple(scratch); + remapTuple(scratch); data->SetTuple(idx, scratch); } @@ -966,7 +852,7 @@ Foam::vtkPVFoam::convertVolFieldToVTK { scratch[d] = component(t, d); } - foamPvFields::remapTuple(scratch); + remapTuple(scratch); data->SetTuple(idx, scratch); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C index 1b873f3972..5970233049 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C @@ -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. @@ -81,14 +81,14 @@ void Foam::vtkPVFoam::convertMeshVolume() Info<< "move points " << longName << nl; } vtkgeom = vtuData.getCopy(); - vtkgeom->SetPoints(movePoints(mesh, vtuData)); + vtkgeom->SetPoints(vtuData.points(mesh)); } } if (!vtkgeom) { // Nothing usable from cache - create new geometry - vtkgeom = volumeVTKMesh(mesh, vtuData); + vtkgeom = vtuData.internal(mesh, this->decomposePoly_); } vtuData.set(vtkgeom); @@ -176,7 +176,10 @@ void Foam::vtkPVFoam::convertMeshPatches() if (patchIds.size() == 1) { vtkgeom = vtpData.getCopy(); - vtkgeom->SetPoints(movePatchPoints(patches[patchIds[0]])); + vtkgeom->SetPoints + ( + vtk::Tools::Patch::points(patches[patchIds[0]]) + ); continue; } } @@ -234,7 +237,7 @@ void Foam::vtkPVFoam::convertMeshPatches() mesh.points() ); - vtkgeom = patchVTKMesh(pp); + vtkgeom = vtk::Tools::Patch::mesh(pp); } faceLabels.clear(); // Unneeded @@ -256,7 +259,7 @@ void Foam::vtkPVFoam::convertMeshPatches() // Store good patch id as additionalIds vtpData.additionalIds() = {patchId}; - vtkgeom = patchVTKMesh(patches[patchId]); + vtkgeom = vtk::Tools::Patch::mesh(patches[patchId]); } } @@ -343,7 +346,7 @@ void Foam::vtkPVFoam::convertMeshArea() vtpData.clear(); // Remove any old mappings // Nothing usable from cache - create new geometry - vtkgeom = patchVTKMesh(mesh.patch()); + vtkgeom = vtk::Tools::Patch::mesh(mesh.patch()); } vtpData.set(vtkgeom); @@ -414,10 +417,7 @@ void Foam::vtkPVFoam::convertMeshCellZones() Info<< "move points " << longName << nl; } vtkgeom = vtuData.getCopy(); - vtkgeom->SetPoints - ( - movePoints(mesh, vtuData, vtuData.pointMap()) - ); + vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); } } @@ -426,7 +426,7 @@ void Foam::vtkPVFoam::convertMeshCellZones() fvMeshSubset subsetter(mesh); subsetter.setLargeCellSubset(zMesh[zoneId]); - vtkgeom = volumeVTKSubsetMesh(subsetter, vtuData); + vtkgeom = vtuData.subset(subsetter, this->decomposePoly_); } vtuData.set(vtkgeom); @@ -484,10 +484,7 @@ void Foam::vtkPVFoam::convertMeshCellSets() Info<< "move points " << longName << nl; } vtkgeom = vtuData.getCopy(); - vtkgeom->SetPoints - ( - movePoints(mesh, vtuData, vtuData.pointMap()) - ); + vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); } } @@ -496,7 +493,7 @@ void Foam::vtkPVFoam::convertMeshCellSets() fvMeshSubset subsetter(mesh); subsetter.setLargeCellSubset(cellSet(mesh, partName)); - vtkgeom = volumeVTKSubsetMesh(subsetter, vtuData); + vtkgeom = vtuData.subset(subsetter, this->decomposePoly_); } vtuData.set(vtkgeom); @@ -571,7 +568,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones() vtpData.clear(); // No additional ids, maps const primitiveFacePatch& pp = zMesh[zoneId](); - vtkgeom = patchVTKMesh(pp); + vtkgeom = vtk::Tools::Patch::mesh(pp); } vtpData.set(vtkgeom); @@ -644,7 +641,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets() mesh.points() ); - vtkgeom = patchVTKMesh(pp); + vtkgeom = vtk::Tools::Patch::mesh(pp); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C index d7706d6656..350ec9a17e 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C @@ -86,7 +86,7 @@ vtkSmartPointer Foam::vtkPVFoam::lagrangianVTKMesh vtkmesh = vtkSmartPointer::New(); vtkmesh->SetPoints(vtkpoints); - vtkmesh->SetVerts(foamPvCore::identityVertices(parcels.size())); + vtkmesh->SetVerts(vtk::Tools::identityVertices(parcels.size())); } if (debug) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C index f1d1ebd36b..7ef9e570ff 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,96 +29,91 @@ License // OpenFOAM includes #include "fvMesh.H" #include "fvMeshSubset.H" -#include "foamVtkAdaptors.H" +#include "foamVtkTools.H" #include "foamVtuSizing.H" // VTK includes -#include "vtkUnstructuredGrid.h" +#include // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -vtkSmartPointer Foam::vtkPVFoam::movePoints +vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points ( - const fvMesh& mesh, - const foamVtuData& vtuData -) + const fvMesh& mesh +) const { // Convert OpenFOAM mesh vertices to VTK auto vtkpoints = vtkSmartPointer::New(); // Normal points - const pointField& points = mesh.points(); + const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = vtuData.additionalIds(); + const labelList& addPoints = this->additionalIds(); - vtkpoints->SetNumberOfPoints(points.size() + addPoints.size()); + vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); // Normal points - label pointi = 0; - forAll(points, i) + label pointId = 0; + for (const point& p : pts) { - vtkpoints->SetPoint(pointi++, points[i].v_); + vtkpoints->SetPoint(pointId, p.v_); + ++pointId; } // Cell centres - forAll(addPoints, i) + for (const label ptId : addPoints) { - vtkpoints->SetPoint(pointi++, mesh.C()[addPoints[i]].v_); + vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); + ++pointId; } return vtkpoints; } -vtkSmartPointer Foam::vtkPVFoam::movePoints +vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points ( const fvMesh& mesh, - const foamVtuData& vtuData, const labelUList& pointMap -) +) const { // Convert OpenFOAM mesh vertices to VTK auto vtkpoints = vtkSmartPointer::New(); // Normal points - const pointField& points = mesh.points(); + const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = vtuData.additionalIds(); + const labelList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); // Normal points - label pointi = 0; - forAll(pointMap, i) + label pointId = 0; + for (const label ptId : pointMap) { - vtkpoints->SetPoint(pointi++, points[pointMap[i]].v_); + vtkpoints->SetPoint(pointId, pts[ptId].v_); + ++pointId; } // Cell centres - forAll(addPoints, i) + for (const label ptId : addPoints) { - vtkpoints->SetPoint(pointi++, mesh.C()[addPoints[i]].v_); + vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); + ++pointId; } return vtkpoints; } -vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh +vtkSmartPointer Foam::vtkPVFoam::foamVtuData::internal ( const fvMesh& mesh, - foamVtuData& vtuData, const bool decompPoly ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - printMemory(); - } - vtk::vtuSizing sizing(mesh, decompPoly); auto cellTypes = vtkSmartPointer::New(); @@ -130,14 +125,14 @@ vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh auto faceLocations = vtkSmartPointer::New(); UList cellTypesUL = - vtkUList + vtk::Tools::asUList ( cellTypes, sizing.nFieldCells() ); UList cellsUL = - vtkUList + vtk::Tools::asUList ( cells, sizing.nFieldCells(), @@ -145,21 +140,21 @@ vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh ); UList cellLocationsUL = - vtkUList + vtk::Tools::asUList ( cellLocations, sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS) ); UList facesUL = - vtkUList + vtk::Tools::asUList ( faces, sizing.sizeInternal(vtk::vtuSizing::slotType::FACES) ); UList faceLocationsUL = - vtkUList + vtk::Tools::asUList ( faceLocations, sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS) @@ -174,7 +169,7 @@ vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh cellLocationsUL, facesUL, faceLocationsUL, - static_cast(vtuData) + static_cast(*this) ); auto vtkmesh = vtkSmartPointer::New(); @@ -182,7 +177,7 @@ vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh // 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(movePoints(mesh, vtuData)); + vtkmesh->SetPoints(this->points(mesh)); if (facesUL.size()) { @@ -207,58 +202,27 @@ vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh ); } - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - printMemory(); - } - return vtkmesh; } -vtkSmartPointer Foam::vtkPVFoam::volumeVTKSubsetMesh +vtkSmartPointer Foam::vtkPVFoam::foamVtuData::subset ( const fvMeshSubset& subsetter, - foamVtuData& vtuData, const bool decompPoly ) { - vtkSmartPointer vtkmesh = volumeVTKMesh - ( - subsetter.subMesh(), - vtuData, - decompPoly - ); + vtkSmartPointer vtkmesh = + this->internal(subsetter.subMesh(), decompPoly); // Convert cellMap, addPointCellLabels to global cell ids - vtuData.renumberCells(subsetter.cellMap()); + this->renumberCells(subsetter.cellMap()); // Copy pointMap as well, otherwise pointFields fail - vtuData.pointMap() = subsetter.pointMap(); + this->pointMap() = subsetter.pointMap(); return vtkmesh; } -vtkSmartPointer Foam::vtkPVFoam::volumeVTKMesh -( - const fvMesh& mesh, - foamVtuData& vtuData -) const -{ - return volumeVTKMesh(mesh, vtuData, this->decomposePoly_); -} - - -vtkSmartPointer Foam::vtkPVFoam::volumeVTKSubsetMesh -( - const fvMeshSubset& subsetter, - foamVtuData& vtuData -) const -{ - return volumeVTKSubsetMesh(subsetter, vtuData, this->decomposePoly_); -} - - // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamTemplates.C deleted file mode 100644 index 986477320d..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamTemplates.C +++ /dev/null @@ -1,119 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / 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. -------------------------------------------------------------------------------- -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 . - -\*---------------------------------------------------------------------------*/ - -#include "vtkPVFoam.H" - -// OpenFOAM includes -#include "polyPatch.H" -#include "primitivePatch.H" -#include "foamVtkAdaptors.H" - -// VTK includes -#include "vtkCellArray.h" -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkSmartPointer.h" - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template -vtkSmartPointer Foam::vtkPVFoam::movePatchPoints -( - const PatchType& p -) -{ - // Convert OpenFOAM mesh vertices to VTK - const pointField& points = p.localPoints(); - - auto vtkpoints = vtkSmartPointer::New(); - - vtkpoints->SetNumberOfPoints(points.size()); - forAll(points, i) - { - vtkpoints->SetPoint(i, points[i].v_); - } - - return vtkpoints; -} - - -template -vtkSmartPointer Foam::vtkPVFoam::patchFacesVTKCells -( - const PatchType& p -) -{ - // Faces as polygons - const faceList& faces = p.localFaces(); - - label nAlloc = faces.size(); - for (const face& f : faces) - { - nAlloc += f.size(); - } - - auto cells = vtkSmartPointer::New(); - - UList cellsUL = - vtkUList - ( - cells, - faces.size(), - nAlloc - ); - - // Cell connectivity for polygons - // [size, verts..., size, verts... ] - label idx = 0; - for (const face& f : faces) - { - cellsUL[idx++] = f.size(); - - for (const label verti : f) - { - cellsUL[idx++] = verti; - } - } - - return cells; -} - - -template -vtkSmartPointer Foam::vtkPVFoam::patchVTKMesh -( - const PatchType& p -) -{ - auto vtkmesh = vtkSmartPointer::New(); - - vtkmesh->SetPoints(movePatchPoints(p)); - vtkmesh->SetPolys(patchFacesVTKCells(p)); - - return vtkmesh; -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options index a41d97cf4f..dc1999774a 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options @@ -3,6 +3,7 @@ sinclude $(GENERAL_RULES)/paraview EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/mesh/blockMesh/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C index 032a5b011a..c976a3f364 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C @@ -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. @@ -29,6 +29,7 @@ License // OpenFOAM includes #include "blockMesh.H" #include "Time.H" +#include "foamVtkTools.H" // VTK includes #include "vtkCellArray.h" @@ -255,7 +256,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners auto vtkmesh = vtkSmartPointer::New(); vtkmesh->SetPoints(vtkpoints); - vtkmesh->SetVerts(foamPvCore::identityVertices(blkPoints.size())); + vtkmesh->SetVerts(vtk::Tools::identityVertices(blkPoints.size())); addToBlock(output, vtkmesh, range, datasetNo, range.name()); ++datasetNo; diff --git a/src/conversion/vtk/adaptor/foamVtkTools.H b/src/conversion/vtk/adaptor/foamVtkTools.H new file mode 100644 index 0000000000..b246e3edf8 --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkTools.H @@ -0,0 +1,285 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017-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 . + +Class + Foam::vtk::Tools + +Description + A collection of static methods to assist converting OpenFOAM data + structures into VTK internal data structures. + +Note + The class is implemented as headers-only. + +SourceFiles + foamVtkToolsI.H + foamVtkToolsTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkTools_H +#define foamVtkTools_H + +#include "labelList.H" +#include "faceList.H" +#include "pointField.H" +#include "symmTensor.H" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace vtk +{ + +/*---------------------------------------------------------------------------*\ + Class vtk::Caching Declaration +\*---------------------------------------------------------------------------*/ + + +//- 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 timesteps etc. +template +struct Caching +{ + typedef DataType dataType; + + //- The geometry, without any cell/point data + vtkSmartPointer vtkgeom; + + //- The shallow-copy of geometry, plus additional data + vtkSmartPointer dataset; + + //- Number of points associated with the 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 getCopy() const + { + auto copy = vtkSmartPointer::New(); + if (vtkgeom) + { + copy->ShallowCopy(vtkgeom); + } + return copy; + } + + //- Make a shallow copy of vtkgeom into dataset + void reuse() + { + dataset = vtkSmartPointer::New(); + if (vtkgeom) + { + dataset->ShallowCopy(vtkgeom); + } + } + + //- Set the geometry and make a shallow copy to dataset + void set(vtkSmartPointer 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; + } +}; + + +/*---------------------------------------------------------------------------*\ + Class vtk::Tools Declaration +\*---------------------------------------------------------------------------*/ + +class Tools +{ +public: + + //- Wrap vtkUnsignedCharArray as a UList + inline static UList asUList + ( + vtkUnsignedCharArray* array, + const label size + ); + + //- Wrap vtkIdTypeArray as a UList + inline static UList asUList + ( + vtkIdTypeArray* array, + const label size + ); + + //- Wrap vtkCellArray as a UList + inline static UList asUList + ( + vtkCellArray* cells, + const label nCells, + const label size + ); + + + //- Convert OpenFOAM patch to vtkPolyData + struct Patch + { + //- Convert local patch points to vtkPoints + template + static vtkSmartPointer points(const PatchType& p); + + //- Convert patch faces to vtk polygon cells + template + static vtkSmartPointer faces(const PatchType& p); + + //- Convert patch points/faces to vtkPolyData + template + static vtkSmartPointer mesh(const PatchType& p); + }; + + + //- Remapping for some OpenFOAM data types + template + inline static void remapTuple(float vec[]) {} + + //- Remapping for some OpenFOAM data types + template + inline static void remapTuple(double vec[]) {} + + // Field Conversion Functions + + //- Copy list to pre-allocated vtk array. + // \return number of input items copied + template + static label transcribeFloatData + ( + vtkFloatArray* array, + const UList& input, + const label start = 0 + ); + + //- Create named field initialized to zero + template + static vtkSmartPointer zeroField + ( + const word& name, + const label size + ); + + //- Convert field data to a vtkFloatArray + template + static vtkSmartPointer convertFieldToVTK + ( + const word& name, + const UList& fld + ); + + //- An identity list of VTK_VERTEX + static inline vtkSmartPointer identityVertices + ( + const label size + ); +}; + + +//- Template specialization for symmTensor +template<> +inline void Foam::vtk::Tools::remapTuple(float vec[]) +{ + std::swap(vec[1], vec[3]); // swap XY <-> YY + std::swap(vec[2], vec[5]); // swap XZ <-> ZZ +} + + +//- Template specialization for symmTensor +template<> +inline void Foam::vtk::Tools::remapTuple(double vec[]) +{ + std::swap(vec[1], vec[3]); // swap XY <-> YY + std::swap(vec[2], vec[5]); // swap XZ <-> ZZ +} + + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace vtk +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "foamVtkToolsI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "foamVtkToolsTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkToolsI.H b/src/conversion/vtk/adaptor/foamVtkToolsI.H new file mode 100644 index 0000000000..f93b2c7d55 --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkToolsI.H @@ -0,0 +1,90 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017-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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +inline Foam::UList Foam::vtk::Tools::asUList +( + vtkUnsignedCharArray* array, + const label size +) +{ + array->SetNumberOfComponents(1); + array->SetNumberOfTuples(size); + + return UList(array->WritePointer(0, size), size); +} + + +inline Foam::UList Foam::vtk::Tools::asUList +( + vtkIdTypeArray* array, + const label size +) +{ + array->SetNumberOfComponents(1); + array->SetNumberOfTuples(size); + + return UList(array->WritePointer(0, size), size); +} + + +inline Foam::UList Foam::vtk::Tools::asUList +( + vtkCellArray* cells, + const label nCells, + const label size +) +{ + cells->GetData()->SetNumberOfTuples(size); + + return UList(cells->WritePointer(nCells, size), size); +} + + +inline vtkSmartPointer Foam::vtk::Tools::identityVertices +( + const label size +) +{ + // VTK_VERTEX: need 2 values (size=1 and index=id) per vertex + auto cells = vtkSmartPointer::New(); + + UList list = asUList(cells, size, 2*size); + + // Cell connectivity for vertex + // [size, ids.., size, ids...] -> therefore [1, id, 1, id, ...] + auto iter = list.begin(); + for (label id=0; id < size; ++id) + { + *(iter++) = 1; + *(iter++) = id; + } + + return cells; +}; + + +// ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C new file mode 100644 index 0000000000..ef9ff93c4d --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C @@ -0,0 +1,229 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017-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 . + +InClass + Foam::vtk::Tools + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkToolsTemplates_C +#define foamVtkToolsTemplates_C + +// OpenFOAM includes +#include "error.H" + +// VTK includes +#include +#include +#include +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +vtkSmartPointer +Foam::vtk::Tools::Patch::points(const PatchType& p) +{ + // Local patch points to vtkPoints + const pointField& pts = p.localPoints(); + + auto vtkpoints = vtkSmartPointer::New(); + + vtkpoints->SetNumberOfPoints(pts.size()); + vtkIdType pointId = 0; + + for (const point& p : pts) + { + vtkpoints->SetPoint(pointId, p.v_); + ++pointId; + } + + return vtkpoints; +} + + +template +vtkSmartPointer +Foam::vtk::Tools::Patch::faces(const PatchType& p) +{ + // Faces as polygons + const faceList& fcs = p.localFaces(); + + label nAlloc = fcs.size(); + for (const face& f : fcs) + { + nAlloc += f.size(); + } + + auto vtkcells = vtkSmartPointer::New(); + + UList list = asUList(vtkcells, fcs.size(), nAlloc); + + // Cell connectivity for polygons + // [size, verts..., size, verts... ] + auto iter = list.begin(); + for (const face& f : fcs) + { + *(iter++) = f.size(); + + for (const label verti : f) + { + *(iter++) = verti; + } + } + + return vtkcells; +} + + +template +vtkSmartPointer +Foam::vtk::Tools::Patch::mesh(const PatchType& p) +{ + auto vtkmesh = vtkSmartPointer::New(); + + vtkmesh->SetPoints(points(p)); + vtkmesh->SetPolys(faces(p)); + + return vtkmesh; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// Low-Level conversions +// + +template +Foam::label Foam::vtk::Tools::transcribeFloatData +( + vtkFloatArray* array, + const UList& input, + const label start +) +{ + const int nComp(pTraits::nComponents); + + if (array->GetNumberOfComponents() != nComp) + { + FatalErrorInFunction + << "vtk array '" << array->GetName() + << "' has mismatch in number of components for type '" + << pTraits::typeName + << "' : target array has " << array->GetNumberOfComponents() + << " components instead of " << nComp + << nl; + } + + const vtkIdType maxSize = array->GetNumberOfTuples(); + const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size()); + + if (!maxSize) + { + // no-op + return 0; + } + else if (start < 0 || vtkIdType(start) >= maxSize) + { + WarningInFunction + << "vtk array '" << array->GetName() + << "' copy with out-of-range [0," << long(maxSize) << ")" + << " starting at " << start + << nl; + + return 0; + } + else if (endPos > maxSize) + { + WarningInFunction + << "vtk array '" << array->GetName() + << "' copy ends out-of-range (" << long(maxSize) << ")" + << " using sizing (start,size) = (" + << start << "," << input.size() << ")" + << nl; + + return 0; + } + + float scratch[nComp]; + forAll(input, idx) + { + const Type& t = input[idx]; + for (direction d=0; d(scratch); + + array->SetTuple(start+idx, scratch); + } + + return input.size(); +} + + +template +vtkSmartPointer +Foam::vtk::Tools::zeroField +( + const word& name, + const label size +) +{ + auto data = vtkSmartPointer::New(); + + data->SetName(name.c_str()); + data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfTuples(size); + + data->Fill(0); + + return data; +} + + +template +vtkSmartPointer +Foam::vtk::Tools::convertFieldToVTK +( + const word& name, + const UList& fld +) +{ + auto data = vtkSmartPointer::New(); + + data->SetName(name.c_str()); + data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfTuples(fld.size()); + + transcribeFloatData(data, fld); + + return data; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From 795bdfb2f1d5dd9b62946bfe306dbd3a46bccb00 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 3 Apr 2018 19:07:35 +0200 Subject: [PATCH 2/2] SUBMODULE: catalyst function object --- .gitmodules | 3 +++ modules/catalyst | 1 + 2 files changed, 4 insertions(+) create mode 160000 modules/catalyst diff --git a/.gitmodules b/.gitmodules index 592cb24277..d0186d99a3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "avalanche"] path = modules/avalanche url = https://develop.openfoam.com/Community/avalanche.git +[submodule "modules/catalyst"] + path = modules/catalyst + url = https://develop.openfoam.com/Community/catalyst.git diff --git a/modules/catalyst b/modules/catalyst new file mode 160000 index 0000000000..fe7832cf63 --- /dev/null +++ b/modules/catalyst @@ -0,0 +1 @@ +Subproject commit fe7832cf638ca452bae799ce953464d21cb2e735