codedFunctionObject: Updated and simplified using the new CodedBase

This commit is contained in:
Henry Weller
2020-02-03 21:44:44 +00:00
parent 7a717a6929
commit d728b23427
4 changed files with 33 additions and 81 deletions

View File

@ -32,7 +32,7 @@ License
namespace Foam
{
defineDebugSwitchWithName(functionObject, "functionObject", 0);
defineTypeNameAndDebug(functionObject, 0);
defineRunTimeSelectionTable(functionObject, dictionary);
}

View File

@ -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;

View File

@ -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<Foam::functionObject>::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<functionObject>(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<word>("redirectType")
: dict.lookup<word>("name");
updateLibrary(name_);
updateLibrary(codeName());
return redirectFunctionObject().read(dict);
}

View File

@ -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<functionObject>
{
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<functionObject> 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)