From bae37a52a67a1720ca9c8ed9b77f6f279425f531 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 25 Dec 2019 11:04:31 +0000 Subject: [PATCH] functionObjects::writeObjects: Added option to disable regular expressions When selecting fields with complex automatically generated names it is cumbersome to escape all the regular expression meta characters and more convenient to specify the name as a literal string, the new regExp option provides the ability to switch the regular expression support and defaults to true for backward compatibility. For example to cache and write out an intermediate temporary field generated by the kOmegaSST model: cacheTemporaryObjects ( "((interpolate(((1|((1|(1|A(U)))-H(1)))-(1|A(U))))*snGrad(p))*magSf)" ); functions { #includeFunc writeObjects(regExp=off, "((interpolate(((1|((1|(1|A(U)))-H(1)))-(1|A(U))))*snGrad(p))*magSf)") } The regExp option can also be specified in a writeObjects dict as regExp off; Additionally regular expression support has been added to the includeFunc argument parsing. --- .../functionObjectList/functionObjectList.C | 7 ++----- .../writeObjectsBase/writeObjectsBase.C | 16 +++++++++++++++- .../writeObjectsBase/writeObjectsBase.H | 6 ++++++ .../utilities/writeObjects/writeObjects.H | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 9676ece13f..3fabfc7b1e 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -229,7 +229,7 @@ bool Foam::functionObjectList::readFunctionObject word funcName(funcCall); int argLevel = 0; - wordList args; + wordReList args; List> namedArgs; bool namedArg = false; @@ -274,10 +274,7 @@ bool Foam::functionObjectList::readFunctionObject } else { - args.append - ( - string::validate(funcCall(start, i - start)) - ); + args.append(wordRe(funcCall(start, i - start))); } start = i+1; } diff --git a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C index f0b3c7347e..95078cea52 100644 --- a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C +++ b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C @@ -114,7 +114,21 @@ Foam::functionObjects::writeObjectsBase::writeObjectNames() const bool Foam::functionObjects::writeObjectsBase::read(const dictionary& dict) { - dict.lookup("objects") >> writeObjectNames_; + regExp_ = dict.lookupOrDefault("regExp", true); + + if (regExp_) + { + dict.lookup("objects") >> writeObjectNames_; + } + else + { + const wordList objectNames(dict.lookup("objects")); + writeObjectNames_.setSize(objectNames.size()); + forAll(objectNames, i) + { + writeObjectNames_[i] = objectNames[i]; + } + } return true; } diff --git a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H index ed9eb078b6..85ee0f3a5e 100644 --- a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H +++ b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H @@ -47,6 +47,7 @@ Usage \table Property | Description | Required | Default value objects | List of objects to be written | yes | + regExp | Switch for regular expression support | no | true \endtable Note: Regular expressions can also be used in \c objects. @@ -66,6 +67,7 @@ SourceFiles #include "wordList.H" #include "wordReList.H" +#include "Switch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -97,6 +99,10 @@ protected: //- Reference to the inheriting function object's log variable const Switch& log_; + //- Optional switch for regular expression support + // Defaults to true + Switch regExp_; + //- Object names requested by the user to be written wordReList writeObjectNames_; diff --git a/src/functionObjects/utilities/writeObjects/writeObjects.H b/src/functionObjects/utilities/writeObjects/writeObjects.H index 2721401b77..a713e33b8b 100644 --- a/src/functionObjects/utilities/writeObjects/writeObjects.H +++ b/src/functionObjects/utilities/writeObjects/writeObjects.H @@ -116,6 +116,7 @@ public: static const NamedEnum writeOptionNames_; + private: // Private Data