Commit ae48c4a4 authored by Mark Olesen's avatar Mark Olesen

ENH: prune cloud fields by names only once

- 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.
parent eaa7f683
...@@ -98,7 +98,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl ...@@ -98,7 +98,7 @@ Foam::vtk::cloudAdaptor::getCloudImpl
auto output = vtkSmartPointer<vtkMultiPieceDataSet>::New(); auto output = vtkSmartPointer<vtkMultiPieceDataSet>::New();
auto objPtr = mesh.lookupObjectPtr<cloud>(cloudName); const auto* objPtr = mesh.lookupObjectPtr<cloud>(cloudName);
if (!objPtr) if (!objPtr)
{ {
return output; return output;
...@@ -126,12 +126,27 @@ Foam::vtk::cloudAdaptor::getCloudImpl ...@@ -126,12 +126,27 @@ Foam::vtk::cloudAdaptor::getCloudImpl
{ {
vtkmesh = startLagrangian(*pointsPtr); vtkmesh = startLagrangian(*pointsPtr);
convertLagrangianFields<label>(vtkmesh, obrTmp, matcher); // Prevent any possible conversion of positions as a field
convertLagrangianFields<scalar>(vtkmesh, obrTmp, matcher); obrTmp.filterKeys
convertLagrangianFields<vector>(vtkmesh, obrTmp, matcher); (
[](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 else
{ {
// This should never occur
vtkmesh = vtkSmartPointer<vtkPolyData>::New(); vtkmesh = vtkSmartPointer<vtkPolyData>::New();
} }
......
...@@ -77,12 +77,11 @@ class cloudAdaptor ...@@ -77,12 +77,11 @@ class cloudAdaptor
); );
//- Lagrangian fields from objectRegistry //- Lagrangian fields from objectRegistry
template<class Type, class UnaryPredicate> template<class Type>
static label convertLagrangianFields static label convertLagrangianFields
( (
vtkPolyData* vtkmesh, vtkPolyData* vtkmesh,
const objectRegistry& obr, const objectRegistry& obr
const UnaryPredicate& pred
); );
//- Get cloud with point/cell data //- Get cloud with point/cell data
......
...@@ -30,32 +30,14 @@ License ...@@ -30,32 +30,14 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type, class UnaryMatchPredicate> template<class Type>
Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields
( (
vtkPolyData* vtkmesh, vtkPolyData* vtkmesh,
const objectRegistry& obr, const objectRegistry& obr
const UnaryMatchPredicate& pred
) )
{ {
label nFields = 0; const wordList fieldNames(obr.sortedNames<IOField<Type>>());
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());
for (const word& fieldName : fieldNames) for (const word& fieldName : fieldNames)
{ {
...@@ -71,11 +53,9 @@ Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields ...@@ -71,11 +53,9 @@ Foam::label Foam::vtk::cloudAdaptor::convertLagrangianFields
// 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 nFields; return fieldNames.size();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment