ENH: relax the (zeroGradient, ddt2) replacement token requirement (#1330)

- when a single (non-regex) source field is specified, it is now
  possible to specify the result name without any '@@' substitution
  tokens
This commit is contained in:
Mark Olesen
2019-06-04 08:45:46 +02:00
committed by Andrew Heather
parent 2ce1ca48a8
commit 9d593adc98
4 changed files with 42 additions and 29 deletions

View File

@ -50,13 +50,15 @@ namespace functionObjects
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::ddt2::checkFormatName(const word& str) bool Foam::functionObjects::ddt2::checkFormatName
(
const std::string& str
)
{ {
if (str.find("@@") == string::npos) if (std::string::npos == str.find("@@"))
{ {
WarningInFunction WarningInFunction
<< "Bad result naming " << "Bad result naming (no '@@' token found)."
<< "(no '@@' token found), deactivating."
<< nl << endl; << nl << endl;
return false; return false;
@ -64,10 +66,8 @@ bool Foam::functionObjects::ddt2::checkFormatName(const word& str)
else if (str == "@@") else if (str == "@@")
{ {
WarningInFunction WarningInFunction
<< "Bad result naming " << "Bad result naming (only a '@@' token found)."
<< "(only a '@@' token found), deactivating." << nl << endl;
<< nl
<< endl;
return false; return false;
} }
@ -145,7 +145,12 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
( mag_ ? "mag(ddt(@@))" : "magSqr(ddt(@@))" ) ( mag_ ? "mag(ddt(@@))" : "magSqr(ddt(@@))" )
); );
if (checkFormatName(resultName_)) // Expect '@@' token for result, unless a single (non-regex) source field
if
(
(selectFields_.size() == 1 && selectFields_.first().isLiteral())
|| checkFormatName(resultName_)
)
{ {
blacklist_.set blacklist_.set
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,7 +62,8 @@ Usage
A list of fields can contain exact names or regular expressions. A list of fields can contain exact names or regular expressions.
The token '\@\@' in the result name is replaced by the name of the source The token '\@\@' in the result name is replaced by the name of the source
field. field. In the special case of a single source field (specified as
a non-regex), the '\@\@' token checking is suppressed.
The function object will skip over fields that appear to have The function object will skip over fields that appear to have
already been processed (ie, their names are similar to the output names). already been processed (ie, their names are similar to the output names).
@ -100,7 +101,7 @@ class ddt2
{ {
// Private data // Private data
//- Name of fields to process //- Name of fields to process.
wordRes selectFields_; wordRes selectFields_;
//- Formatting for the result fields. //- Formatting for the result fields.
@ -120,8 +121,8 @@ class ddt2
// Private Member Functions // Private Member Functions
//- Check that the word contains the appropriate substitution token(s). //- Check that string contains the appropriate substitution token(s).
static bool checkFormatName(const word& str); static bool checkFormatName(const std::string& str);
//- Accept unless field name appears to have already been processed //- Accept unless field name appears to have already been processed

View File

@ -49,13 +49,15 @@ namespace functionObjects
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::zeroGradient::checkFormatName(const word& str) bool Foam::functionObjects::zeroGradient::checkFormatName
(
const std::string& str
)
{ {
if (str.find("@@") == string::npos) if (std::string::npos == str.find("@@"))
{ {
WarningInFunction WarningInFunction
<< "Bad result naming " << "Bad result naming (no '@@' token found)."
<< "(no '@@' token found), deactivating."
<< nl << endl; << nl << endl;
return false; return false;
@ -63,10 +65,8 @@ bool Foam::functionObjects::zeroGradient::checkFormatName(const word& str)
else if (str == "@@") else if (str == "@@")
{ {
WarningInFunction WarningInFunction
<< "Bad result naming " << "Bad result naming (only a '@@' token found)."
<< "(only a '@@' token found), deactivating." << nl << endl;
<< nl
<< endl;
return false; return false;
} }
@ -118,7 +118,13 @@ bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
Info<< type() << " fields: " << selectFields_ << nl; Info<< type() << " fields: " << selectFields_ << nl;
resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)"); resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)");
return checkFormatName(resultName_);
// Require '@@' token for result, unless a single (non-regex) source field
return
(
(selectFields_.size() == 1 && selectFields_.first().isLiteral())
|| checkFormatName(resultName_)
);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -58,7 +58,8 @@ Usage
A list of fields can contain exact names or regular expressions. A list of fields can contain exact names or regular expressions.
The token '\@\@' in the result name is replaced by the name of the source The token '\@\@' in the result name is replaced by the name of the source
field. field. In the special case of a single source field (specified as
a non-regex), the '\@\@' token checking is suppressed.
The function object will skip over fields that would not benefit The function object will skip over fields that would not benefit
- ie, only processor, empty, zeroGradient, symmetry patches. - ie, only processor, empty, zeroGradient, symmetry patches.
@ -95,20 +96,20 @@ class zeroGradient
{ {
// Private data // Private data
//- Name of fields to process //- Name of fields to process.
wordRes selectFields_; wordRes selectFields_;
//- Formatting for the result fields. //- Formatting for the result fields.
word resultName_; word resultName_;
//- Hashed names of result fields, and their type //- Hashed names of result fields, and their type.
HashTable<word> results_; HashTable<word> results_;
// Private Member Functions // Private Member Functions
//- Check that the word contains the appropriate substitution token(s). //- Check that string contains the appropriate substitution token(s).
static bool checkFormatName(const word& str); static bool checkFormatName(const std::string& str);
//- Accept unless field only has constraint patches //- Accept unless field only has constraint patches