From d728b23427619ebbfe6fbe0ca795b5134add8bea Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 3 Feb 2020 21:44:44 +0000 Subject: [PATCH] codedFunctionObject: Updated and simplified using the new CodedBase --- .../functionObject/functionObject.C | 2 +- .../functionObject/functionObject.H | 6 +- .../codedFunctionObject/codedFunctionObject.C | 71 ++++++------------- .../codedFunctionObject/codedFunctionObject.H | 35 ++------- 4 files changed, 33 insertions(+), 81 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 9c128a1ef9..18024fc5a9 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -32,7 +32,7 @@ License namespace Foam { - defineDebugSwitchWithName(functionObject, "functionObject", 0); + defineTypeNameAndDebug(functionObject, 0); defineRunTimeSelectionTable(functionObject, dictionary); } diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index 0c3a549301..0207017c73 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.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 @@ -147,11 +147,11 @@ class functionObject public: + ClassName("functionObject"); + //- Runtime type information virtual const word& type() const = 0; - static int debug; - //- Global post-processing mode switch static bool postProcess; diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index bab3776dcb..f666e30dcc 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -35,16 +35,17 @@ License // * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * // -const Foam::wordList Foam::codedFunctionObject::codeKeys_ = - { - "codeData", - "codeEnd", - "codeExecute", - "codeInclude", - "codeRead", - "codeWrite", - "localCode" - }; +template<> +const Foam::wordList Foam::CodedBase::codeKeys_ = +{ + "codeData", + "codeEnd", + "codeExecute", + "codeInclude", + "codeRead", + "codeWrite", + "localCode" +}; // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -70,7 +71,7 @@ void Foam::codedFunctionObject::prepare const dynamicCodeContext& context ) const { - dynCode.setFilterVariable("typeName", name_); + dynCode.setFilterVariable("typeName", codeName()); // Compile filtered C template dynCode.addCompileFile("functionObjectTemplate.C"); @@ -80,7 +81,7 @@ void Foam::codedFunctionObject::prepare // Debugging: make verbose // dynCode.setFilterVariable("verbose", "true"); - // Info<<"compile " << name_ << " sha1: " + // Info<<"compile " << codeName() << " sha1: " // << context.sha1() << endl; // Define Make/options @@ -99,30 +100,12 @@ void Foam::codedFunctionObject::prepare } -Foam::string Foam::codedFunctionObject::description() const -{ - return "functionObject " + name(); -} - - void Foam::codedFunctionObject::clearRedirect() const { redirectFunctionObjectPtr_.clear(); } -const Foam::dictionary& Foam::codedFunctionObject::codeDict() const -{ - return dict_; -} - - -const Foam::wordList& Foam::codedFunctionObject::codeKeys() const -{ - return codeKeys_; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::codedFunctionObject::codedFunctionObject @@ -133,11 +116,10 @@ Foam::codedFunctionObject::codedFunctionObject ) : functionObject(name), - codedBase(), - time_(time), - dict_(dict) + CodedBase(dict), + time_(time) { - read(dict_); + read(dict); } @@ -153,12 +135,12 @@ Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const { if (!redirectFunctionObjectPtr_.valid()) { - dictionary constructDict(dict_); - constructDict.set("type", name_); + dictionary constructDict(codeDict()); + constructDict.set("type", codeName()); redirectFunctionObjectPtr_ = functionObject::New ( - name_, + codeName(), time_, constructDict ); @@ -169,35 +151,28 @@ Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const bool Foam::codedFunctionObject::execute() { - updateLibrary(name_); + updateLibrary(codeName()); return redirectFunctionObject().execute(); } bool Foam::codedFunctionObject::write() { - updateLibrary(name_); + updateLibrary(codeName()); return redirectFunctionObject().write(); } bool Foam::codedFunctionObject::end() { - updateLibrary(name_); + updateLibrary(codeName()); return redirectFunctionObject().end(); } bool Foam::codedFunctionObject::read(const dictionary& dict) { - // 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_ = dict.found("redirectType") - ? dict.lookup("redirectType") - : dict.lookup("name"); - - updateLibrary(name_); + updateLibrary(codeName()); return redirectFunctionObject().read(dict); } diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H index 705cfa0716..b7e41fe63c 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H @@ -72,7 +72,7 @@ SourceFiles #define functionObjects_codedFunctionObject_H #include "functionObject.H" -#include "codedBase.H" +#include "CodedBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -86,47 +86,27 @@ namespace Foam class codedFunctionObject : public functionObject, - public codedBase + public CodedBase { -protected: - - // Protected static data - - //- The keywords associated with source code - static const wordList codeKeys_; - - - // Protected data + // Private Data //- Reference to the time database const Time& time_; - //- Input dictionary - dictionary dict_; - - //- Name of the dynamically generated functionObject - word name_; - //- The dynamically generated functionObject pointer mutable autoPtr redirectFunctionObjectPtr_; - // Protected Member Functions + // Private Member Functions //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - //- Return a description (type + name) for the output - virtual string description() const; - //- Clear any redirected objects virtual void clearRedirect() const; - //- Get the dictionary to initialize the codeContext - virtual const dictionary& codeDict() const; - - //- Get the keywords associated with source code - virtual const wordList& codeKeys() const; + //- Compile, link and return the now coded functionObject + functionObject& redirectFunctionObject() const; public: @@ -155,9 +135,6 @@ public: // Member Functions - //- Dynamically compiled functionObject - functionObject& redirectFunctionObject() const; - //- Called at each ++ or += of the time-loop. // postProcess overrides the usual executeControl behaviour and // forces execution (used in post-processing mode)