mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -172,10 +172,26 @@ labelList getSelectedPatches
|
|||||||
const wordRes& blacklist
|
const wordRes& blacklist
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DynamicList<label> patchIDs(patches.size());
|
// Name-based selection
|
||||||
|
labelList indices
|
||||||
|
(
|
||||||
|
stringListOps::findMatching
|
||||||
|
(
|
||||||
|
patches,
|
||||||
|
whitelist,
|
||||||
|
blacklist,
|
||||||
|
nameOp<polyPatch>()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
for (const polyPatch& pp : patches)
|
|
||||||
|
// Remove undesirable patches
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
for (const label patchi : indices)
|
||||||
{
|
{
|
||||||
|
const polyPatch& pp = patches[patchi];
|
||||||
|
|
||||||
if (isType<emptyPolyPatch>(pp))
|
if (isType<emptyPolyPatch>(pp))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -185,33 +201,13 @@ labelList getSelectedPatches
|
|||||||
break; // No processor patches for parallel output
|
break; // No processor patches for parallel output
|
||||||
}
|
}
|
||||||
|
|
||||||
const word& patchName = pp.name();
|
indices[count] = patchi;
|
||||||
|
++count;
|
||||||
bool accept = false;
|
|
||||||
|
|
||||||
if (whitelist.size())
|
|
||||||
{
|
|
||||||
const auto matched = whitelist.matched(patchName);
|
|
||||||
|
|
||||||
accept =
|
|
||||||
(
|
|
||||||
matched == wordRe::LITERAL
|
|
||||||
? true
|
|
||||||
: (matched == wordRe::REGEX && !blacklist.match(patchName))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accept = !blacklist.match(patchName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accept)
|
indices.resize(count);
|
||||||
{
|
|
||||||
patchIDs.append(pp.index());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return patchIDs.shrink();
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -67,10 +67,26 @@ labelList getSelectedPatches
|
|||||||
const wordRes& blacklist
|
const wordRes& blacklist
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DynamicList<label> patchIDs(patches.size());
|
// Name-based selection
|
||||||
|
labelList indices
|
||||||
|
(
|
||||||
|
stringListOps::findMatching
|
||||||
|
(
|
||||||
|
patches,
|
||||||
|
whitelist,
|
||||||
|
blacklist,
|
||||||
|
nameOp<polyPatch>()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
for (const polyPatch& pp : patches)
|
|
||||||
|
// Remove undesirable patches
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
for (const label patchi : indices)
|
||||||
{
|
{
|
||||||
|
const polyPatch& pp = patches[patchi];
|
||||||
|
|
||||||
if (isType<emptyPolyPatch>(pp))
|
if (isType<emptyPolyPatch>(pp))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -80,33 +96,13 @@ labelList getSelectedPatches
|
|||||||
break; // No processor patches for parallel output
|
break; // No processor patches for parallel output
|
||||||
}
|
}
|
||||||
|
|
||||||
const word& patchName = pp.name();
|
indices[count] = patchi;
|
||||||
|
++count;
|
||||||
bool accept = false;
|
|
||||||
|
|
||||||
if (whitelist.size())
|
|
||||||
{
|
|
||||||
const auto matched = whitelist.matched(patchName);
|
|
||||||
|
|
||||||
accept =
|
|
||||||
(
|
|
||||||
matched == wordRe::LITERAL
|
|
||||||
? true
|
|
||||||
: (matched == wordRe::REGEX && !blacklist.match(patchName))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accept = !blacklist.match(patchName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accept)
|
indices.resize(count);
|
||||||
{
|
|
||||||
patchIDs.append(pp.index());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return patchIDs.shrink();
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2018 OpenCFD Ltd.
|
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -47,6 +47,7 @@ SourceFiles
|
|||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
#include "stringList.H"
|
#include "stringList.H"
|
||||||
#include "wordRes.H"
|
#include "wordRes.H"
|
||||||
|
#include "flipOp.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -346,6 +347,32 @@ struct foundOp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//- Return ids for items with matching names.
|
||||||
|
// Uses a combination of whitelist and blacklist.
|
||||||
|
//
|
||||||
|
// An empty whitelist accepts everything that is not blacklisted.
|
||||||
|
// A regex match is trumped by a literal match.
|
||||||
|
//
|
||||||
|
// Eg,
|
||||||
|
// \verbatim
|
||||||
|
// input: ( abc apple wall wall1 wall2 )
|
||||||
|
// whitelist: ( abc def "wall.*" )
|
||||||
|
// blacklist: ( "[ab].*" wall )
|
||||||
|
//
|
||||||
|
// result: (abc wall1 wall2)
|
||||||
|
// \endverbatim
|
||||||
|
//
|
||||||
|
// \return List indices for matches
|
||||||
|
template<class StringListType, class AccessOp = noOp>
|
||||||
|
labelList findMatching
|
||||||
|
(
|
||||||
|
const StringListType& input,
|
||||||
|
const wordRes& whitelist,
|
||||||
|
const wordRes& blacklist = wordRes(),
|
||||||
|
AccessOp aop = noOp()
|
||||||
|
);
|
||||||
|
|
||||||
} // End namespace stringListOps
|
} // End namespace stringListOps
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -109,4 +109,57 @@ void Foam::inplaceSubsetMatchingStrings
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringListType, class AccessOp>
|
||||||
|
Foam::labelList Foam::stringListOps::findMatching
|
||||||
|
(
|
||||||
|
const StringListType& input,
|
||||||
|
const wordRes& whitelist,
|
||||||
|
const wordRes& blacklist,
|
||||||
|
AccessOp aop
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const label len = input.size();
|
||||||
|
|
||||||
|
if (whitelist.empty() && blacklist.empty())
|
||||||
|
{
|
||||||
|
return identity(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
labelList indices(len);
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
for (label i=0; i < len; ++i)
|
||||||
|
{
|
||||||
|
const std::string& text = aop(input[i]);
|
||||||
|
|
||||||
|
bool accept = false;
|
||||||
|
|
||||||
|
if (whitelist.size())
|
||||||
|
{
|
||||||
|
const auto result = whitelist.matched(text);
|
||||||
|
|
||||||
|
accept =
|
||||||
|
(
|
||||||
|
result == wordRe::LITERAL
|
||||||
|
? true
|
||||||
|
: (result == wordRe::REGEX && !blacklist.match(text))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
accept = !blacklist.match(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accept)
|
||||||
|
{
|
||||||
|
indices[count] = i;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indices.resize(count);
|
||||||
|
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -42,69 +42,6 @@ const Foam::label Foam::ensightMesh::internalZone = -1;
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Find matching ids based on whitelist, blacklist
|
|
||||||
//
|
|
||||||
// An empty whitelist accepts everything that is not blacklisted.
|
|
||||||
// A regex match is trumped by a literal match.
|
|
||||||
//
|
|
||||||
// Eg,
|
|
||||||
// input: ( abc apple wall wall1 wall2 )
|
|
||||||
// whitelist: ( abc def "wall.*" )
|
|
||||||
// blacklist: ( "[ab].*" wall )
|
|
||||||
//
|
|
||||||
// result: (abc wall1 wall2)
|
|
||||||
//
|
|
||||||
static labelList getSelected
|
|
||||||
(
|
|
||||||
const UList<word>& input,
|
|
||||||
const wordRes& whitelist,
|
|
||||||
const wordRes& blacklist
|
|
||||||
)
|
|
||||||
{
|
|
||||||
const label len = input.size();
|
|
||||||
|
|
||||||
if (whitelist.empty() && blacklist.empty())
|
|
||||||
{
|
|
||||||
return identity(len);
|
|
||||||
}
|
|
||||||
|
|
||||||
labelList indices(len);
|
|
||||||
|
|
||||||
label count = 0;
|
|
||||||
for (label i=0; i < len; ++i)
|
|
||||||
{
|
|
||||||
const auto& text = input[i];
|
|
||||||
|
|
||||||
bool accept = false;
|
|
||||||
|
|
||||||
if (whitelist.size())
|
|
||||||
{
|
|
||||||
const auto result = whitelist.matched(text);
|
|
||||||
|
|
||||||
accept =
|
|
||||||
(
|
|
||||||
result == wordRe::LITERAL
|
|
||||||
? true
|
|
||||||
: (result == wordRe::REGEX && !blacklist.match(text))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accept = !blacklist.match(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accept)
|
|
||||||
{
|
|
||||||
indices[count] = i;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
indices.resize(count);
|
|
||||||
|
|
||||||
return indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Patch names without processor patches
|
// Patch names without processor patches
|
||||||
static wordList nonProcessorPatchNames(const polyBoundaryMesh& bmesh)
|
static wordList nonProcessorPatchNames(const polyBoundaryMesh& bmesh)
|
||||||
{
|
{
|
||||||
@ -237,7 +174,7 @@ void Foam::ensightMesh::correct()
|
|||||||
const labelList patchIds =
|
const labelList patchIds =
|
||||||
(
|
(
|
||||||
option().useBoundaryMesh()
|
option().useBoundaryMesh()
|
||||||
? getSelected
|
? stringListOps::findMatching
|
||||||
(
|
(
|
||||||
patchNames,
|
patchNames,
|
||||||
option().patchSelection(),
|
option().patchSelection(),
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2019 OpenCFD Ltd.
|
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -124,10 +124,13 @@ bool Foam::functionObjects::mapFields::mapFieldType() const
|
|||||||
const fvMesh& mapRegion = mapRegionPtr_();
|
const fvMesh& mapRegion = mapRegionPtr_();
|
||||||
|
|
||||||
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
|
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
|
||||||
const labelList selected = findStrings(fieldNames_, fieldNames);
|
|
||||||
|
const labelList selected(fieldNames_.matching(fieldNames));
|
||||||
|
|
||||||
for (const label fieldi : selected)
|
for (const label fieldi : selected)
|
||||||
{
|
{
|
||||||
const word& fieldName = fieldNames[fieldi];
|
const word& fieldName = fieldNames[fieldi];
|
||||||
|
|
||||||
const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
|
const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
|
||||||
|
|
||||||
if (!mapRegion.foundObject<VolFieldType>(fieldName))
|
if (!mapRegion.foundObject<VolFieldType>(fieldName))
|
||||||
@ -160,7 +163,7 @@ bool Foam::functionObjects::mapFields::mapFieldType() const
|
|||||||
evaluateConstraintTypes(mappedField);
|
evaluateConstraintTypes(mappedField);
|
||||||
}
|
}
|
||||||
|
|
||||||
return selected.size() > 0;
|
return !selected.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -172,7 +175,9 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
|
|||||||
const fvMesh& mapRegion = mapRegionPtr_();
|
const fvMesh& mapRegion = mapRegionPtr_();
|
||||||
|
|
||||||
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
|
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
|
||||||
const labelList selected = findStrings(fieldNames_, fieldNames);
|
|
||||||
|
const labelList selected(fieldNames_.matching(fieldNames));
|
||||||
|
|
||||||
for (const label fieldi : selected)
|
for (const label fieldi : selected)
|
||||||
{
|
{
|
||||||
const word& fieldName = fieldNames[fieldi];
|
const word& fieldName = fieldNames[fieldi];
|
||||||
@ -185,7 +190,7 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
|
|||||||
Log << " " << fieldName << ": written";
|
Log << " " << fieldName << ": written";
|
||||||
}
|
}
|
||||||
|
|
||||||
return selected.size() > 0;
|
return !selected.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2013-2016 OpenFOAM Foundation
|
Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2019 OpenCFD Ltd.
|
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -865,11 +865,13 @@ bool Foam::functionObjects::regionSizeDistribution::write()
|
|||||||
// Collect some more field
|
// Collect some more field
|
||||||
{
|
{
|
||||||
wordList scalarNames(obr_.names(volScalarField::typeName));
|
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;
|
Log << " Scalar field " << fldName << endl;
|
||||||
|
|
||||||
const scalarField& fld = obr_.lookupObject
|
const scalarField& fld = obr_.lookupObject
|
||||||
@ -894,11 +896,13 @@ bool Foam::functionObjects::regionSizeDistribution::write()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
wordList vectorNames(obr_.names(volVectorField::typeName));
|
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;
|
Log << " Vector field " << fldName << endl;
|
||||||
|
|
||||||
vectorField fld = obr_.lookupObject
|
vectorField fld = obr_.lookupObject
|
||||||
|
|||||||
Reference in New Issue
Block a user