functionObjectList: Improved flexibility of field argument parsing
Function object argument parsing now takes all "field", "fields" and
"objects" arguments and combines them into a single list of
fields/objects that the function should operate on. This means that the
following postProcess executions are now all equivalent and function as
expected:
postProcess -func "
flowRatePatch
(
name=outlet,
phi,
alphaRhoPhi.air,
alphaRhoPhi.particles
)"
postProcess -func "
flowRatePatch
(
name=outlet,
fields=(phi alphaRhoPhi.air alphaRhoPhi.particles)
)"
postProcess -func "
flowRatePatch
(
name=outlet,
objects=(phi),
alphaRhoPhi.air,
field=alphaRhoPhi.particles
)"
As are the following:
postProcess -func "mag(U.air)"
postProcess -func "mag(field=U.air)"
This commit is contained in:
@ -337,32 +337,42 @@ bool Foam::functionObjectList::readFunctionObject
|
||||
// Insert the 'field' and/or 'fields' entry corresponding to the optional
|
||||
// arguments or read the 'field' or 'fields' entry and add the required
|
||||
// fields to requiredFields
|
||||
if (args.size() == 1)
|
||||
wordList fieldArgs(args);
|
||||
forAll(namedArgs, i)
|
||||
{
|
||||
if (funcDict.found("objects"))
|
||||
if (namedArgs[i].first() == "field")
|
||||
{
|
||||
funcDict.set("objects", args);
|
||||
fieldArgs.append(namedArgs[i].second());
|
||||
}
|
||||
else
|
||||
if
|
||||
(
|
||||
namedArgs[i].first() == "fields"
|
||||
|| namedArgs[i].first() == "objects"
|
||||
)
|
||||
{
|
||||
funcDict.set("field", args[0]);
|
||||
funcDict.set("fields", args);
|
||||
IStringStream iss(namedArgs[i].second());
|
||||
fieldArgs.append(wordList(iss));
|
||||
}
|
||||
}
|
||||
else if (args.size() > 1)
|
||||
if (fieldArgs.size() >= 1)
|
||||
{
|
||||
if (funcDict.found("objects"))
|
||||
if (fieldArgs.size() == 1)
|
||||
{
|
||||
funcDict.set("objects", args);
|
||||
}
|
||||
else
|
||||
{
|
||||
funcDict.set("fields", args);
|
||||
funcDict.set("field", fieldArgs[0]);
|
||||
}
|
||||
funcDict.set("fields", fieldArgs);
|
||||
funcDict.set("objects", fieldArgs);
|
||||
}
|
||||
|
||||
// Insert named arguments
|
||||
// Insert non-field arguments
|
||||
forAll(namedArgs, i)
|
||||
{
|
||||
if
|
||||
(
|
||||
namedArgs[i].first() != "field"
|
||||
&& namedArgs[i].first() != "fields"
|
||||
&& namedArgs[i].first() != "objects"
|
||||
)
|
||||
{
|
||||
IStringStream entryStream
|
||||
(
|
||||
@ -370,6 +380,7 @@ bool Foam::functionObjectList::readFunctionObject
|
||||
);
|
||||
funcDict.set(entry::New(entryStream).ptr());
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the region name if specified
|
||||
if (region != word::null)
|
||||
@ -399,52 +410,28 @@ bool Foam::functionObjectList::readFunctionObject
|
||||
// Lookup the field and fields entries from the now expanded funcDict
|
||||
// and insert into the requiredFields
|
||||
dictionary& expandedFuncDict = funcArgsDict.subDict(funcCallKeyword);
|
||||
|
||||
if (expandedFuncDict.found("field"))
|
||||
{
|
||||
requiredFields.insert(word(expandedFuncDict.lookup("field")));
|
||||
requiredFields.insert
|
||||
(
|
||||
word(expandedFuncDict.lookup("field"))
|
||||
);
|
||||
}
|
||||
else if (expandedFuncDict.found("fields"))
|
||||
{
|
||||
ITstream& is = expandedFuncDict.lookup("fields");
|
||||
|
||||
// Read BEGIN_LIST
|
||||
const token firstToken(is);
|
||||
|
||||
if
|
||||
(
|
||||
firstToken.isPunctuation()
|
||||
&& firstToken.pToken() == token::BEGIN_LIST
|
||||
)
|
||||
{
|
||||
// Read first field name
|
||||
const token secondToken(is);
|
||||
|
||||
// Read second field name or BEGIN_BLOCK
|
||||
const token thirdToken(is);
|
||||
|
||||
if
|
||||
(
|
||||
thirdToken.isPunctuation()
|
||||
&& thirdToken.pToken() == token::BEGIN_BLOCK
|
||||
)
|
||||
if (expandedFuncDict.found("fields"))
|
||||
{
|
||||
requiredFields.insert
|
||||
(
|
||||
wordList
|
||||
(
|
||||
dictionary(expandedFuncDict.lookup("fields")).toc()
|
||||
)
|
||||
wordOrDictNameList(expandedFuncDict.lookup("fields"))
|
||||
);
|
||||
}
|
||||
else
|
||||
if (expandedFuncDict.found("objects"))
|
||||
{
|
||||
requiredFields.insert
|
||||
(
|
||||
wordList(expandedFuncDict.lookup("fields"))
|
||||
wordOrDictNameList(expandedFuncDict.lookup("objects"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge this functionObject dictionary into functionsDict
|
||||
functionsDict.merge(funcArgsDict);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -45,6 +45,7 @@ SourceFiles
|
||||
#include "SHA1Digest.H"
|
||||
#include "HashTable.H"
|
||||
#include "HashSet.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -104,6 +105,65 @@ class functionObjectList
|
||||
);
|
||||
|
||||
|
||||
// Private Classes
|
||||
|
||||
class wordOrDictName;
|
||||
|
||||
friend Istream& operator>>(Istream& is, wordOrDictName& w);
|
||||
|
||||
//- Class to facilitate reading of either a word or the name of a
|
||||
// dictionary
|
||||
class wordOrDictName
|
||||
:
|
||||
public word
|
||||
{
|
||||
public:
|
||||
|
||||
using word::word;
|
||||
|
||||
friend Istream& operator>>(Istream& is, wordOrDictName& w)
|
||||
{
|
||||
is >> static_cast<word&>(w);
|
||||
|
||||
token t(is);
|
||||
|
||||
if (t.isPunctuation() && t.pToken() == token::BEGIN_BLOCK)
|
||||
{
|
||||
is.putBack(t);
|
||||
dictionary d(is);
|
||||
}
|
||||
else
|
||||
{
|
||||
is.putBack(t);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
};
|
||||
|
||||
class wordOrDictNameList;
|
||||
|
||||
friend Istream& operator>>(Istream& is, wordOrDictNameList& l);
|
||||
|
||||
//- Class to facilitate reading of either a list of words or the names
|
||||
// of a list of dictionaries
|
||||
class wordOrDictNameList
|
||||
:
|
||||
public wordList
|
||||
{
|
||||
public:
|
||||
|
||||
using wordList::wordList;
|
||||
|
||||
friend Istream& operator>>(Istream& is, wordOrDictNameList& l)
|
||||
{
|
||||
static_cast<wordList&>(l) = wordList(List<wordOrDictName>(is));
|
||||
|
||||
return is;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static Data Members
|
||||
|
||||
Reference in New Issue
Block a user