mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: code cleanup for vtk transcription
- use cellCentres() instead of volField equivalent for vtk conversion - make looping variables more consistent - centralize the transcription of OpenFOAM -> vtk tuples
This commit is contained in:
@ -40,11 +40,11 @@ InClass
|
|||||||
#include "areaFaMesh.H"
|
#include "areaFaMesh.H"
|
||||||
#include "areaFields.H"
|
#include "areaFields.H"
|
||||||
|
|
||||||
// vtk includes
|
// VTK includes
|
||||||
#include "vtkFloatArray.h"
|
#include <vtkFloatArray.h>
|
||||||
#include "vtkCellData.h"
|
#include <vtkCellData.h>
|
||||||
#include "vtkPointData.h"
|
#include <vtkPointData.h>
|
||||||
#include "vtkSmartPointer.h"
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
//
|
//
|
||||||
@ -68,10 +68,8 @@ void Foam::vtkPVFoam::convertVolField
|
|||||||
autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr;
|
autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr;
|
||||||
if (interpField)
|
if (interpField)
|
||||||
{
|
{
|
||||||
if (debug)
|
DebugInfo
|
||||||
{
|
<< "convertVolField interpolating:" << fld.name() << nl;
|
||||||
Info<< "convertVolField interpolating:" << fld.name() << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptfPtr.reset
|
ptfPtr.reset
|
||||||
(
|
(
|
||||||
@ -102,7 +100,7 @@ void Foam::vtkPVFoam::convertVolField
|
|||||||
foamVtpData& vtpData = iter.object();
|
foamVtpData& vtpData = iter.object();
|
||||||
auto dataset = vtpData.dataset;
|
auto dataset = vtpData.dataset;
|
||||||
|
|
||||||
const labelList& patchIds = vtpData.additionalIds();
|
const labelUList& patchIds = vtpData.additionalIds();
|
||||||
|
|
||||||
if (patchIds.empty())
|
if (patchIds.empty())
|
||||||
{
|
{
|
||||||
@ -291,13 +289,13 @@ void Foam::vtkPVFoam::convertVolFields
|
|||||||
catch (Foam::IOerror& ioErr)
|
catch (Foam::IOerror& ioErr)
|
||||||
{
|
{
|
||||||
ioErr.write(Warning, false);
|
ioErr.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
catch (Foam::error& err)
|
catch (Foam::error& err)
|
||||||
{
|
{
|
||||||
// Bit of trickery to get the original message
|
// Bit of trickery to get the original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous exception throwing state
|
// Restore previous exception throwing state
|
||||||
@ -373,13 +371,13 @@ void Foam::vtkPVFoam::convertDimFields
|
|||||||
catch (Foam::IOerror& ioErr)
|
catch (Foam::IOerror& ioErr)
|
||||||
{
|
{
|
||||||
ioErr.write(Warning, false);
|
ioErr.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
catch (Foam::error& err)
|
catch (Foam::error& err)
|
||||||
{
|
{
|
||||||
// Bit of trickery to get the original message
|
// Bit of trickery to get the original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous exception throwing state
|
// Restore previous exception throwing state
|
||||||
@ -501,13 +499,13 @@ void Foam::vtkPVFoam::convertAreaFields
|
|||||||
catch (Foam::IOerror& ioErr)
|
catch (Foam::IOerror& ioErr)
|
||||||
{
|
{
|
||||||
ioErr.write(Warning, false);
|
ioErr.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
catch (Foam::error& err)
|
catch (Foam::error& err)
|
||||||
{
|
{
|
||||||
// Bit of trickery to get the original message
|
// Bit of trickery to get the original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous exception throwing state
|
// Restore previous exception throwing state
|
||||||
@ -545,10 +543,8 @@ void Foam::vtkPVFoam::convertPointFields
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
DebugInfo
|
||||||
{
|
<< "convertPointFields : " << fieldName << nl;
|
||||||
Info<< "convertPointFields : " << fieldName << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Throw FatalError, FatalIOError as exceptions
|
// Throw FatalError, FatalIOError as exceptions
|
||||||
const bool throwingError = FatalError.throwExceptions();
|
const bool throwingError = FatalError.throwExceptions();
|
||||||
@ -581,7 +577,7 @@ void Foam::vtkPVFoam::convertPointFields
|
|||||||
foamVtpData& vtpData = iter.object();
|
foamVtpData& vtpData = iter.object();
|
||||||
auto dataset = vtpData.dataset;
|
auto dataset = vtpData.dataset;
|
||||||
|
|
||||||
const labelList& patchIds = vtpData.additionalIds();
|
const labelUList& patchIds = vtpData.additionalIds();
|
||||||
if (patchIds.size() != 1)
|
if (patchIds.size() != 1)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -645,13 +641,13 @@ void Foam::vtkPVFoam::convertPointFields
|
|||||||
catch (Foam::IOerror& ioErr)
|
catch (Foam::IOerror& ioErr)
|
||||||
{
|
{
|
||||||
ioErr.write(Warning, false);
|
ioErr.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
catch (Foam::error& err)
|
catch (Foam::error& err)
|
||||||
{
|
{
|
||||||
// Bit of trickery to get the original message
|
// Bit of trickery to get the original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous exception throwing state
|
// Restore previous exception throwing state
|
||||||
@ -706,7 +702,6 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
|||||||
const foamVtuData& vtuData
|
const foamVtuData& vtuData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nComp(pTraits<Type>::nComponents);
|
|
||||||
const labelUList& addPointCellLabels = vtuData.additionalIds();
|
const labelUList& addPointCellLabels = vtuData.additionalIds();
|
||||||
const labelUList& pointMap = vtuData.pointMap();
|
const labelUList& pointMap = vtuData.pointMap();
|
||||||
|
|
||||||
@ -714,7 +709,7 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
|||||||
const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size());
|
const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size());
|
||||||
|
|
||||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||||
data->SetNumberOfComponents(nComp);
|
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
|
||||||
data->SetNumberOfTuples(nPoints + addPointCellLabels.size());
|
data->SetNumberOfTuples(nPoints + addPointCellLabels.size());
|
||||||
|
|
||||||
// Note: using the name of the original volField
|
// Note: using the name of the original volField
|
||||||
@ -729,75 +724,54 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
|||||||
data->SetName(pfld.name().c_str());
|
data->SetName(pfld.name().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
DebugInfo
|
||||||
{
|
<< "Convert point field: " << pfld.name()
|
||||||
Info<< "convert Point field: "
|
<< " size=" << (nPoints + addPointCellLabels.size())
|
||||||
<< pfld.name()
|
<< " (" << nPoints << " + " << addPointCellLabels.size()
|
||||||
<< " size=" << (nPoints + addPointCellLabels.size())
|
<< ") nComp=" << static_cast<int>(pTraits<Type>::nComponents) << nl;
|
||||||
<< " (" << nPoints << " + " << addPointCellLabels.size()
|
|
||||||
<< ") nComp=" << nComp << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
float vec[nComp];
|
|
||||||
|
|
||||||
label pointi = 0;
|
float scratch[pTraits<Type>::nComponents];
|
||||||
|
|
||||||
|
vtkIdType pointi = 0;
|
||||||
if (pointMap.size())
|
if (pointMap.size())
|
||||||
{
|
{
|
||||||
forAll(pointMap, i)
|
for (const label meshPointi : pointMap)
|
||||||
{
|
{
|
||||||
const Type& t = pfld[pointMap[i]];
|
vtk::Tools::foamToVtkTuple(scratch, pfld[meshPointi]);
|
||||||
for (direction d=0; d<nComp; ++d)
|
data->SetTuple(pointi++, scratch);
|
||||||
{
|
|
||||||
vec[d] = component(t, d);
|
|
||||||
}
|
|
||||||
remapTuple<Type>(vec);
|
|
||||||
|
|
||||||
data->SetTuple(pointi++, vec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
forAll(pfld, i)
|
for (const Type& val : pfld)
|
||||||
{
|
{
|
||||||
const Type& t = pfld[i];
|
vtk::Tools::foamToVtkTuple(scratch, val);
|
||||||
for (direction d=0; d<nComp; ++d)
|
data->SetTuple(pointi++, scratch);
|
||||||
{
|
|
||||||
vec[d] = component(t, d);
|
|
||||||
}
|
|
||||||
remapTuple<Type>(vec);
|
|
||||||
|
|
||||||
data->SetTuple(pointi++, vec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with additional points
|
// Continue with additional points
|
||||||
|
// - correspond to cell centres
|
||||||
|
|
||||||
if (notNull(vfld))
|
if (notNull(vfld))
|
||||||
{
|
{
|
||||||
forAll(addPointCellLabels, apI)
|
for (const label meshCelli : addPointCellLabels)
|
||||||
{
|
{
|
||||||
const Type& t = vfld[addPointCellLabels[apI]];
|
vtk::Tools::foamToVtkTuple(scratch, vfld[meshCelli]);
|
||||||
for (direction d=0; d<nComp; ++d)
|
data->SetTuple(pointi++, scratch);
|
||||||
{
|
|
||||||
vec[d] = component(t, d);
|
|
||||||
}
|
|
||||||
remapTuple<Type>(vec);
|
|
||||||
|
|
||||||
data->SetTuple(pointi++, vec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
forAll(addPointCellLabels, apI)
|
for (const label meshCelli : addPointCellLabels)
|
||||||
{
|
{
|
||||||
Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]);
|
vtk::Tools::foamToVtkTuple
|
||||||
for (direction d=0; d<nComp; ++d)
|
(
|
||||||
{
|
scratch,
|
||||||
vec[d] = component(t, d);
|
interpolatePointToCell(pfld, meshCelli)
|
||||||
}
|
);
|
||||||
remapTuple<Type>(vec);
|
data->SetTuple(pointi++, scratch);
|
||||||
|
|
||||||
data->SetTuple(pointi++, vec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,13 +820,13 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
|||||||
catch (Foam::IOerror& ioErr)
|
catch (Foam::IOerror& ioErr)
|
||||||
{
|
{
|
||||||
ioErr.write(Warning, false);
|
ioErr.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
catch (Foam::error& err)
|
catch (Foam::error& err)
|
||||||
{
|
{
|
||||||
// Bit of trickery to get the original message
|
// Bit of trickery to get the original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info << nl << endl;
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous exception throwing state
|
// Restore previous exception throwing state
|
||||||
@ -876,53 +850,44 @@ Foam::vtkPVFoam::convertFaceFieldToVTK
|
|||||||
const labelUList& faceLabels
|
const labelUList& faceLabels
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (debug)
|
DebugInfo
|
||||||
{
|
<< "Convert face field: " << fld.name()
|
||||||
Info<< "convert face field: "
|
<< " size=" << faceLabels.size()
|
||||||
<< fld.name()
|
<< " nComp=" << static_cast<int>(pTraits<Type>::nComponents) << nl;
|
||||||
<< " size=" << faceLabels.size()
|
|
||||||
<< " nComp=" << int(pTraits<Type>::nComponents) << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fvMesh& mesh = fld.mesh();
|
const fvMesh& mesh = fld.mesh();
|
||||||
|
|
||||||
const int nComp(pTraits<Type>::nComponents);
|
|
||||||
const label nInternalFaces = mesh.nInternalFaces();
|
const label nInternalFaces = mesh.nInternalFaces();
|
||||||
const labelList& faceOwner = mesh.faceOwner();
|
const labelUList& faceOwner = mesh.faceOwner();
|
||||||
const labelList& faceNeigh = mesh.faceNeighbour();
|
const labelUList& faceNeigh = mesh.faceNeighbour();
|
||||||
|
|
||||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||||
data->SetName(fld.name().c_str());
|
data->SetName(fld.name().c_str());
|
||||||
data->SetNumberOfComponents(nComp);
|
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
|
||||||
data->SetNumberOfTuples(faceLabels.size());
|
data->SetNumberOfTuples(faceLabels.size());
|
||||||
|
|
||||||
float scratch[nComp];
|
|
||||||
|
|
||||||
// Interior faces: average owner/neighbour
|
// Interior faces: average owner/neighbour
|
||||||
// Boundary faces: the owner value
|
// Boundary faces: the owner value
|
||||||
forAll(faceLabels, idx)
|
|
||||||
{
|
|
||||||
const label faceNo = faceLabels[idx];
|
|
||||||
if (faceNo < nInternalFaces)
|
|
||||||
{
|
|
||||||
Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]);
|
|
||||||
|
|
||||||
for (direction d=0; d<nComp; ++d)
|
float scratch[pTraits<Type>::nComponents];
|
||||||
{
|
|
||||||
scratch[d] = component(t, d);
|
vtkIdType faceId = 0;
|
||||||
}
|
for (const label meshFacei : faceLabels)
|
||||||
|
{
|
||||||
|
if (meshFacei < nInternalFaces)
|
||||||
|
{
|
||||||
|
Type val =
|
||||||
|
0.5*(fld[faceOwner[meshFacei]] + fld[faceNeigh[meshFacei]]);
|
||||||
|
|
||||||
|
vtk::Tools::foamToVtkTuple(scratch, val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const Type& t = fld[faceOwner[faceNo]];
|
const Type& val = fld[faceOwner[meshFacei]];
|
||||||
for (direction d=0; d<nComp; ++d)
|
vtk::Tools::foamToVtkTuple(scratch, val);
|
||||||
{
|
|
||||||
scratch[d] = component(t, d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
remapTuple<Type>(scratch);
|
|
||||||
|
|
||||||
data->SetTuple(idx, scratch);
|
data->SetTuple(faceId++, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -937,35 +902,26 @@ Foam::vtkPVFoam::convertVolFieldToVTK
|
|||||||
const foamVtuData& vtuData
|
const foamVtuData& vtuData
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const int nComp(pTraits<Type>::nComponents);
|
|
||||||
const labelUList& cellMap = vtuData.cellMap();
|
const labelUList& cellMap = vtuData.cellMap();
|
||||||
|
|
||||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||||
data->SetName(fld.name().c_str());
|
data->SetName(fld.name().c_str());
|
||||||
data->SetNumberOfComponents(nComp);
|
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
|
||||||
data->SetNumberOfTuples(cellMap.size());
|
data->SetNumberOfTuples(cellMap.size());
|
||||||
|
|
||||||
if (debug)
|
DebugInfo
|
||||||
{
|
<< "Convert volField: " << fld.name() << " size="
|
||||||
Info<< "convert volField: "
|
<< cellMap.size() << " (field "
|
||||||
<< fld.name()
|
<< fld.size() << ") nComp="
|
||||||
<< " size=" << cellMap.size()
|
<< static_cast<int>(pTraits<Type>::nComponents) << nl;
|
||||||
<< " (" << fld.size() << " + "
|
|
||||||
<< (cellMap.size() - fld.size())
|
|
||||||
<< ") nComp=" << nComp << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
float scratch[nComp];
|
float scratch[pTraits<Type>::nComponents];
|
||||||
forAll(cellMap, idx)
|
|
||||||
{
|
|
||||||
const Type& t = fld[cellMap[idx]];
|
|
||||||
for (direction d=0; d<nComp; ++d)
|
|
||||||
{
|
|
||||||
scratch[d] = component(t, d);
|
|
||||||
}
|
|
||||||
remapTuple<Type>(scratch);
|
|
||||||
|
|
||||||
data->SetTuple(idx, scratch);
|
vtkIdType celli = 0;
|
||||||
|
for (const label meshCelli : cellMap)
|
||||||
|
{
|
||||||
|
vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]);
|
||||||
|
data->SetTuple(celli++, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@ -172,7 +172,7 @@ void Foam::vtkPVFoam::convertMeshPatches()
|
|||||||
{
|
{
|
||||||
// Point movement on single patch is OK
|
// Point movement on single patch is OK
|
||||||
|
|
||||||
const labelList& patchIds = vtpData.additionalIds();
|
const labelUList& patchIds = vtpData.additionalIds();
|
||||||
if (patchIds.size() == 1)
|
if (patchIds.size() == 1)
|
||||||
{
|
{
|
||||||
vtkgeom = vtpData.getCopy();
|
vtkgeom = vtpData.getCopy();
|
||||||
|
|||||||
@ -49,23 +49,21 @@ vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
|
|||||||
const pointField& pts = mesh.points();
|
const pointField& pts = mesh.points();
|
||||||
|
|
||||||
// Additional cell centres
|
// Additional cell centres
|
||||||
const labelList& addPoints = this->additionalIds();
|
const labelUList& addPoints = this->additionalIds();
|
||||||
|
|
||||||
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
|
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
|
||||||
|
|
||||||
// Normal points
|
// Normal points
|
||||||
label pointId = 0;
|
vtkIdType pointId = 0;
|
||||||
for (const point& p : pts)
|
for (const point& p : pts)
|
||||||
{
|
{
|
||||||
vtkpoints->SetPoint(pointId, p.v_);
|
vtkpoints->SetPoint(pointId++, p.v_);
|
||||||
++pointId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cell centres
|
// Cell centres
|
||||||
for (const label ptId : addPoints)
|
for (const label meshCelli : addPoints)
|
||||||
{
|
{
|
||||||
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
|
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
|
||||||
++pointId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vtkpoints;
|
return vtkpoints;
|
||||||
@ -85,23 +83,21 @@ vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
|
|||||||
const pointField& pts = mesh.points();
|
const pointField& pts = mesh.points();
|
||||||
|
|
||||||
// Additional cell centres
|
// Additional cell centres
|
||||||
const labelList& addPoints = this->additionalIds();
|
const labelUList& addPoints = this->additionalIds();
|
||||||
|
|
||||||
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
|
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
|
||||||
|
|
||||||
// Normal points
|
// Normal points
|
||||||
label pointId = 0;
|
vtkIdType pointId = 0;
|
||||||
for (const label ptId : pointMap)
|
for (const label meshPointi : pointMap)
|
||||||
{
|
{
|
||||||
vtkpoints->SetPoint(pointId, pts[ptId].v_);
|
vtkpoints->SetPoint(pointId++, pts[meshPointi].v_);
|
||||||
++pointId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cell centres
|
// Cell centres
|
||||||
for (const label ptId : addPoints)
|
for (const label meshCelli : addPoints)
|
||||||
{
|
{
|
||||||
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
|
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
|
||||||
++pointId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vtkpoints;
|
return vtkpoints;
|
||||||
|
|||||||
@ -49,6 +49,7 @@ SourceFiles
|
|||||||
#include "pointField.H"
|
#include "pointField.H"
|
||||||
#include "symmTensor.H"
|
#include "symmTensor.H"
|
||||||
|
|
||||||
|
// VTK includes
|
||||||
#include <vtkCellArray.h>
|
#include <vtkCellArray.h>
|
||||||
#include <vtkFloatArray.h>
|
#include <vtkFloatArray.h>
|
||||||
#include <vtkDoubleArray.h>
|
#include <vtkDoubleArray.h>
|
||||||
@ -209,13 +210,36 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Remapping for some OpenFOAM data types (eg, symmTensor)
|
//- Remapping for some OpenFOAM data types (eg, symmTensor)
|
||||||
|
// \param data[in,out] The data to be remapped in-place
|
||||||
template<class Type>
|
template<class Type>
|
||||||
inline static void remapTuple(float data[]) {}
|
inline static void remapTuple(float data[]) {}
|
||||||
|
|
||||||
//- Remapping for some OpenFOAM data types (eg, symmTensor)
|
//- Remapping for some OpenFOAM data types (eg, symmTensor)
|
||||||
|
// \param data[in,out] The data to be remapped in-place
|
||||||
template<class Type>
|
template<class Type>
|
||||||
inline static void remapTuple(double data[]) {}
|
inline static void remapTuple(double data[]) {}
|
||||||
|
|
||||||
|
//- Copy/transcribe OpenFOAM data types to VTK format
|
||||||
|
// This allows a change of data type (float vs double) as well as
|
||||||
|
// addressing any swapping issues (eg, symmTensor)
|
||||||
|
//
|
||||||
|
// \param output[out] The output scratch space. Must be long enough
|
||||||
|
// to hold the result.
|
||||||
|
// \param val[in] The input data to copy/transcribe
|
||||||
|
template<class Type>
|
||||||
|
inline static void foamToVtkTuple(float output[], const Type& val);
|
||||||
|
|
||||||
|
//- Copy/transcribe OpenFOAM data types to VTK format
|
||||||
|
// This allows a change of data type (float vs double) as well as
|
||||||
|
// addressing any swapping issues (eg, symmTensor)
|
||||||
|
//
|
||||||
|
// \param output[out] The output scratch space. Must be long enough
|
||||||
|
// to hold the result.
|
||||||
|
// \param val[in] The input data to copy/transcribe
|
||||||
|
template<class Type>
|
||||||
|
inline static void foamToVtkTuple(double output[], const Type& val);
|
||||||
|
|
||||||
|
|
||||||
// Field Conversion Functions
|
// Field Conversion Functions
|
||||||
|
|
||||||
//- Copy list to pre-allocated vtk array.
|
//- Copy list to pre-allocated vtk array.
|
||||||
@ -225,7 +249,7 @@ public:
|
|||||||
(
|
(
|
||||||
vtkFloatArray* array,
|
vtkFloatArray* array,
|
||||||
const UList<Type>& input,
|
const UList<Type>& input,
|
||||||
const label start = 0
|
vtkIdType start = 0 //!< The write offset into output array
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Create named field initialized to zero
|
//- Create named field initialized to zero
|
||||||
@ -270,7 +294,6 @@ inline void Foam::vtk::Tools::remapTuple<Foam::symmTensor>(double data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace vtk
|
} // End namespace vtk
|
||||||
|
|||||||
@ -87,4 +87,34 @@ inline vtkSmartPointer<vtkCellArray> Foam::vtk::Tools::identityVertices
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
inline void Foam::vtk::Tools::foamToVtkTuple
|
||||||
|
(
|
||||||
|
float output[],
|
||||||
|
const Type& val
|
||||||
|
)
|
||||||
|
{
|
||||||
|
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||||
|
{
|
||||||
|
output[cmpt] = component(val, cmpt);
|
||||||
|
}
|
||||||
|
remapTuple<Type>(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
inline void Foam::vtk::Tools::foamToVtkTuple
|
||||||
|
(
|
||||||
|
double output[],
|
||||||
|
const Type& val
|
||||||
|
)
|
||||||
|
{
|
||||||
|
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||||
|
{
|
||||||
|
output[cmpt] = component(val, cmpt);
|
||||||
|
}
|
||||||
|
remapTuple<Type>(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -50,12 +50,11 @@ Foam::vtk::Tools::Patch::points(const PatchType& p)
|
|||||||
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||||
|
|
||||||
vtkpoints->SetNumberOfPoints(pts.size());
|
vtkpoints->SetNumberOfPoints(pts.size());
|
||||||
vtkIdType pointId = 0;
|
|
||||||
|
|
||||||
|
vtkIdType pointId = 0;
|
||||||
for (const point& p : pts)
|
for (const point& p : pts)
|
||||||
{
|
{
|
||||||
vtkpoints->SetPoint(pointId, p.v_);
|
vtkpoints->SetPoint(pointId++, p.v_);
|
||||||
++pointId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vtkpoints;
|
return vtkpoints;
|
||||||
@ -127,8 +126,7 @@ Foam::vtk::Tools::Patch::faceNormals(const PatchType& p)
|
|||||||
vtkIdType faceId = 0;
|
vtkIdType faceId = 0;
|
||||||
for (const vector& n : norms)
|
for (const vector& n : norms)
|
||||||
{
|
{
|
||||||
array->SetTuple(faceId, n.v_);
|
array->SetTuple(faceId++, n.v_);
|
||||||
++faceId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
@ -145,7 +143,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData
|
|||||||
(
|
(
|
||||||
vtkFloatArray* array,
|
vtkFloatArray* array,
|
||||||
const UList<Type>& input,
|
const UList<Type>& input,
|
||||||
const label start
|
vtkIdType start
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nComp(pTraits<Type>::nComponents);
|
const int nComp(pTraits<Type>::nComponents);
|
||||||
@ -162,7 +160,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vtkIdType maxSize = array->GetNumberOfTuples();
|
const vtkIdType maxSize = array->GetNumberOfTuples();
|
||||||
const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size());
|
const vtkIdType endPos = start + vtkIdType(input.size());
|
||||||
|
|
||||||
if (!maxSize)
|
if (!maxSize)
|
||||||
{
|
{
|
||||||
@ -174,7 +172,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData
|
|||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "vtk array '" << array->GetName()
|
<< "vtk array '" << array->GetName()
|
||||||
<< "' copy with out-of-range [0," << long(maxSize) << ")"
|
<< "' copy with out-of-range [0," << long(maxSize) << ")"
|
||||||
<< " starting at " << start
|
<< " starting at " << long(start)
|
||||||
<< nl;
|
<< nl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -185,23 +183,18 @@ Foam::label Foam::vtk::Tools::transcribeFloatData
|
|||||||
<< "vtk array '" << array->GetName()
|
<< "vtk array '" << array->GetName()
|
||||||
<< "' copy ends out-of-range (" << long(maxSize) << ")"
|
<< "' copy ends out-of-range (" << long(maxSize) << ")"
|
||||||
<< " using sizing (start,size) = ("
|
<< " using sizing (start,size) = ("
|
||||||
<< start << "," << input.size() << ")"
|
<< long(start) << "," << input.size() << ")"
|
||||||
<< nl;
|
<< nl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float scratch[nComp];
|
float scratch[pTraits<Type>::nComponents];
|
||||||
forAll(input, idx)
|
|
||||||
{
|
|
||||||
const Type& t = input[idx];
|
|
||||||
for (direction d=0; d<nComp; ++d)
|
|
||||||
{
|
|
||||||
scratch[d] = component(t, d);
|
|
||||||
}
|
|
||||||
remapTuple<Type>(scratch);
|
|
||||||
|
|
||||||
array->SetTuple(start+idx, scratch);
|
for (const Type& val : input)
|
||||||
|
{
|
||||||
|
foamToVtkTuple(scratch, val);
|
||||||
|
array->SetTuple(start++, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.size();
|
return input.size();
|
||||||
@ -219,7 +212,7 @@ Foam::vtk::Tools::zeroField
|
|||||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||||
|
|
||||||
data->SetName(name.c_str());
|
data->SetName(name.c_str());
|
||||||
data->SetNumberOfComponents(int(pTraits<Type>::nComponents));
|
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
|
||||||
data->SetNumberOfTuples(size);
|
data->SetNumberOfTuples(size);
|
||||||
|
|
||||||
data->Fill(0);
|
data->Fill(0);
|
||||||
@ -239,7 +232,7 @@ Foam::vtk::Tools::convertFieldToVTK
|
|||||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||||
|
|
||||||
data->SetName(name.c_str());
|
data->SetName(name.c_str());
|
||||||
data->SetNumberOfComponents(int(pTraits<Type>::nComponents));
|
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
|
||||||
data->SetNumberOfTuples(fld.size());
|
data->SetNumberOfTuples(fld.size());
|
||||||
|
|
||||||
transcribeFloatData(data, fld);
|
transcribeFloatData(data, fld);
|
||||||
|
|||||||
Reference in New Issue
Block a user