diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 0b32757771..6a01e21e87 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -337,38 +337,49 @@ 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) - { - 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 + wordList fieldArgs(args); forAll(namedArgs, i) { - IStringStream entryStream + if (namedArgs[i].first() == "field") + { + fieldArgs.append(namedArgs[i].second()); + } + if ( - namedArgs[i].first() + ' ' + namedArgs[i].second() + ';' - ); - funcDict.set(entry::New(entryStream).ptr()); + namedArgs[i].first() == "fields" + || namedArgs[i].first() == "objects" + ) + { + 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 @@ -399,51 +410,27 @@ 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"))); - } - else if (expandedFuncDict.found("fields")) - { - ITstream& is = expandedFuncDict.lookup("fields"); - - // Read BEGIN_LIST - const token firstToken(is); - - if + requiredFields.insert ( - 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 - ) - { - requiredFields.insert - ( - wordList - ( - dictionary(expandedFuncDict.lookup("fields")).toc() - ) - ); - } - else - { - requiredFields.insert - ( - wordList(expandedFuncDict.lookup("fields")) - ); - } - } + word(expandedFuncDict.lookup("field")) + ); + } + if (expandedFuncDict.found("fields")) + { + requiredFields.insert + ( + wordOrDictNameList(expandedFuncDict.lookup("fields")) + ); + } + if (expandedFuncDict.found("objects")) + { + requiredFields.insert + ( + wordOrDictNameList(expandedFuncDict.lookup("objects")) + ); } // Merge this functionObject dictionary into functionsDict diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index fa48aabf01..c94aa194cf 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -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(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(l) = wordList(List(is)); + + return is; + } + }; + + public: // Static Data Members