ENH: add stringListOps with whitelist/blacklist matching

- refactored from ensightMesh, foamToVTK, surfaceMeshExtract

STYLE: use wordRes matching() method instead of findString() function
This commit is contained in:
Mark Olesen
2020-02-26 20:45:20 +01:00
parent a456e9ae92
commit fc26fb758d
7 changed files with 150 additions and 132 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -124,10 +124,13 @@ bool Foam::functionObjects::mapFields::mapFieldType() const
const fvMesh& mapRegion = mapRegionPtr_();
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
const labelList selected = findStrings(fieldNames_, fieldNames);
const labelList selected(fieldNames_.matching(fieldNames));
for (const label fieldi : selected)
{
const word& fieldName = fieldNames[fieldi];
const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
if (!mapRegion.foundObject<VolFieldType>(fieldName))
@ -160,7 +163,7 @@ bool Foam::functionObjects::mapFields::mapFieldType() const
evaluateConstraintTypes(mappedField);
}
return selected.size() > 0;
return !selected.empty();
}
@ -172,7 +175,9 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
const fvMesh& mapRegion = mapRegionPtr_();
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
const labelList selected = findStrings(fieldNames_, fieldNames);
const labelList selected(fieldNames_.matching(fieldNames));
for (const label fieldi : selected)
{
const word& fieldName = fieldNames[fieldi];
@ -185,7 +190,7 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
Log << " " << fieldName << ": written";
}
return selected.size() > 0;
return !selected.empty();
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -865,11 +865,13 @@ bool Foam::functionObjects::regionSizeDistribution::write()
// Collect some more field
{
wordList scalarNames(obr_.names(volScalarField::typeName));
labelList selected = findStrings(fields_, scalarNames);
forAll(selected, i)
const labelList selected(fields_.matching(scalarNames));
for (const label fieldi : selected)
{
const word& fldName = scalarNames[selected[i]];
const word& fldName = scalarNames[fieldi];
Log << " Scalar field " << fldName << endl;
const scalarField& fld = obr_.lookupObject
@ -894,11 +896,13 @@ bool Foam::functionObjects::regionSizeDistribution::write()
}
{
wordList vectorNames(obr_.names(volVectorField::typeName));
labelList selected = findStrings(fields_, vectorNames);
forAll(selected, i)
const labelList selected(fields_.matching(vectorNames));
for (const label fieldi : selected)
{
const word& fldName = vectorNames[selected[i]];
const word& fldName = vectorNames[fieldi];
Log << " Vector field " << fldName << endl;
vectorField fld = obr_.lookupObject