ENH: avoid unneeded IOobjectList scan in sampledSurfaces

STYLE: replace findStrings with ListOps::found
This commit is contained in:
Mark Olesen
2022-01-24 17:56:19 +01:00
parent 1ea1b84f12
commit bd10f67a13
3 changed files with 18 additions and 12 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,6 +32,7 @@ License
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "areaFields.H" #include "areaFields.H"
#include "HashOps.H" #include "HashOps.H"
#include "ListOps.H"
#include "Time.H" #include "Time.H"
#include "UIndirectList.H" #include "UIndirectList.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -273,7 +274,7 @@ bool Foam::areaWrite::write()
// Detect missing fields // Detect missing fields
forAll(fieldSelection_, i) forAll(fieldSelection_, i)
{ {
if (findStrings(fieldSelection_[i], allFields).empty()) if (!ListOps::found(allFields, fieldSelection_[i]))
{ {
missed.append(i); missed.append(i);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -95,15 +95,17 @@ bool Foam::sampledSurfaces::removeRegistrySurface
} }
void Foam::sampledSurfaces::countFields() Foam::IOobjectList Foam::sampledSurfaces::preCheckFields()
{ {
wordList allFields; // Just needed for warnings wordList allFields; // Just needed for warnings
HashTable<wordHashSet> selected; HashTable<wordHashSet> selected;
IOobjectList objects(0);
if (loadFromFiles_) if (loadFromFiles_)
{ {
// Check files for a particular time // Check files for a particular time
IOobjectList objects(obr_, obr_.time().timeName()); objects = IOobjectList(obr_, obr_.time().timeName());
allFields = objects.names(); allFields = objects.names();
selected = objects.classes(fieldSelection_); selected = objects.classes(fieldSelection_);
@ -127,7 +129,7 @@ void Foam::sampledSurfaces::countFields()
// Detect missing fields // Detect missing fields
forAll(fieldSelection_, i) forAll(fieldSelection_, i)
{ {
if (findStrings(fieldSelection_[i], allFields).empty()) if (!ListOps::found(allFields, fieldSelection_[i]))
{ {
missed.append(i); missed.append(i);
} }
@ -183,6 +185,8 @@ void Foam::sampledSurfaces::countFields()
) )
); );
} }
return objects;
} }
@ -543,10 +547,11 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
} }
// Determine the per-surface number of fields, including Ids etc. // Determine availability of fields.
// Only seems to be needed for VTK legacy // Count per-surface number of fields, including Ids etc
countFields(); // which only seems to be needed for VTK legacy
IOobjectList objects = preCheckFields();
// Update writers // Update writers
@ -596,8 +601,6 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
// Sample fields // Sample fields
const IOobjectList objects(obr_, obr_.time().timeName());
performAction<volScalarField>(objects, request); performAction<volScalarField>(objects, request);
performAction<volVectorField>(objects, request); performAction<volVectorField>(objects, request);
performAction<volSphericalTensorField>(objects, request); performAction<volSphericalTensorField>(objects, request);

View File

@ -233,7 +233,8 @@ class sampledSurfaces
bool performAction(unsigned request); bool performAction(unsigned request);
//- Count selected/sampled fields per surface //- Count selected/sampled fields per surface
void countFields(); // Returns empty IOobjectList if loadFromFiles_ is not active
IOobjectList preCheckFields();
//- Write sampled fieldName on surface and on outputDir path //- Write sampled fieldName on surface and on outputDir path
template<class Type> template<class Type>
@ -261,6 +262,7 @@ class sampledSurfaces
); );
//- Sample and write all applicable sampled fields //- Sample and write all applicable sampled fields
// Only uses IOobjectList when loadFromFiles_ is active
template<class GeoField> template<class GeoField>
void performAction void performAction
( (