mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
stringListOps - findStrings() with wordReList
- we can now use a list of words/regexp for filtering/selecting ... the first results: cellTable/boundaryRegion
This commit is contained in:
@ -38,21 +38,45 @@ SourceFiles
|
|||||||
|
|
||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
#include "stringList.H"
|
#include "stringList.H"
|
||||||
|
#include "wordReList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
//- Return list indices for the strings matching the regular expression
|
//- Return list indices for strings matching the regular expression
|
||||||
// partial matches are optional
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const string& regexpPattern,
|
const string& regexpPattern,
|
||||||
const UList<StringType>&,
|
const UList<StringType>&
|
||||||
bool partialMatch=false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Return list indices for strings matching the regular expression
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const wordRe&,
|
||||||
|
const UList<StringType>&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Return list indices for strings matching one of the regular expression
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const UList<wordRe>&,
|
||||||
|
const UList<StringType>&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Return true if string matches one of the regular expressions
|
||||||
|
template<class StringType>
|
||||||
|
bool findStrings
|
||||||
|
(
|
||||||
|
const UList<wordRe>&,
|
||||||
|
const StringType& str
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -38,8 +38,7 @@ template<class StringType>
|
|||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const string& pattern,
|
const string& pattern,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst
|
||||||
bool partialMatch
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
regExp re(pattern);
|
regExp re(pattern);
|
||||||
@ -48,7 +47,7 @@ labelList findStrings
|
|||||||
label matchI = 0;
|
label matchI = 0;
|
||||||
forAll(lst, elemI)
|
forAll(lst, elemI)
|
||||||
{
|
{
|
||||||
if (partialMatch ? re.search(lst[elemI]) : re.match(lst[elemI]))
|
if (re.match(lst[elemI]))
|
||||||
{
|
{
|
||||||
matched[matchI++] = elemI;
|
matched[matchI++] = elemI;
|
||||||
}
|
}
|
||||||
@ -59,6 +58,75 @@ labelList findStrings
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const wordRe& wre,
|
||||||
|
const UList<StringType>& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
labelList matched(lst.size());
|
||||||
|
|
||||||
|
label matchI = 0;
|
||||||
|
forAll(lst, elemI)
|
||||||
|
{
|
||||||
|
if (wre.match(lst[elemI]))
|
||||||
|
{
|
||||||
|
matched[matchI++] = elemI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matched.setSize(matchI);
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const UList<wordRe>& wreLst,
|
||||||
|
const UList<StringType>& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
labelList matched(lst.size());
|
||||||
|
|
||||||
|
label matchI = 0;
|
||||||
|
forAll(lst, elemI)
|
||||||
|
{
|
||||||
|
forAll(wreLst, reI)
|
||||||
|
{
|
||||||
|
if (wreLst[reI].match(lst[elemI]))
|
||||||
|
{
|
||||||
|
matched[matchI++] = elemI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matched.setSize(matchI);
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
bool findStrings
|
||||||
|
(
|
||||||
|
const UList<wordRe>& wreLst,
|
||||||
|
const StringType& str
|
||||||
|
)
|
||||||
|
{
|
||||||
|
forAll(wreLst, reI)
|
||||||
|
{
|
||||||
|
if (wreLst[reI].match(str))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -27,6 +27,7 @@ License
|
|||||||
#include "boundaryRegion.H"
|
#include "boundaryRegion.H"
|
||||||
#include "IOMap.H"
|
#include "IOMap.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
|
#include "stringListOps.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -94,6 +95,31 @@ Foam::Map<Foam::word> Foam::boundaryRegion::names() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Map<Foam::word> Foam::boundaryRegion::names
|
||||||
|
(
|
||||||
|
const List<wordRe>& patterns
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
Map<word> lookup;
|
||||||
|
|
||||||
|
forAllConstIter(Map<dictionary>, *this, iter)
|
||||||
|
{
|
||||||
|
word lookupName = iter().lookupOrDefault<word>
|
||||||
|
(
|
||||||
|
"Label",
|
||||||
|
"boundaryRegion_" + Foam::name(iter.key())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (findStrings(patterns, lookupName))
|
||||||
|
{
|
||||||
|
lookup.insert(iter.key(), lookupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Map<Foam::word> Foam::boundaryRegion::boundaryTypes() const
|
Foam::Map<Foam::word> Foam::boundaryRegion::boundaryTypes() const
|
||||||
{
|
{
|
||||||
Map<word> lookup;
|
Map<word> lookup;
|
||||||
|
|||||||
@ -58,6 +58,7 @@ SourceFiles
|
|||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
|
#include "wordReList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -110,6 +111,9 @@ public:
|
|||||||
//- Return a Map of (id => name)
|
//- Return a Map of (id => name)
|
||||||
Map<word> names() const;
|
Map<word> names() const;
|
||||||
|
|
||||||
|
//- Return a Map of (id => names) selected by patterns
|
||||||
|
Map<word> names(const List<wordRe>& patterns) const;
|
||||||
|
|
||||||
//- Return a Map of (id => type)
|
//- Return a Map of (id => type)
|
||||||
Map<word> boundaryTypes() const;
|
Map<word> boundaryTypes() const;
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ Description
|
|||||||
#include "IOMap.H"
|
#include "IOMap.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
|
#include "stringListOps.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -166,6 +167,31 @@ Foam::Map<Foam::word> Foam::cellTable::names() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Map<Foam::word> Foam::cellTable::names
|
||||||
|
(
|
||||||
|
const List<wordRe>& patterns
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
Map<word> lookup;
|
||||||
|
|
||||||
|
forAllConstIter(Map<dictionary>, *this, iter)
|
||||||
|
{
|
||||||
|
word lookupName = iter().lookupOrDefault<word>
|
||||||
|
(
|
||||||
|
"Label",
|
||||||
|
"cellTable_" + Foam::name(iter.key())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (findStrings(patterns, lookupName))
|
||||||
|
{
|
||||||
|
lookup.insert(iter.key(), lookupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::cellTable::name(const label& id) const
|
Foam::word Foam::cellTable::name(const label& id) const
|
||||||
{
|
{
|
||||||
word theName("cellTable_" + Foam::name(id));
|
word theName("cellTable_" + Foam::name(id));
|
||||||
@ -281,7 +307,7 @@ void Foam::cellTable::setName(const label& id)
|
|||||||
|
|
||||||
if (iter == end() || !iter().found("Label"))
|
if (iter == end() || !iter().found("Label"))
|
||||||
{
|
{
|
||||||
setName(id, "cellTable_" + ::Foam::name(id));
|
setName(id, "cellTable_" + Foam::name(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,64 +517,43 @@ void Foam::cellTable::combine(const dictionary& mapDict, labelList& tableIds)
|
|||||||
bool remap = false;
|
bool remap = false;
|
||||||
labelList mapping(identity(max(this->toc()) + 1));
|
labelList mapping(identity(max(this->toc()) + 1));
|
||||||
|
|
||||||
forAllConstIter (dictionary, mapDict, iter)
|
forAllConstIter(dictionary, mapDict, iter)
|
||||||
{
|
{
|
||||||
wordList zoneNames(iter().stream());
|
Map<word> matches = names(wordReList(iter().stream()));
|
||||||
labelList zoneIndex(zoneNames.size());
|
|
||||||
|
|
||||||
label nElem = 0;
|
if (matches.size())
|
||||||
forAll(zoneNames, zoneI)
|
|
||||||
{
|
|
||||||
zoneIndex[nElem] = this->findIndex(zoneNames[zoneI]);
|
|
||||||
if (zoneIndex[nElem] >= 0)
|
|
||||||
{
|
|
||||||
if (zoneI != nElem)
|
|
||||||
{
|
|
||||||
zoneNames[nElem] = zoneNames[zoneI];
|
|
||||||
}
|
|
||||||
++nElem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zoneIndex.setSize(nElem);
|
|
||||||
zoneNames.setSize(nElem);
|
|
||||||
|
|
||||||
if (nElem)
|
|
||||||
{
|
{
|
||||||
remap = true;
|
remap = true;
|
||||||
label targetId = this->findIndex(iter().keyword());
|
label targetId = this->findIndex(iter().keyword());
|
||||||
|
|
||||||
Info<< "combine cellTable: " << iter().keyword();
|
Info<< "combine cellTable: " << iter().keyword();
|
||||||
if (targetId >= 0)
|
if (targetId < 0)
|
||||||
{
|
{
|
||||||
Info<< " += (";
|
// re-use the first element if possible
|
||||||
|
targetId = min(matches.toc());
|
||||||
|
operator[](targetId).set("Label", iter().keyword());
|
||||||
|
|
||||||
|
Info<< " = (";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Info<< " = (";
|
Info<< " += (";
|
||||||
}
|
|
||||||
forAll(zoneNames, zoneI)
|
|
||||||
{
|
|
||||||
Info<< " " << zoneNames[zoneI];
|
|
||||||
}
|
|
||||||
Info<< " )" << endl;
|
|
||||||
|
|
||||||
// re-use the first element if possible
|
|
||||||
if (targetId < 0)
|
|
||||||
{
|
|
||||||
targetId = min(zoneIndex);
|
|
||||||
operator[](targetId).set("Label", iter().keyword());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(zoneIndex, zoneI)
|
|
||||||
|
forAllConstIter(Map<word>, matches, matchIter)
|
||||||
{
|
{
|
||||||
label idx = zoneIndex[zoneI];
|
label idx = matchIter.key();
|
||||||
|
|
||||||
if (idx != targetId && idx >= 0)
|
if (idx != targetId && idx >= 0)
|
||||||
{
|
{
|
||||||
mapping[idx] = targetId;
|
mapping[idx] = targetId;
|
||||||
this->erase(idx);
|
this->erase(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< " " << matchIter();
|
||||||
}
|
}
|
||||||
|
Info<< " )" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,6 +65,7 @@ SourceFiles
|
|||||||
#include "Map.H"
|
#include "Map.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
|
#include "wordReList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -137,6 +138,9 @@ public:
|
|||||||
//- Return a Map of (id => name)
|
//- Return a Map of (id => name)
|
||||||
Map<word> names() const;
|
Map<word> names() const;
|
||||||
|
|
||||||
|
//- Return a Map of (id => names) selected by patterns
|
||||||
|
Map<word> names(const List<wordRe>& patterns) const;
|
||||||
|
|
||||||
//- Return a Map of (id => name) for materialType (fluid | solid | shell)
|
//- Return a Map of (id => name) for materialType (fluid | solid | shell)
|
||||||
Map<word> selectType(const word& materialType) const;
|
Map<word> selectType(const word& materialType) const;
|
||||||
|
|
||||||
|
|||||||
38
src/conversion/meshTables/remappingDict
Normal file
38
src/conversion/meshTables/remappingDict
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*--------------------------------*- C++ -*----------------------------------*\
|
||||||
|
| ========= | |
|
||||||
|
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||||
|
| \\ / O peration | Version: dev |
|
||||||
|
| \\ / A nd | |
|
||||||
|
| \\/ M anipulation | www.OpenFOAM.org |
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
FoamFile
|
||||||
|
{
|
||||||
|
version 2.0;
|
||||||
|
format ascii;
|
||||||
|
class dictionary;
|
||||||
|
location "constant";
|
||||||
|
object remapping;
|
||||||
|
}
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// this is a simple example of remapping cellTable and boundaryRegion entries
|
||||||
|
// NB: can't yet combine boundaryRegions, since this reorganizes the mesh faces
|
||||||
|
|
||||||
|
// rename/combine cellTable entries
|
||||||
|
// newName ( listOldNames );
|
||||||
|
cellTable
|
||||||
|
{
|
||||||
|
fluid ( fluid "[Ff]Luid[0-9]+" "(inlet|outlet)Region" );
|
||||||
|
cat1 ( CAT1 "cat1_(Back|Front|Gamma)" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// rename boundary regions
|
||||||
|
// newName oldName;
|
||||||
|
boundaryRegion
|
||||||
|
{
|
||||||
|
inlet_4 inlet_1;
|
||||||
|
inlet_5 inlet_2;
|
||||||
|
inlet_6 inlet_3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
Reference in New Issue
Block a user