Commit c126464d authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: change wordRes to be a List of wordRe instead of a wrapper (issue #259)

- this permits direct storage of a list with additional matcher
  capabilities

- provide wordRes::matcher class for similar behaviour as previously
parent 03b287ed
......@@ -55,7 +55,7 @@ Description
items:
\code
{
wordReList matchProcs
wordRes matchProcs
{
wordRe("processors"),
wordRe("processor\\d+", wordRe::REGEX)
......@@ -64,7 +64,7 @@ Description
for
(
const word& item
: DirLister::dirs(".").where(wordRes(matchProcs))
: DirLister::dirs(".").where(matchProcs)
)
{
Info<< "processor dir: " << item << nl;
......@@ -75,7 +75,7 @@ Description
methods:
\code
{
wordReList matchProcs
wordRes matchProcs
{
wordRe("processor[0-9][0-9]*", wordRe::REGEX),
wordRe("processors")
......@@ -83,7 +83,7 @@ Description
fileNameList procDirs
(
DirLister::dirs(".").sorted<fileName>(wordRes(matchProcs))
DirLister::dirs(".").sorted<fileName>(matchProcs)
);
}
\endcode
......
......@@ -144,16 +144,15 @@ int main(int argc, char *argv[])
<< "List files - filtered" << nl
<< "~~~~~~~~~~" << nl;
wordReList relist
{
wordRes relist
({
wordRe("processors"),
wordRe("processor[0-9][0-9]*", wordRe::REGEX)
};
wordRes matcher(relist);
});
Info<<"matcher: " << flatOutput(matcher) << endl;
Info<<"matcher: " << flatOutput(relist) << endl;
for (const word& item : DirLister::dirs(".").where(wordRes(relist)))
for (const word& item : DirLister::dirs(".").where(relist))
{
Info<< "=> " << item << nl;
}
......@@ -161,7 +160,7 @@ int main(int argc, char *argv[])
Info<< "dirList: "
<< flatOutput
(
DirLister::dirs(".").sorted<fileName>(wordRes(relist))
DirLister::dirs(".").sorted<fileName>(relist)
) << nl;
}
......
......@@ -40,7 +40,7 @@ using namespace Foam;
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addOption("re", "wordReList");
argList::addOption("re", "wordRes");
// timeSelector::addOptions();
timeSelector::addOptions(true, true);
......@@ -48,12 +48,10 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
wordReList matcher;
if (args.found("re"))
wordRes matcher;
if (args.readListIfPresent<wordRe>("re", matcher))
{
matcher = args.readList<wordRe>("re");
Info<<"limit names: " << matcher << nl;
}
const hashedWordList subsetTypes
......
......@@ -34,7 +34,7 @@ See also
#include "OSspecific.H"
#include "argList.H"
#include "wordReList.H"
#include "wordRes.H"
#include "IOstreams.H"
#include "StringStream.H"
......@@ -446,20 +446,11 @@ int main(int argc, char *argv[])
Info<<"read float " << xxx << endl;
}
if (args.found("reList"))
{
reLst = args.readList<wordRe>("reList");
}
if (args.found("wordList"))
{
wLst = args.readList<word>("wordList");
}
args.readListIfPresent<wordRe>("reList", reLst);
args.readListIfPresent<word>("wordList", wLst);
if (args.found("stringList"))
if (args.readListIfPresent<string>("stringList", sLst))
{
sLst = args.readList<string>("stringList");
printMyString(sLst);
}
......
......@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
labelList patchIDs
(
pbm.patchSet(wordReList(IStringStream(args[1])())).sortedToc()
pbm.patchSet(args.readList<wordRe>(1)).sortedToc()
);
Info<< "Starting walk from patches "
......
......@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
"okkkey",
};
wordReList reLst(IStringStream("( okey \"[hy]e+.*\" )")());
wordRes reLst(IStringStream("( okey \"[hy]e+.*\" )")());
Info<< "stringList " << strLst << nl;
......
......@@ -31,7 +31,6 @@ Description
#include "List.H"
#include "Tuple2.H"
#include "keyType.H"
#include "wordRe.H"
#include "wordRes.H"
#include "predicates.H"
......@@ -108,7 +107,7 @@ int main(int argc, char *argv[])
wordRes wrelist(wordrelist);
Info<< "re-list:" << wrelist() << endl;
Info<< "re-list:" << wrelist << endl;
Info<< "match this: " << wrelist("this") << endl;
Info<< "match xyz: " << wrelist("xyz") << endl;
Info<< "match zyx: " << wrelist("zyx") << endl;
......
......@@ -81,12 +81,11 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
// Find set of patches from the list of regular expressions provided
const wordReList patches((IStringStream(args[1])()));
const labelHashSet patchSet(mesh.boundaryMesh().patchSet(patches));
const wordRes patches(args.readList<wordRe>(1));
const scalar weight = args.read<scalar>(2);
const bool overwrite = args.found("overwrite");
const labelHashSet patchSet(mesh.boundaryMesh().patchSet(patches));
if (!patchSet.size())
{
FatalErrorInFunction
......
......@@ -1666,7 +1666,7 @@ int main(int argc, char *argv[])
{
includePatches = bMesh.patchSet
(
wordReList(args.lookup("patches")())
args.readList<wordRe>("patches")
);
}
else
......
......@@ -414,7 +414,7 @@ int main(int argc, char *argv[])
}
else if (args.found("patches"))
{
const wordReList patchNames(args.opt<wordReList>("patches"));
const wordRes patchNames(args.readList<wordRe>("patches"));
exposedPatchIDs = mesh.boundaryMesh().patchSet(patchNames).sortedToc();
......
......@@ -360,10 +360,10 @@ int main(int argc, char *argv[])
}
}
if (args.found("scale"))
List<scalar> scaling;
if (args.readListIfPresent("scale", scaling))
{
// Use readList to handle single or multiple values
const List<scalar> scaling = args.readList<scalar>("scale");
// readList handles single or multiple values
if (scaling.size() == 1)
{
......
......@@ -127,20 +127,20 @@ int main(int argc, char *argv[])
argList::addOption
(
"patches",
"wordReList",
"wordRes",
"specify particular patches to write - eg '(outlet \"inlet.*\")'. "
"An empty list suppresses writing the internalMesh."
);
argList::addOption
(
"faceZones",
"wordReList",
"wordRes",
"specify faceZones to write - eg '( slice \"mfp-.*\" )'."
);
argList::addOption
(
"fields",
"wordReList",
"wordRes",
"specify fields to export (all by default) - eg '( \"U.*\" )'."
);
argList::addOption
......@@ -249,11 +249,8 @@ int main(int argc, char *argv[])
//
const bool noLagrangian = args.found("noLagrangian");
wordReList fieldPatterns;
if (args.found("fields"))
{
fieldPatterns = args.readList<wordRe>("fields");
}
wordRes fieldPatterns;
args.readListIfPresent<wordRe>("fields", fieldPatterns);
word cellZoneName;
if (args.readIfPresent("cellZone", cellZoneName))
......
......@@ -79,8 +79,7 @@ Usage
#include "tensorIOField.H"
#include "passiveParticleCloud.H"
#include "faceSet.H"
#include "stringOps.H"
#include "wordReList.H"
#include "wordRes.H"
#include "meshSubsetHelper.H"
#include "readFields.H"
......@@ -117,7 +116,7 @@ void print(Ostream& os, const wordList& flds)
labelList getSelectedPatches
(
const polyBoundaryMesh& patches,
const List<wordRe>& excludePatches //HashSet<word>& excludePatches
const wordRes& excludePatches
)
{
DynamicList<label> patchIDs(patches.size());
......@@ -137,7 +136,7 @@ labelList getSelectedPatches
Info<< " discarding empty/processor patch " << patchi
<< " " << pp.name() << endl;
}
else if (stringOps::match(excludePatches, pp.name()))
else if (excludePatches.match(pp.name()))
{
Info<< " excluding patch " << patchi
<< " " << pp.name() << endl;
......@@ -227,11 +226,9 @@ int main(int argc, char *argv[])
<< "Outputting cell values only" << nl << endl;
}
List<wordRe> excludePatches;
if (args.found("excludePatches"))
wordRes excludePatches;
if (args.readListIfPresent<wordRe>("excludePatches", excludePatches))
{
args.lookup("excludePatches")() >> excludePatches;
Info<< "Not including patches " << excludePatches << nl << endl;
}
......
......@@ -156,7 +156,7 @@ Note
#include "faceZoneMesh.H"
#include "Cloud.H"
#include "passiveParticle.H"
#include "stringOps.H"
#include "wordRes.H"
#include "areaFields.H"
#include "meshSubsetHelper.H"
#include "readFields.H"
......@@ -412,7 +412,7 @@ int main(int argc, char *argv[])
argList::addOption
(
"excludePatches",
"wordReList",
"wordRes",
"a list of patches to exclude - eg '( inlet \".*Wall\" )' "
);
argList::addBoolOption
......@@ -474,11 +474,9 @@ int main(int argc, char *argv[])
const bool allPatches = args.found("allPatches");
wordReList excludePatches;
if (args.found("excludePatches"))
wordRes excludePatches;
if (args.readListIfPresent<wordRe>("excludePatches", excludePatches))
{
args.lookup("excludePatches")() >> excludePatches;
Info<< "Not including patches " << excludePatches << nl << endl;
}
......@@ -499,7 +497,7 @@ int main(int argc, char *argv[])
else if (Pstream::parRun())
{
// Strip off leading casename, leaving just processor_DDD ending.
string::size_type i = vtkName.rfind("processor");
const auto i = vtkName.rfind("processor");
if (i != string::npos)
{
......@@ -1284,7 +1282,7 @@ int main(int argc, char *argv[])
{
const polyPatch& pp = patches[patchi];
if (stringOps::match(excludePatches, pp.name()))
if (excludePatches.match(pp.name()))
{
// Skip excluded patch
continue;
......
......@@ -446,7 +446,7 @@ int main(int argc, char *argv[])
forAll(times, timei)
{
word instance;
if (args.found("instance"))
if (args.readIfPresent("instance", instance))
{
if (times.size() > 1)
{
......@@ -454,8 +454,6 @@ int main(int argc, char *argv[])
<< "Multiple times selected with 'instance' option"
<< exit(FatalError);
}
args.lookup("instance")() >> instance;
}
else
{
......
......@@ -28,8 +28,6 @@ License
#include "IFstream.H"
#include "StringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryTemplates::boundaryTemplates
......
......@@ -27,9 +27,9 @@ Class
Description
Class to store boundary template specifications
Templates are typically stored centrally, and constructed in a hierarchical
manner. The main use is to convert the (user) specified conditions into
a form which can be inserted into each field file as dictionary entries.
Templates are typically stored centrally, and constructed hierarchically.
The main use is to convert the (user) specified conditions into
a form that can be inserted into each field file as dictionary entries.
\*---------------------------------------------------------------------------*/
......@@ -37,8 +37,6 @@ Description
#define boundaryTemplates_H
#include "dictionary.H"
#include "wordList.H"
#include "wordReList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -43,26 +43,26 @@ Foam::label Foam::caseInfo::findPatchConditionID
// Assign condition according to last condition applied, wins
forAllReverse(conditionNames_, conditionI)
{
const wordReList& patchNames = patchNames_[conditionI];
const wordRes& patchNames = patchNames_[conditionI];
forAll(patchNames, nameI)
for (const wordRe& select : patchNames)
{
if (patchNames[nameI] == patchName)
if (select == patchName)
{
// Check for explicit match
// Literal match
return conditionI;
}
else if (patchNames[nameI].match(patchName))
else if (select.match(patchName))
{
// Check wildcards
// Regex match
return conditionI;
}
else
{
// Check for group match
forAll(patchGroups, groupI)
for (const word& groupName : patchGroups)
{
if (patchNames[nameI] == patchGroups[groupI])
if (select == groupName)
{
return conditionI;
}
......@@ -160,7 +160,7 @@ void Foam::caseInfo::checkPatches
}
const Foam::List<Foam::wordReList>& Foam::caseInfo::patchNames() const
const Foam::List<Foam::wordRes>& Foam::caseInfo::patchNames() const
{
return patchNames_;
}
......
......@@ -36,7 +36,7 @@ Description
#include "labelList.H"
#include "wordList.H"
#include "HashSet.H"
#include "wordReList.H"
#include "wordRes.H"
#include "IOdictionary.H"
#include "boundaryInfo.H"
......@@ -72,7 +72,7 @@ class caseInfo
// Per-condition information
//- List of patch names
List<wordReList> patchNames_;
List<wordRes> patchNames_;
//- Patch category
wordList patchCategories_;
......@@ -103,7 +103,7 @@ public:
) const;
//- Return the list of patch names
const List<wordReList>& patchNames() const;
const List<wordRes>& patchNames() const;
//- Return the condition name for patch with index patchI
const word& conditionName(const label patchI) const;
......
......@@ -200,17 +200,15 @@ int main(int argc, char *argv[])
Info<< "Source: " << rootDirSource << " " << caseDirSource << endl;
word sourceRegion = fvMesh::defaultRegion;
if (args.found("sourceRegion"))
if (args.readIfPresent("sourceRegion", sourceRegion))
{
sourceRegion = args["sourceRegion"];
Info<< "Source region: " << sourceRegion << endl;
}
Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl;
word targetRegion = fvMesh::defaultRegion;
if (args.found("targetRegion"))
if (args.readIfPresent("targetRegion", targetRegion))
{
targetRegion = args["targetRegion"];
Info<< "Target region: " << targetRegion << endl;
}
......@@ -242,10 +240,8 @@ int main(int argc, char *argv[])
}
// Optionally override
if (args.found("patchMapMethod"))
if (args.readIfPresent("patchMapMethod", patchMapMethod))
{
patchMapMethod = args["patchMapMethod"];
Info<< "Patch mapping method: " << patchMapMethod << endl;
}
......@@ -265,10 +261,7 @@ int main(int argc, char *argv[])
}
HashSet<word> selectedFields;
if (args.found("fields"))
{
args.lookup("fields")() >> selectedFields;
}
args.readIfPresent("fields", selectedFields);
const bool noLagrangian = args.found("noLagrangian");
......
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