Skip to content
Commits on Source (1)
  • Mark OLESEN's avatar
    ENH: prune cloud fields by names only once · ae48c4a4
    Mark OLESEN authored
    - can remove directly from the temporary objectRegistry prior to
      converting by field type. Cannot, however, do the same for volFields
      or areaFields since these reside on their respective mesh objects.
    ae48c4a4
......@@ -98,7 +98,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl
auto output = vtkSmartPointer<vtkMultiPieceDataSet>::New();
auto objPtr = mesh.lookupObjectPtr<cloud>(cloudName);
const auto* objPtr = mesh.lookupObjectPtr<cloud>(cloudName);
if (!objPtr)
{
return output;
......@@ -126,12 +126,27 @@ Foam::vtk::cloudAdaptor::getCloudImpl
{
vtkmesh = startLagrangian(*pointsPtr);
convertLagrangianFields<label>(vtkmesh, obrTmp, matcher);
convertLagrangianFields<scalar>(vtkmesh, obrTmp, matcher);
convertLagrangianFields<vector>(vtkmesh, obrTmp, matcher);
// Prevent any possible conversion of positions as a field
obrTmp.filterKeys
(
[](const word& k)
{
return k.startsWith("position")
|| k.startsWith("coordinate");
},
true // prune
);
// Restrict to specified fields
obrTmp.filterKeys(matcher);
convertLagrangianFields<label>(vtkmesh, obrTmp);
convertLagrangianFields<scalar>(vtkmesh, obrTmp);
convertLagrangianFields<vector>(vtkmesh, obrTmp);
}
else
{
// This should never occur
vtkmesh = vtkSmartPointer<vtkPolyData>::New();
}
......
......@@ -77,12 +77,11 @@ class cloudAdaptor
);
//- Lagrangian fields from objectRegistry
template<class Type, class UnaryPredicate>
template<class Type>
static label convertLagrangianFields
(
vtkPolyData* vtkmesh,
const objectRegistry& obr,
const UnaryPredicate& pred
const objectRegistry& obr
);
//- Get cloud with point/cell data
......
......@@ -30,32 +30,14 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type, class UnaryMatchPredicate>
template<class Type>
Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields
(
vtkPolyData* vtkmesh,
const objectRegistry& obr,
const UnaryMatchPredicate& pred
const objectRegistry& obr
)
{
label nFields = 0;
wordHashSet names(obr.names<IOField<Type>>());
// Restrict to specified names
names.filterKeys(pred);
// Avoid converting particle positions as a field too.
names.filterKeys
(
[](const word& k)
{
return k.startsWith("position") || k.startsWith("coordinate");
},
true // prune
);
const wordList fieldNames(names.sortedToc());
const wordList fieldNames(obr.sortedNames<IOField<Type>>());
for (const word& fieldName : fieldNames)
{
......@@ -71,11 +53,9 @@ Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields
// Provide identical data as cell and as point data
vtkmesh->GetCellData()->AddArray(data);
vtkmesh->GetPointData()->AddArray(data);
++nFields;
}
return nFields;
return fieldNames.size();
}
......