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,38 +337,49 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
// Insert the 'field' and/or 'fields' entry corresponding to the optional
|
// Insert the 'field' and/or 'fields' entry corresponding to the optional
|
||||||
// arguments or read the 'field' or 'fields' entry and add the required
|
// arguments or read the 'field' or 'fields' entry and add the required
|
||||||
// fields to requiredFields
|
// fields to requiredFields
|
||||||
if (args.size() == 1)
|
wordList fieldArgs(args);
|
||||||
{
|
|
||||||
if (funcDict.found("objects"))
|
|
||||||
{
|
|
||||||
funcDict.set("objects", args);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
funcDict.set("field", args[0]);
|
|
||||||
funcDict.set("fields", args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (args.size() > 1)
|
|
||||||
{
|
|
||||||
if (funcDict.found("objects"))
|
|
||||||
{
|
|
||||||
funcDict.set("objects", args);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
funcDict.set("fields", args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert named arguments
|
|
||||||
forAll(namedArgs, i)
|
forAll(namedArgs, i)
|
||||||
{
|
{
|
||||||
IStringStream entryStream
|
if (namedArgs[i].first() == "field")
|
||||||
|
{
|
||||||
|
fieldArgs.append(namedArgs[i].second());
|
||||||
|
}
|
||||||
|
if
|
||||||
(
|
(
|
||||||
namedArgs[i].first() + ' ' + namedArgs[i].second() + ';'
|
namedArgs[i].first() == "fields"
|
||||||
);
|
|| namedArgs[i].first() == "objects"
|
||||||
funcDict.set(entry::New(entryStream).ptr());
|
)
|
||||||
|
{
|
||||||
|
IStringStream iss(namedArgs[i].second());
|
||||||
|
fieldArgs.append(wordList(iss));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fieldArgs.size() >= 1)
|
||||||
|
{
|
||||||
|
if (fieldArgs.size() == 1)
|
||||||
|
{
|
||||||
|
funcDict.set("field", fieldArgs[0]);
|
||||||
|
}
|
||||||
|
funcDict.set("fields", fieldArgs);
|
||||||
|
funcDict.set("objects", fieldArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert non-field arguments
|
||||||
|
forAll(namedArgs, i)
|
||||||
|
{
|
||||||
|
if
|
||||||
|
(
|
||||||
|
namedArgs[i].first() != "field"
|
||||||
|
&& namedArgs[i].first() != "fields"
|
||||||
|
&& namedArgs[i].first() != "objects"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
IStringStream entryStream
|
||||||
|
(
|
||||||
|
namedArgs[i].first() + ' ' + namedArgs[i].second() + ';'
|
||||||
|
);
|
||||||
|
funcDict.set(entry::New(entryStream).ptr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the region name if specified
|
// Insert the region name if specified
|
||||||
@ -399,51 +410,27 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
// Lookup the field and fields entries from the now expanded funcDict
|
// Lookup the field and fields entries from the now expanded funcDict
|
||||||
// and insert into the requiredFields
|
// and insert into the requiredFields
|
||||||
dictionary& expandedFuncDict = funcArgsDict.subDict(funcCallKeyword);
|
dictionary& expandedFuncDict = funcArgsDict.subDict(funcCallKeyword);
|
||||||
|
|
||||||
if (expandedFuncDict.found("field"))
|
if (expandedFuncDict.found("field"))
|
||||||
{
|
{
|
||||||
requiredFields.insert(word(expandedFuncDict.lookup("field")));
|
requiredFields.insert
|
||||||
}
|
|
||||||
else if (expandedFuncDict.found("fields"))
|
|
||||||
{
|
|
||||||
ITstream& is = expandedFuncDict.lookup("fields");
|
|
||||||
|
|
||||||
// Read BEGIN_LIST
|
|
||||||
const token firstToken(is);
|
|
||||||
|
|
||||||
if
|
|
||||||
(
|
(
|
||||||
firstToken.isPunctuation()
|
word(expandedFuncDict.lookup("field"))
|
||||||
&& firstToken.pToken() == token::BEGIN_LIST
|
);
|
||||||
)
|
}
|
||||||
{
|
if (expandedFuncDict.found("fields"))
|
||||||
// Read first field name
|
{
|
||||||
const token secondToken(is);
|
requiredFields.insert
|
||||||
|
(
|
||||||
// Read second field name or BEGIN_BLOCK
|
wordOrDictNameList(expandedFuncDict.lookup("fields"))
|
||||||
const token thirdToken(is);
|
);
|
||||||
|
}
|
||||||
if
|
if (expandedFuncDict.found("objects"))
|
||||||
(
|
{
|
||||||
thirdToken.isPunctuation()
|
requiredFields.insert
|
||||||
&& thirdToken.pToken() == token::BEGIN_BLOCK
|
(
|
||||||
)
|
wordOrDictNameList(expandedFuncDict.lookup("objects"))
|
||||||
{
|
);
|
||||||
requiredFields.insert
|
|
||||||
(
|
|
||||||
wordList
|
|
||||||
(
|
|
||||||
dictionary(expandedFuncDict.lookup("fields")).toc()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
requiredFields.insert
|
|
||||||
(
|
|
||||||
wordList(expandedFuncDict.lookup("fields"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge this functionObject dictionary into functionsDict
|
// Merge this functionObject dictionary into functionsDict
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -45,6 +45,7 @@ SourceFiles
|
|||||||
#include "SHA1Digest.H"
|
#include "SHA1Digest.H"
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "HashSet.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:
|
public:
|
||||||
|
|
||||||
// Static Data Members
|
// Static Data Members
|
||||||
|
|||||||
Reference in New Issue
Block a user