diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H index e475982bdc..7deb25076f 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H @@ -80,15 +80,6 @@ Description #{ Pout<< "**codeSetValue**" << endl; #}; - - // Dummy entry. Make dependent on above to trigger recompilation - code - #{ - $codeInclude - $codeCorrect - $codeAddSup - $codeSetValue - #}; } sourceTimeCoeffs diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 552f3941ca..89c20e9d81 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,8 +59,8 @@ namespace functionEntries } -const Foam::word Foam::functionEntries::codeStream::codeTemplateC - = "codeStreamTemplate.C"; +const Foam::word Foam::functionEntries::codeStream::codeTemplateC = + "codeStreamTemplate.C"; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -123,8 +123,8 @@ Foam::functionEntries::codeStream::getFunction const dictionary& codeDict ) { - // get code, codeInclude, codeOptions - dynamicCodeContext context(codeDict); + // get code, codeInclude, ... + dynamicCodeContext context(codeDict, {"code", "codeInclude", "localCode"}); // codeName: codeStream + _ // codeDir : _ diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C index 9f576d4714..6dbf271493 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -293,7 +293,7 @@ void Foam::codedBase::updateLibrary dict ); - dynamicCodeContext context(dict); + dynamicCodeContext context(dict, codeKeys()); // codeName: name + _ // codeDir : name diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H index 88d489f020..7f924d76b0 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -92,30 +92,26 @@ class codedBase protected: //- Update library as required - void updateLibrary - ( - const word& name - ) const; + void updateLibrary(const word& name) const; //- Get the loaded dynamic libraries virtual dlLibraryTable& libs() const = 0; //- Adapt the context for the current object - virtual void prepare - ( - dynamicCode&, - const dynamicCodeContext& - ) const = 0; + virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0; - // Return a description (type + name) for the output + //- Return a description (type + name) for the output virtual string description() const = 0; - // Clear any redirected objects + //- Clear any redirected objects virtual void clearRedirect() const = 0; - // Get the dictionary to initialize the codeContext + //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const = 0; + //- Get the keywords associated with source code + virtual const wordList& codeKeys() const = 0; + public: diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index 87e7fd07f2..4c9c763179 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -343,7 +343,13 @@ void Foam::dynamicCode::reset ) { clear(); - setFilterContext(context); + + forAllConstIter(HashTable, context.code(), iter) + { + setFilterVariable(iter.key(), iter()); + } + + setFilterVariable("SHA1sum", context.sha1().str()); } @@ -369,18 +375,6 @@ void Foam::dynamicCode::addCreateFile } -void Foam::dynamicCode::setFilterContext -( - const dynamicCodeContext& context -) -{ - filterVars_.set("localCode", context.localCode()); - filterVars_.set("code", context.code()); - filterVars_.set("codeInclude", context.include()); - filterVars_.set("SHA1sum", context.sha1().str()); -} - - void Foam::dynamicCode::setFilterVariable ( const word& key, diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H index 6a6f5a97ff..3cda3e3404 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -259,9 +259,6 @@ public: //- Add a file to create with its contents. Will not be filtered void addCreateFile(const fileName& name, const string& contents); - //- Define filter variables for code, codeInclude, SHA1sum - void setFilterContext(const dynamicCodeContext&); - //- Define a filter variable void setFilterVariable(const word& key, const std::string& value); diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C index d54bf297a4..42550e3e23 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,102 +27,7 @@ License #include "stringOps.H" #include "OSHA1stream.H" -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) -: - dict_(dict), - code_(), - localCode_(), - include_(), - options_(), - libs_() -{ - // Expand dictionary entries - - // Note: removes any leading/trailing whitespace - // - necessary for compilation options, convenient for includes - // and body. - - const entry* codePtr = dict.lookupEntryPtr - ( - "code", - false, - false - ); - if (codePtr) - { - code_ = stringOps::trim(codePtr->stream()); - stringOps::inplaceExpand(code_, dict); - } - - const entry* includePtr = dict.lookupEntryPtr - ( - "codeInclude", - false, - false - ); - if (includePtr) - { - include_ = stringOps::trim(includePtr->stream()); - stringOps::inplaceExpand(include_, dict); - } - - const entry* optionsPtr = dict.lookupEntryPtr - ( - "codeOptions", - false, - false - ); - if (optionsPtr) - { - options_ = stringOps::trim(optionsPtr->stream()); - stringOps::inplaceExpand(options_, dict); - } - - const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false); - if (libsPtr) - { - libs_ = stringOps::trim(libsPtr->stream()); - stringOps::inplaceExpand(libs_, dict); - } - - const entry* localPtr = dict.lookupEntryPtr("localCode", false, false); - if (localPtr) - { - localCode_ = stringOps::trim(localPtr->stream()); - stringOps::inplaceExpand(localCode_, dict); - } - - // Calculate SHA1 digest from include, options, localCode, code - OSHA1stream os; - os << include_ << options_ << libs_ << localCode_ << code_; - sha1_ = os.digest(); - - - // Add line number after calculating sha1 since includes processorDDD - // in path which differs between processors. - - if (codePtr) - { - addLineDirective(code_, codePtr->startLineNumber(), dict.name()); - } - - if (includePtr) - { - addLineDirective(include_, includePtr->startLineNumber(), dict.name()); - } - - // Do not add line directive to options_ (Make/options) and libs since - // they are preprocessed as a single line at this point. Can be fixed. - if (localPtr) - { - addLineDirective(localCode_, localPtr->startLineNumber(), dict.name()); - } -} - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::dynamicCodeContext::addLineDirective ( @@ -135,4 +40,69 @@ void Foam::dynamicCodeContext::addLineDirective } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::dynamicCodeContext::dynamicCodeContext +( + const dictionary& dict, + const wordList& codeKeys +) +: + dict_(dict), + code_(), + options_(), + libs_() +{ + // Expand all dictionary entries. Note that this removes any leading or + // trailing whitespace, which is necessary for compilation options, and + // doesn't hurt for everything else + List codePtrs(codeKeys.size(), nullptr); + forAll(codeKeys, i) + { + const word& key = codeKeys[i]; + codePtrs[i] = dict.lookupEntryPtr(key, false, false); + if (codePtrs[i]) + { + code_.insert + ( + key, + stringOps::expand + ( + stringOps::trim(codePtrs[i]->stream()), + dict + ) + ); + } + else + { + code_.insert(key, ""); + } + } + + // Calculate SHA1 digest from all entries + OSHA1stream os; + forAllConstIter(HashTable, code_, iter) + { + os << iter(); + } + sha1_ = os.digest(); + + // Add line directive after calculating SHA1 since this includes + // "processor..." in the path which differs between cores + forAll(codeKeys, i) + { + if (codePtrs[i]) + { + const word& key = codeKeys[i]; + addLineDirective + ( + code_[key], + codePtrs[i]->startLineNumber(), + dict.name() + ); + } + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H index 914ab53348..7c5f8edffd 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,6 +36,7 @@ SourceFiles #define dynamicCodeContext_H #include "dictionary.H" +#include "HashTable.H" #include "SHA1Digest.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,31 +55,42 @@ class dynamicCodeContext //- The parent dictionary context const dictionary& dict_; - //- Optional "code" entry - string code_; - - //- Optional "localCode" entry - string localCode_; - - //- Optional "codeInclude" entry - string include_; + //- Code entries + HashTable code_; //- Optional "codeOptions" entry string options_; - //- Optional "codeLib" entry + //- Optional "codeLibs" entry string libs_; //- Calculated SHA1Digest SHA1Digest sha1_; + // Private member functions + + //- Add a \#line directive to the start of the given source string that + // compilation messages are meaningful + static void addLineDirective + ( + string&, + const label lineNum, + const fileName& name + ); + + public: // Constructors - //- Construct from a dictionary - dynamicCodeContext(const dictionary&); + //- Construct from a dictionary and lists of which entries correspond + // to code + dynamicCodeContext + ( + const dictionary& dict, + const wordList& codeKeys + ); // Member functions @@ -89,10 +101,10 @@ public: return dict_; } - //- Return the code-includes - const string& include() const + //- Return the code table + const HashTable& code() const { - return include_; + return code_; } //- Return the code-options @@ -107,31 +119,11 @@ public: return libs_; } - //- Return the code - const string& code() const - { - return code_; - } - - //- Return the local (file-scope) code - const string& localCode() const - { - return localCode_; - } - //- Return SHA1 digest calculated from include, options, code const SHA1Digest& sha1() const { return sha1_; } - - //- Helper: add \#line directive - static void addLineDirective - ( - string&, - const label lineNum, - const fileName& name - ); }; diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index e5662598d1..b067390698 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -31,15 +31,22 @@ License #include "dynamicCodeContext.H" #include "stringOps.H" +// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // + +template +const Foam::wordList Foam::codedFixedValuePointPatchField::codeKeys_ = + {"code", "codeInclude", "localCode"}; + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template -const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateC - = "fixedValuePointPatchFieldTemplate.C"; +const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateC = + "fixedValuePointPatchFieldTemplate.C"; template -const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateH - = "fixedValuePointPatchFieldTemplate.H"; +const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateH = + "fixedValuePointPatchFieldTemplate.H"; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -141,8 +148,8 @@ void Foam::codedFixedValuePointPatchField::prepare template -const Foam::dictionary& Foam::codedFixedValuePointPatchField::codeDict() -const +const Foam::dictionary& +Foam::codedFixedValuePointPatchField::codeDict() const { // Use system/codeDict or in-line return @@ -154,6 +161,14 @@ const } +template +const Foam::wordList& +Foam::codedFixedValuePointPatchField::codeKeys() const +{ + return codeKeys_; +} + + template Foam::string Foam::codedFixedValuePointPatchField::description() const { diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H index a5ae64405f..1b8bab9356 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H @@ -105,6 +105,12 @@ class codedFixedValuePointPatchField public fixedValuePointPatchField, public codedBase { + // Private static data + + //- The keywords associated with source code + static const wordList codeKeys_; + + // Private data //- Dictionary contents for the boundary condition @@ -128,15 +134,18 @@ class codedFixedValuePointPatchField //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - // Return a description (type + name) for the output + //- Return a description (type + name) for the output virtual string description() const; - // Clear the ptr to the redirected object + //- Clear the ptr to the redirected object virtual void clearRedirect() const; - // Get the dictionary to initialize the codeContext + //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; + //- Get the keywords associated with source code + virtual const wordList& codeKeys() const; + public: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index 72533c1f6e..7ad67e79a1 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -31,15 +31,22 @@ License #include "dynamicCodeContext.H" #include "stringOps.H" +// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // + +template +const Foam::wordList Foam::codedFixedValueFvPatchField::codeKeys_ = + {"code", "codeInclude", "localCode"}; + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template -const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateC - = "fixedValueFvPatchFieldTemplate.C"; +const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateC = + "fixedValueFvPatchFieldTemplate.C"; template -const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateH - = "fixedValueFvPatchFieldTemplate.H"; +const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateH = + "fixedValueFvPatchFieldTemplate.H"; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -153,6 +160,13 @@ const } +template +const Foam::wordList& Foam::codedFixedValueFvPatchField::codeKeys() const +{ + return codeKeys_; +} + + template Foam::string Foam::codedFixedValueFvPatchField::description() const { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H index 02f46e90f7..3fb76e6f9f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -103,6 +103,12 @@ class codedFixedValueFvPatchField public fixedValueFvPatchField, public codedBase { + // Private static data + + //- The keywords associated with source code + static const wordList codeKeys_; + + // Private data //- Dictionary contents for the boundary condition @@ -126,15 +132,18 @@ class codedFixedValueFvPatchField //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - // Return a description (type + name) for the output + //- Return a description (type + name) for the output virtual string description() const; - // Clear the ptr to the redirected object + //- Clear the ptr to the redirected object virtual void clearRedirect() const; - // Get the dictionary to initialize the codeContext + //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; + //- Get the keywords associated with source code + virtual const wordList& codeKeys() const; + public: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index a5e9cdf49b..b7c0defe39 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -31,15 +31,22 @@ License #include "dynamicCodeContext.H" #include "stringOps.H" +// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // + +template +const Foam::wordList Foam::codedMixedFvPatchField::codeKeys_ = + {"code", "codeInclude", "localCode"}; + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template -const Foam::word Foam::codedMixedFvPatchField::codeTemplateC - = "mixedFvPatchFieldTemplate.C"; +const Foam::word Foam::codedMixedFvPatchField::codeTemplateC = + "mixedFvPatchFieldTemplate.C"; template -const Foam::word Foam::codedMixedFvPatchField::codeTemplateH - = "mixedFvPatchFieldTemplate.H"; +const Foam::word Foam::codedMixedFvPatchField::codeTemplateH = + "mixedFvPatchFieldTemplate.H"; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -153,6 +160,13 @@ const } +template +const Foam::wordList& Foam::codedMixedFvPatchField::codeKeys() const +{ + return codeKeys_; +} + + template Foam::string Foam::codedMixedFvPatchField::description() const { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H index 6f86957b95..ab7539c497 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -113,6 +113,12 @@ class codedMixedFvPatchField public mixedFvPatchField, public codedBase { + // Private static data + + //- The keywords associated with source code + static const wordList codeKeys_; + + // Private data //- Dictionary contents for the boundary condition @@ -136,15 +142,18 @@ class codedMixedFvPatchField //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - // Return a description (type + name) for the output + //- Return a description (type + name) for the output virtual string description() const; - // Clear the ptr to the redirected object + //- Clear the ptr to the redirected object virtual void clearRedirect() const; - // Get the dictionary to initialize the codeContext + //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; + //- Get the keywords associated with source code + virtual const wordList& codeKeys() const; + public: diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index 55ce2ce4cf..7633e32e1a 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,6 +33,20 @@ License #include "stringOps.H" #include "addToRunTimeSelectionTable.H" +// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * // + +const Foam::wordList Foam::codedFunctionObject::codeKeys_ = + { + "codeData", + "codeEnd", + "codeExecute", + "codeInclude", + "codeRead", + "codeWrite", + "localCode" + }; + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam @@ -47,6 +61,7 @@ namespace Foam ); } + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::codedFunctionObject::prepare @@ -55,13 +70,7 @@ void Foam::codedFunctionObject::prepare const dynamicCodeContext& context ) const { - // Set additional rewrite rules dynCode.setFilterVariable("typeName", name_); - dynCode.setFilterVariable("codeData", codeData_); - dynCode.setFilterVariable("codeRead", codeRead_); - dynCode.setFilterVariable("codeExecute", codeExecute_); - dynCode.setFilterVariable("codeWrite", codeWrite_); - dynCode.setFilterVariable("codeEnd", codeEnd_); // Compile filtered C template dynCode.addCompileFile("functionObjectTemplate.C"); @@ -114,6 +123,12 @@ const Foam::dictionary& Foam::codedFunctionObject::codeDict() const } +const Foam::wordList& Foam::codedFunctionObject::codeKeys() const +{ + return codeKeys_; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::codedFunctionObject::codedFunctionObject @@ -129,9 +144,6 @@ Foam::codedFunctionObject::codedFunctionObject dict_(dict) { read(dict_); - - updateLibrary(name_); - redirectFunctionObject(); } @@ -184,114 +196,15 @@ bool Foam::codedFunctionObject::end() bool Foam::codedFunctionObject::read(const dictionary& dict) { - // Backward compatibility - if (dict.found("redirectType")) + // The name keyword is "name". "redirectType" is also maintained here + // for backwards compatibility, but "name" is taken in preference and + // is printed in the error message if neither keyword is present. + name_ = word::null; + name_ = dict.lookupOrDefault("redirectType", name_); + name_ = dict.lookupOrDefault("name", name_); + if (name_ == word::null) { - dict.lookup("redirectType") >> name_; - } - else - { - dict.lookup("name") >> name_; - } - - const entry* dataPtr = dict.lookupEntryPtr - ( - "codeData", - false, - false - ); - if (dataPtr) - { - codeData_ = stringOps::trim(dataPtr->stream()); - stringOps::inplaceExpand(codeData_, dict); - dynamicCodeContext::addLineDirective - ( - codeData_, - dataPtr->startLineNumber(), - dict.name() - ); - } - - const entry* readPtr = dict.lookupEntryPtr - ( - "codeRead", - false, - false - ); - if (readPtr) - { - codeRead_ = stringOps::trim(readPtr->stream()); - stringOps::inplaceExpand(codeRead_, dict); - dynamicCodeContext::addLineDirective - ( - codeRead_, - readPtr->startLineNumber(), - dict.name() - ); - } - - const entry* execPtr = dict.lookupEntryPtr - ( - "codeExecute", - false, - false - ); - if (execPtr) - { - codeExecute_ = stringOps::trim(execPtr->stream()); - stringOps::inplaceExpand(codeExecute_, dict); - dynamicCodeContext::addLineDirective - ( - codeExecute_, - execPtr->startLineNumber(), - dict.name() - ); - } - - const entry* writePtr = dict.lookupEntryPtr - ( - "codeWrite", - false, - false - ); - if (writePtr) - { - codeWrite_ = stringOps::trim(writePtr->stream()); - stringOps::inplaceExpand(codeWrite_, dict); - dynamicCodeContext::addLineDirective - ( - codeWrite_, - writePtr->startLineNumber(), - dict.name() - ); - } - - const entry* endPtr = dict.lookupEntryPtr - ( - "codeEnd", - false, - false - ); - if (endPtr) - { - codeEnd_ = stringOps::trim(endPtr->stream()); - stringOps::inplaceExpand(codeEnd_, dict); - dynamicCodeContext::addLineDirective - ( - codeEnd_, - endPtr->startLineNumber(), - dict.name() - ); - } - - if(!dataPtr && !readPtr && !execPtr && !writePtr && !endPtr) - { - IOWarningInFunction - ( - dict - ) << "No critical \"code\" prefixed keywords were found." - << " Please check the code documentation for more details." - << nl << endl; + dict.lookup("name"); // <-- generate error message with "name" in it } updateLibrary(name_); diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H index d38729fe9d..5b94f7bde7 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,6 +90,12 @@ class codedFunctionObject { protected: + // Protected static data + + //- The keywords associated with source code + static const wordList codeKeys_; + + // Protected data //- Reference to the time database @@ -98,14 +104,9 @@ protected: //- Input dictionary dictionary dict_; + //- The name word name_; - string codeData_; - string codeRead_; - string codeExecute_; - string codeWrite_; - string codeEnd_; - //- Underlying functionObject mutable autoPtr redirectFunctionObjectPtr_; @@ -118,15 +119,18 @@ protected: //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - // Return a description (type + name) for the output + //- Return a description (type + name) for the output virtual string description() const; - // Clear any redirected objects + //- Clear any redirected objects virtual void clearRedirect() const; - // Get the dictionary to initialize the codeContext + //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; + //- Get the keywords associated with source code + virtual const wordList& codeKeys() const; + private: diff --git a/src/fvOptions/sources/general/codedSource/CodedSource.C b/src/fvOptions/sources/general/codedSource/CodedSource.C index 5e016a1f8c..b240ffee57 100644 --- a/src/fvOptions/sources/general/codedSource/CodedSource.C +++ b/src/fvOptions/sources/general/codedSource/CodedSource.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,6 +29,13 @@ License #include "dynamicCode.H" #include "dynamicCodeContext.H" +// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * // + +template +const Foam::wordList Foam::fv::CodedSource::codeKeys_ = + {"codeAddSup", "codeCorrect", "codeInclude", "codeSetValue", "localCode"}; + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template @@ -45,11 +52,6 @@ void Foam::fv::CodedSource::prepare dynCode.setFilterVariable("TemplateType", sourceType); dynCode.setFilterVariable("SourceType", sourceType + "Source"); - // dynCode.removeFilterVariable("code"); - dynCode.setFilterVariable("codeCorrect", codeCorrect_); - dynCode.setFilterVariable("codeAddSup", codeAddSup_); - dynCode.setFilterVariable("codeSetValue", codeSetValue_); - // compile filtered C template dynCode.addCompileFile("codedFvOptionTemplate.C"); @@ -108,6 +110,13 @@ const Foam::dictionary& Foam::fv::CodedSource::codeDict() const } +template +const Foam::wordList& Foam::fv::CodedSource::codeKeys() const +{ + return codeKeys_; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template diff --git a/src/fvOptions/sources/general/codedSource/CodedSource.H b/src/fvOptions/sources/general/codedSource/CodedSource.H index 00a25de4de..303b8157cd 100644 --- a/src/fvOptions/sources/general/codedSource/CodedSource.H +++ b/src/fvOptions/sources/general/codedSource/CodedSource.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,15 +89,6 @@ Usage #{ Pout<< "**codeSetValue**" << endl; #}; - - // Dummy entry. Make dependent on above to trigger recompilation - code - #{ - $codeInclude - $codeCorrect - $codeAddSup - $codeSetValue - #}; } sourceTimeCoeffs @@ -136,17 +127,19 @@ class CodedSource public cellSetOption, public codedBase { - protected: + // Protected static data + + //- The keywords associated with source code + static const wordList codeKeys_; + + // Protected data + //- The name word name_; - string codeCorrect_; - string codeAddSup_; - string codeSetValue_; - //- Underlying functionObject mutable autoPtr