includeFunc: Added 'funcName' option to set the name of the functionObject entry in the functions list

This is used to set the directory name for the results of the functionObject, if
not specified a unique name is generated automatically from the function type
and argument list, e.g.

    #includeFunc patchAverage(name=inlet, fields=(p U))

writes surfaceFieldValue.dat in postProcessing/patchAverage(name=inlet,fields=(pU))/0 and

    #includeFunc patchAverage(funcName=inlet, name=inlet, fields=(p U))

writes surfaceFieldValue.dat in postProcessing/inlet/0.
This commit is contained in:
Henry Weller
2020-12-11 17:10:46 +00:00
parent b594bcb753
commit f5b0a27241

View File

@ -224,19 +224,19 @@ bool Foam::functionObjectList::readFunctionObject
const word& region const word& region
) )
{ {
word funcName; word funcType;
wordReList args; wordReList args;
List<Tuple2<word, string>> namedArgs; List<Tuple2<word, string>> namedArgs;
dictArgList(funcArgs, funcName, args, namedArgs); dictArgList(funcArgs, funcType, args, namedArgs);
// Search for the functionObject dictionary // Search for the functionObject dictionary
fileName path = findDict(funcName, region); fileName path = findDict(funcType, region);
if (path == fileName::null) if (path == fileName::null)
{ {
WarningInFunction WarningInFunction
<< "Cannot find functionObject file " << funcName << endl; << "Cannot find functionObject file " << funcType << endl;
return false; return false;
} }
@ -248,14 +248,14 @@ bool Foam::functionObjectList::readFunctionObject
// Delay processing the functionEntries // Delay processing the functionEntries
// until after the function argument entries have been added // until after the function argument entries have been added
entry::disableFunctionEntries = true; entry::disableFunctionEntries = true;
dictionary funcsDict(funcName, functionsDict, fileStream); dictionary funcsDict(funcType, functionsDict, fileStream);
entry::disableFunctionEntries = false; entry::disableFunctionEntries = false;
dictionary* funcDictPtr = &funcsDict; dictionary* funcDictPtr = &funcsDict;
if (funcsDict.found(funcName) && funcsDict.isDict(funcName)) if (funcsDict.found(funcType) && funcsDict.isDict(funcType))
{ {
funcDictPtr = &funcsDict.subDict(funcName); funcDictPtr = &funcsDict.subDict(funcType);
} }
dictionary& funcDict = *funcDictPtr; dictionary& funcDict = *funcDictPtr;
@ -324,9 +324,16 @@ bool Foam::functionObjectList::readFunctionObject
funcDict.set("region", region); funcDict.set("region", region);
} }
const word funcArgsKeyword = string::validate<word>(funcArgs); // Set the name of the function entry to that specified by the optional
// funcName argument otherwise automatically generate a unique name
// from the function type and arguments
const word funcName
(
funcDict.lookupOrDefault("funcName", string::validate<word>(funcArgs))
);
dictionary funcArgsDict; dictionary funcArgsDict;
funcArgsDict.add(funcArgsKeyword, funcDict); funcArgsDict.add(funcName, funcDict);
// Re-parse the funcDict to execute the functionEntries // Re-parse the funcDict to execute the functionEntries
// now that the function argument entries have been added // now that the function argument entries have been added
@ -335,7 +342,7 @@ bool Foam::functionObjectList::readFunctionObject
funcArgsDict.write(os); funcArgsDict.write(os);
funcArgsDict = dictionary funcArgsDict = dictionary
( (
funcName, funcType,
functionsDict, functionsDict,
IStringStream(os.str())() IStringStream(os.str())()
); );
@ -346,7 +353,7 @@ bool Foam::functionObjectList::readFunctionObject
// Lookup the field, fields and objects entries from the now expanded // Lookup the field, fields and objects entries from the now expanded
// funcDict and insert into the requiredFields // funcDict and insert into the requiredFields
dictionary& expandedFuncDict = funcArgsDict.subDict(funcArgsKeyword); dictionary& expandedFuncDict = funcArgsDict.subDict(funcName);
if (functionObject::debug) if (functionObject::debug)
{ {
InfoInFunction InfoInFunction
@ -377,7 +384,7 @@ bool Foam::functionObjectList::readFunctionObject
// Merge this functionObject dictionary into functionsDict // Merge this functionObject dictionary into functionsDict
functionsDict.merge(funcArgsDict); functionsDict.merge(funcArgsDict);
functionsDict.subDict(funcArgsKeyword).name() = funcDict.name(); functionsDict.subDict(funcName).name() = funcDict.name();
return true; return true;
} }