The OpenFOAM development repository is currently offline for maintenance - sorry for any inconvenience

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