diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H index 64d6b3c2f5..8c67c54403 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -119,8 +119,6 @@ public: primitiveEntry&, Istream& ); - - }; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C index c33e3a887d..79644653a9 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C @@ -25,28 +25,16 @@ License #include "includeFuncEntry.H" #include "functionObjectList.H" -#include "dictionary.H" -#include "IFstream.H" #include "addToMemberFunctionSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::word Foam::functionEntries::includeFuncEntry::typeName -( - Foam::functionEntries::includeFuncEntry::typeName_() -); - -// Don't lookup the debug switch here as the debug switch dictionary -// might include includeFuncEntry -int Foam::functionEntries::includeFuncEntry::debug(0); - -bool Foam::functionEntries::includeFuncEntry::report(false); - - namespace Foam { namespace functionEntries { + defineTypeNameAndDebug(includeFuncEntry, 0); + addToMemberFunctionSelectionTable ( functionEntry, @@ -54,29 +42,9 @@ namespace functionEntries execute, dictionaryIstream ); - - addToMemberFunctionSelectionTable - ( - functionEntry, - includeFuncEntry, - execute, - primitiveEntryIstream - ); } } -// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // - -Foam::fileName Foam::functionEntries::includeFuncEntry::funcPath -( - const word& fName, - const dictionary& dict -) -{ - // Search the system and etc directories for the file and return the path - return functionObjectList::findDict(fName); -} - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -86,66 +54,15 @@ bool Foam::functionEntries::includeFuncEntry::execute Istream& is ) { - const word fName(is); - const fileName fPath(funcPath(fName, parentDict)); - IFstream ifs(fPath); + const word fNameArgs(is); + HashSet selectedFields; - if (ifs) - { - if (Foam::functionEntries::includeFuncEntry::report) - { - Info<< fPath << endl; - } - parentDict.read(ifs); - return true; - } - else - { - FatalIOErrorInFunction - ( - is - ) << "Cannot open functionObject file " - << (ifs.name().size() ? ifs.name() : fileName(fName)) - << " while reading dictionary " << parentDict.name() - << exit(FatalIOError); - - return false; - } -} - - -bool Foam::functionEntries::includeFuncEntry::execute -( - const dictionary& parentDict, - primitiveEntry& entry, - Istream& is -) -{ - const word fName(is); - const fileName fPath(funcPath(fName, parentDict)); - IFstream ifs(fPath); - - if (ifs) - { - if (Foam::functionEntries::includeFuncEntry::report) - { - Info<< fPath << endl; - } - entry.read(parentDict, ifs); - return true; - } - else - { - FatalIOErrorInFunction - ( - is - ) << "Cannot open functionObject file " - << (ifs.name().size() ? ifs.name() : fileName(fName)) - << " while reading dictionary " << parentDict.name() - << exit(FatalIOError); - - return false; - } + return functionObjectList::readFunctionObject + ( + fNameArgs, + parentDict, + selectedFields + ); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H index 9cae783062..71a47c0fb6 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H @@ -50,7 +50,7 @@ Description \endverbatim See Also - functionObjectList::findDict + Foam::functionObjectList SourceFiles includeFuncEntry.C @@ -77,30 +77,9 @@ class includeFuncEntry : public functionEntry { - // Private Member Functions - - //- Disallow default bitwise copy construct - includeFuncEntry(const includeFuncEntry&); - - //- Disallow default bitwise assignment - void operator=(const includeFuncEntry&); - - //- Return the path to the functionObject dictionary path - static fileName funcPath - ( - const word& fName, - const dictionary& dict - ); - public: - // Static data members - - //- Report which file is included to stdout - static bool report; - - //- Runtime type information ClassName("includeFunc"); @@ -109,14 +88,6 @@ public: //- Execute the functionEntry in a sub-dict context static bool execute(dictionary& parentDict, Istream&); - - //- Execute the functionEntry in a primitiveEntry context - static bool execute - ( - const dictionary& parentDict, - primitiveEntry&, - Istream& - ); }; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 041c3b98e4..72804ed5cd 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -99,11 +99,11 @@ Foam::fileName Foam::functionObjectList::findDict(const word& funcName) } -void Foam::functionObjectList::readFunctionObject +bool Foam::functionObjectList::readFunctionObject ( const word& funcNameArgs0, dictionary& functionsDict, - HashSet& selectedFields + HashSet& requiredFields ) { // Parse the optional functionObject arguments @@ -153,7 +153,7 @@ void Foam::functionObjectList::readFunctionObject { WarningInFunction << "Cannot find functionObject file " << funcName << endl; - return; + return false; } // Read the functionObject dictionary @@ -163,30 +163,32 @@ void Foam::functionObjectList::readFunctionObject // Insert the 'field' or 'fields' entry corresponding to the optional // arguments or read the 'field' or 'fields' entry and add the required - // fields to selectedFields + // fields to requiredFields if (args.size() == 1) { funcDict.set("field", args[0]); - selectedFields.insert(args[0]); + requiredFields.insert(args[0]); } else if (args.size() > 1) { funcDict.set("fields", args); - selectedFields.insert(args); + requiredFields.insert(args); } else if (funcDict.found("field")) { - selectedFields.insert(word(funcDict.lookup("field"))); + requiredFields.insert(word(funcDict.lookup("field"))); } else if (funcDict.found("fields")) { - selectedFields.insert(wordList(funcDict.lookup("fields"))); + requiredFields.insert(wordList(funcDict.lookup("fields"))); } // Merge this functionObject dictionary into functionsDict dictionary funcArgsDict; funcArgsDict.add(funcNameArgs, funcDict); - functionsDict.subDict("functions").merge(funcArgsDict); + functionsDict.merge(funcArgsDict); + + return true; } @@ -229,17 +231,19 @@ Foam::autoPtr Foam::functionObjectList::New ( const argList& args, const Time& runTime, - dictionary& functionsDict, - HashSet& selectedFields + dictionary& controlDict, + HashSet& requiredFields ) { autoPtr functionsPtr; - functionsDict.add + controlDict.add ( - dictionaryEntry("functions", functionsDict, dictionary::null) + dictionaryEntry("functions", controlDict, dictionary::null) ); + dictionary& functionsDict = controlDict.subDict("functions"); + if ( args.optionFound("dict") @@ -249,7 +253,7 @@ Foam::autoPtr Foam::functionObjectList::New { if (args.optionFound("dict")) { - functionsDict.merge + controlDict.merge ( IOdictionary ( @@ -265,7 +269,7 @@ Foam::autoPtr Foam::functionObjectList::New if (args.optionFound("func")) { - readFunctionObject(args["func"], functionsDict, selectedFields); + readFunctionObject(args["func"], functionsDict, requiredFields); } if (args.optionFound("funcs")) @@ -274,11 +278,11 @@ Foam::autoPtr Foam::functionObjectList::New forAll(funcs, i) { - readFunctionObject(funcs[i], functionsDict, selectedFields); + readFunctionObject(funcs[i], functionsDict, requiredFields); } } - functionsPtr.reset(new functionObjectList(runTime, functionsDict)); + functionsPtr.reset(new functionObjectList(runTime, controlDict)); } else { diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index b69d0d7aae..788b4b8884 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -91,13 +91,6 @@ class functionObjectList // Returns a NULL pointer (and index -1) if it didn't exist. functionObject* remove(const word&, label& oldIndex); - static void readFunctionObject - ( - const word& funcNameArgs0, - dictionary& functionsDict, - HashSet& selectedFields - ); - //- Disallow default bitwise copy construct functionObjectList(const functionObjectList&); @@ -142,14 +135,14 @@ public: //- Construct and return a functionObjectList for an application. // If the "dict" argument is specified the functionObjectList is // constructed from that dictionary which is returned as - // functionObjectsDict otherwise the functionObjectList is constructed + // controlDict otherwise the functionObjectList is constructed // from the "functions" sub-dictionary of "system/controlDict" static autoPtr New ( const argList& args, const Time& runTime, - dictionary& functionObjectsDict, - HashSet& selectedFields + dictionary& controlDict, + HashSet& requiredFields ); @@ -194,6 +187,19 @@ public: // otherwise null static fileName findDict(const word& funcName); + //- Read the specified functionObject configuration dictionary parsing + // the optional arguments included in the name 'funcNameArgs0', + // inserting 'field' or 'fields' entries as required and merging the + // resulting functionObject dictionary into 'functionsDict'. Any + // fields required to execute the functionObject are added to + // 'requiredFields' + static bool readFunctionObject + ( + const word& funcNameArgs0, + dictionary& functionsDict, + HashSet& requiredFields + ); + //- Read and set the function objects if their data have changed bool read(); diff --git a/tutorials/compressible/sonicFoam/laminar/shockTube/system/controlDict b/tutorials/compressible/sonicFoam/laminar/shockTube/system/controlDict index 7a1b060649..7c916f2a5e 100644 --- a/tutorials/compressible/sonicFoam/laminar/shockTube/system/controlDict +++ b/tutorials/compressible/sonicFoam/laminar/shockTube/system/controlDict @@ -47,8 +47,7 @@ runTimeModifiable true; functions { - #includeFunc mag - mag{field U;} + #includeFunc mag(U) } // ************************************************************************* // diff --git a/tutorials/electromagnetics/mhdFoam/hartmann/system/controlDict b/tutorials/electromagnetics/mhdFoam/hartmann/system/controlDict index 42c61af392..4c8a1aef5a 100644 --- a/tutorials/electromagnetics/mhdFoam/hartmann/system/controlDict +++ b/tutorials/electromagnetics/mhdFoam/hartmann/system/controlDict @@ -47,8 +47,7 @@ runTimeModifiable true; functions { - #includeFunc components - components{field U;} + #includeFunc components(U) } // ************************************************************************* //