...
 
Commits (2)
......@@ -43,16 +43,15 @@ void Foam::vtk::faMeshAdaptor::convertAreaFields
const wordRes& selectFields
)
{
typedef GeometricField<Type, faPatchField, areaMesh> FieldType;
const auto& obr = mesh_.mesh();
// Restrict to GeometricField<Type, ...>
const wordList names(mesh_.mesh().sortedNames<FieldType>(selectFields));
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
for (const word& fieldName : names)
for (const word& fieldName : obr.sortedNames<fieldType>(selectFields))
{
convertAreaField
(
mesh_.mesh().lookupObject<FieldType>(fieldName)
obr.lookupObject<fieldType>(fieldName)
);
}
}
......@@ -97,37 +96,8 @@ Foam::vtk::faMeshAdaptor::convertAreaFieldToVTK
const foamVtpData& vtpData
) const
{
const int nComp(pTraits<Type>::nComponents);
auto data = vtkSmartPointer<vtkFloatArray>::New();
data->SetName(fld.name().c_str());
data->SetNumberOfComponents(nComp);
data->SetNumberOfTuples(fld.size());
const label len = fld.size();
if (debug)
{
Info<< "convert areaField: "
<< fld.name()
<< " size=" << len
<< " nComp=" << nComp << endl;
}
float scratch[nComp];
for (label i=0; i < len; ++i)
{
const Type& t = fld[i];
for (direction d=0; d<nComp; ++d)
{
scratch[d] = component(t, d);
}
remapTuple<Type>(scratch);
data->SetTuple(i, scratch);
}
return data;
// The vtpData is not used for anything
return vtk::Tools::convertFieldToVTK(fld.name(), fld);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -34,28 +34,6 @@ License
// Templates (only needed here)
#include "foamVtkFaMeshAdaptorFieldTemplates.C"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
static wordHashSet supportedTypes()
{
// typedef DimensionedField<Type, areaMesh> DimFieldType;
typedef GeometricField<Type, faPatchField, areaMesh> AreaFieldType;
wordHashSet types;
// TODO: types.insert(DimFieldType::typeName);
types.insert(AreaFieldType::typeName);
return types;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields
......@@ -63,30 +41,20 @@ Foam::wordHashSet Foam::vtk::faMeshAdaptor::knownFields
const wordRes& selectFields
) const
{
wordHashSet allFields;
// Quick exit if no volume fields can be converted.
// This could be refined
HashTable<wordHashSet> objects = mesh_.mesh().classes(selectFields);
if (objects.empty())
{
return allFields;
}
wordHashSet types;
types += supportedTypes<scalar>();
types += supportedTypes<vector>();
types += supportedTypes<sphericalTensor>();
types += supportedTypes<symmTensor>();
types += supportedTypes<tensor>();
objects.retain(types);
wordHashSet allFields(2*objects.size());
forAllConstIters(objects, iter)
{
allFields += iter.object();
const word& clsName = iter.key();
if (fieldTypes::area.found(clsName))
{
allFields += iter.object();
}
}
return allFields;
......
......@@ -40,19 +40,16 @@ void Foam::vtk::faMeshAdaptor::convertGeometryInternal()
if (meshState_ == polyMesh::UNCHANGED)
{
// Without movement is easy.
if (debug)
{
Info<< "reuse " << longName << nl;
}
DebugInfo
<< "reuse " << longName << nl;
vtpData.reuse();
return;
}
else if (meshState_ == polyMesh::POINTS_MOVED)
{
if (debug)
{
Info<< "move points " << longName << nl;
}
DebugInfo
<< "move points " << longName << nl;
vtkgeom = vtpData.getCopy();
vtkgeom->SetPoints
......@@ -64,10 +61,8 @@ void Foam::vtk::faMeshAdaptor::convertGeometryInternal()
if (!vtkgeom)
{
if (debug)
{
Info<< "Nothing usable from cache - create new geometry" << nl;
}
DebugInfo
<< "Nothing usable from cache - create new geometry" << nl;
vtkgeom = vtk::Tools::Patch::mesh(mesh_.patch());
}
......
......@@ -37,25 +37,28 @@ Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields
const objectRegistry& obr
)
{
const wordList fieldNames(obr.sortedNames<IOField<Type>>());
typedef IOField<Type> fieldType;
for (const word& fieldName : fieldNames)
label nFields = 0;
for (const word& fieldName : obr.sortedNames<fieldType>())
{
const auto& fld = obr.lookupObject<IOField<Type>>(fieldName);
const auto& fld = obr.lookupObject<fieldType>(fieldName);
vtkSmartPointer<vtkFloatArray> data =
vtk::Tools::convertFieldToVTK
(
fieldName,
fld
);
vtkSmartPointer<vtkFloatArray> data = vtk::Tools::convertFieldToVTK
(
fld.name(),
fld
);
// Provide identical data as cell and as point data
vtkmesh->GetCellData()->AddArray(data);
vtkmesh->GetPointData()->AddArray(data);
++nFields;
}
return fieldNames.size();
return nFields;
}
......
......@@ -141,7 +141,6 @@ private:
public vtk::Caching<vtkUnstructuredGrid>,
public foamVtkMeshMaps
{
//- The vtk points for the mesh (and decomposition)
vtkSmartPointer<vtkPoints> points
(
......
......@@ -173,17 +173,20 @@ void Foam::vtk::fvMeshAdaptor::convertVolFields
const wordRes& selectFields
)
{
typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
// Restrict to GeometricField<Type, ...>
const wordList names(mesh_.sortedNames<FieldType>(selectFields));
for (const word& fieldName : names)
for
(
const word& fieldName
: mesh_.sortedNames<fieldType>(selectFields)
)
{
convertVolField
(
patchInterpList,
mesh_.lookupObject<FieldType>(fieldName)
mesh_.lookupObject<fieldType>(fieldName)
);
}
}
......@@ -274,75 +277,50 @@ vtkSmartPointer<vtkFloatArray> Foam::vtk::fvMeshAdaptor::convertPointField
data->SetName(pfld.name().c_str());
}
if (debug)
{
Info<< "convert Point field: "
<< pfld.name()
<< " size=" << (nPoints + addPointCellLabels.size())
<< " (" << nPoints << " + " << addPointCellLabels.size()
<< ") nComp=" << nComp << endl;
}
DebugInfo
<< "convert Point field: " << pfld.name()
<< " size=" << (nPoints + addPointCellLabels.size())
<< " (" << nPoints << " + " << addPointCellLabels.size()
<< ") nComp=" << nComp << endl;
float vec[pTraits<Type>::nComponents];
label pointi = 0;
float scratch[pTraits<Type>::nComponents];
vtkIdType pointi = 0;
if (pointMap.size())
{
forAll(pointMap, i)
for (const label meshPointi : pointMap)
{
const Type& t = pfld[pointMap[i]];
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
remapTuple<Type>(vec);
data->SetTuple(pointi++, vec);
foamToVtkTuple(scratch, pfld[meshPointi]);
data->SetTuple(pointi++, scratch);
}
}
else
{
forAll(pfld, i)
for (const Type& val : pfld)
{
const Type& t = pfld[i];
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
remapTuple<Type>(vec);
data->SetTuple(pointi++, vec);
foamToVtkTuple(scratch, val);
data->SetTuple(pointi++, scratch);
}
}
// Continue with additional points
// - correspond to cell centres
if (notNull(vfld))
{
forAll(addPointCellLabels, apI)
for (const label meshCelli : addPointCellLabels)
{
const Type& t = vfld[addPointCellLabels[apI]];
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
remapTuple<Type>(vec);
data->SetTuple(pointi++, vec);
foamToVtkTuple(scratch, vfld[meshCelli]);
data->SetTuple(pointi++, scratch);
}
}
else
{
forAll(addPointCellLabels, apI)
for (const label meshCelli : addPointCellLabels)
{
Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]);
for (direction d=0; d<nComp; ++d)
{
vec[d] = component(t, d);
}
remapTuple<Type>(vec);
data->SetTuple(pointi++, vec);
foamToVtkTuple(scratch, interpolatePointToCell(pfld, meshCelli));
data->SetTuple(pointi++, scratch);
}
}
......@@ -371,27 +349,21 @@ Foam::vtk::fvMeshAdaptor::convertVolFieldToVTK
data->SetNumberOfComponents(nComp);
data->SetNumberOfTuples(cellMap.size());
if (debug)
{
Info<< "convert volField: "
<< fld.name()
<< " size=" << cellMap.size()
<< " (" << fld.size() << " + "
<< (cellMap.size() - fld.size())
<< ") nComp=" << nComp << endl;
}
DebugInfo
<< "convert volField: " << fld.name()
<< " size=" << cellMap.size()
<< " (" << fld.size() << " + "
<< (cellMap.size() - fld.size())
<< ") nComp=" << nComp << endl;
float scratch[nComp];
forAll(cellMap, i)
{
const Type& t = fld[cellMap[i]];
for (direction d=0; d<nComp; ++d)
{
scratch[d] = component(t, d);
}
remapTuple<Type>(scratch);
data->SetTuple(i, scratch);
float scratch[pTraits<Type>::nComponents];
vtkIdType celli = 0;
for (const label meshCelli : cellMap)
{
foamToVtkTuple(scratch, fld[meshCelli]);
data->SetTuple(celli++, scratch);
}
return data;
......
......@@ -34,55 +34,30 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
static wordHashSet supportedTypes()
{
// typedef DimensionedField<Type, volMesh> DimFieldType;
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
wordHashSet types;
// TODO: types.insert(DimFieldType::typeName);
types.insert(VolFieldType::typeName);
return types;
}
} // End namespace Foam
Foam::wordHashSet Foam::vtk::fvMeshAdaptor::knownFields
(
const wordRes& selectFields
) const
{
wordHashSet allFields;
// Quick exit if no volume fields can be converted.
// This could be refined
HashTable<wordHashSet> objects = mesh_.classes(selectFields);
if (objects.empty())
{
return allFields;
}
wordHashSet types;
types += supportedTypes<scalar>();
types += supportedTypes<vector>();
types += supportedTypes<sphericalTensor>();
types += supportedTypes<symmTensor>();
types += supportedTypes<tensor>();
objects.retain(types);
wordHashSet allFields(2*objects.size());
forAllConstIters(objects, iter)
{
allFields += iter.object();
const word& clsName = iter.key();
if
(
fieldTypes::volume.found(clsName)
// TODO
// || fieldTypes::internal.found(clsName)
)
{
allFields += iter.object();
}
}
return allFields;
......
......@@ -52,19 +52,17 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryInternal()
{
if (meshState_ == polyMesh::UNCHANGED)
{
if (debug)
{
Info<< "reuse " << longName << nl;
}
DebugInfo
<< "reuse " << longName << nl;
vtuData.reuse(); // No movement - simply reuse
return;
}
else if (meshState_ == polyMesh::POINTS_MOVED)
{
if (debug)
{
Info<< "move points " << longName << nl;
}
DebugInfo
<< "move points " << longName << nl;
vtkgeom = vtuData.getCopy();
vtkgeom->SetPoints(vtuData.points(mesh_));
}
......@@ -72,10 +70,8 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryInternal()
if (!vtkgeom)
{
if (debug)
{
Info<< "Nothing usable from cache - create new geometry" << nl;
}
DebugInfo
<< "Nothing usable from cache - create new geometry" << nl;
// Nothing usable from cache - create new geometry
vtkgeom = vtuData.internal(mesh_, decomposePoly_);
......@@ -103,20 +99,18 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryBoundary()
{
if (meshState_ == polyMesh::UNCHANGED)
{
if (debug)
{
Info<< "reuse " << longName << nl;
}
DebugInfo
<< "reuse " << longName << nl;
vtpData.reuse(); // No movement - simply reuse
continue;
}
else if (meshState_ == polyMesh::POINTS_MOVED)
{
// Point movement on single patch
if (debug)
{
Info<< "move points " << longName << nl;
}
DebugInfo
<< "move points " << longName << nl;
vtkgeom = vtpData.getCopy();
vtkgeom->SetPoints(vtk::Tools::Patch::points(pp));
}
......@@ -124,11 +118,9 @@ void Foam::vtk::fvMeshAdaptor::convertGeometryBoundary()
vtpData.clear(); // Remove any old mappings
if (debug)
{
Info<< "Creating VTK mesh for patch [" << patchId <<"] "
<< longName << endl;
}
DebugInfo
<< "Creating VTK mesh for patch [" << patchId <<"] "
<< longName << endl;
// Unused information
vtpData.additionalIds().clear();
......
......@@ -48,23 +48,21 @@ Foam::vtk::fvMeshAdaptor::foamVtuData::points
const pointField& pts = mesh.points();
// Additional cell centres
const labelList& addPoints = this->additionalIds();
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
// Normal points
label pointId = 0;
vtkIdType pointId = 0;
for (const point& p : pts)
{
vtkpoints->SetPoint(pointId, p.v_);
++pointId;
vtkpoints->SetPoint(pointId++, p.v_);
}
// Cell centres
for (const label ptId : addPoints)
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
++pointId;
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
......@@ -85,23 +83,21 @@ Foam::vtk::fvMeshAdaptor::foamVtuData::points
const pointField& pts = mesh.points();
// Additional cell centres
const labelList& addPoints = this->additionalIds();
const labelUList& addPoints = this->additionalIds();
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
// Normal points
label pointId = 0;
for (const label ptId : pointMap)
vtkIdType pointId = 0;
for (const label meshPointi : pointMap)
{
vtkpoints->SetPoint(pointId, pts[ptId].v_);
++pointId;
vtkpoints->SetPoint(pointId++, pts[meshPointi].v_);
}
// Cell centres
for (const label ptId : addPoints)
for (const label meshCelli : addPoints)
{
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
++pointId;
vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_);
}
return vtkpoints;
......