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/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C index 567db9ca58..01c4ff7665 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.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 @@ -127,6 +127,7 @@ bool Foam::combineFaces::validFace void Foam::combineFaces::regioniseFaces ( const scalar minCos, + const labelHashSet& patchIDs, const label celli, const labelList& cEdges, Map