codedFunctionObject: Updated and simplified using the new CodedBase
This commit is contained in:
@ -32,7 +32,7 @@ License
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
defineDebugSwitchWithName(functionObject, "functionObject", 0);
|
defineTypeNameAndDebug(functionObject, 0);
|
||||||
defineRunTimeSelectionTable(functionObject, dictionary);
|
defineRunTimeSelectionTable(functionObject, dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -147,11 +147,11 @@ class functionObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ClassName("functionObject");
|
||||||
|
|
||||||
//- Runtime type information
|
//- Runtime type information
|
||||||
virtual const word& type() const = 0;
|
virtual const word& type() const = 0;
|
||||||
|
|
||||||
static int debug;
|
|
||||||
|
|
||||||
//- Global post-processing mode switch
|
//- Global post-processing mode switch
|
||||||
static bool postProcess;
|
static bool postProcess;
|
||||||
|
|
||||||
|
|||||||
@ -35,16 +35,17 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * //
|
// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * //
|
||||||
|
|
||||||
const Foam::wordList Foam::codedFunctionObject::codeKeys_ =
|
template<>
|
||||||
{
|
const Foam::wordList Foam::CodedBase<Foam::functionObject>::codeKeys_ =
|
||||||
"codeData",
|
{
|
||||||
"codeEnd",
|
"codeData",
|
||||||
"codeExecute",
|
"codeEnd",
|
||||||
"codeInclude",
|
"codeExecute",
|
||||||
"codeRead",
|
"codeInclude",
|
||||||
"codeWrite",
|
"codeRead",
|
||||||
"localCode"
|
"codeWrite",
|
||||||
};
|
"localCode"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -70,7 +71,7 @@ void Foam::codedFunctionObject::prepare
|
|||||||
const dynamicCodeContext& context
|
const dynamicCodeContext& context
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
dynCode.setFilterVariable("typeName", name_);
|
dynCode.setFilterVariable("typeName", codeName());
|
||||||
|
|
||||||
// Compile filtered C template
|
// Compile filtered C template
|
||||||
dynCode.addCompileFile("functionObjectTemplate.C");
|
dynCode.addCompileFile("functionObjectTemplate.C");
|
||||||
@ -80,7 +81,7 @@ void Foam::codedFunctionObject::prepare
|
|||||||
|
|
||||||
// Debugging: make verbose
|
// Debugging: make verbose
|
||||||
// dynCode.setFilterVariable("verbose", "true");
|
// dynCode.setFilterVariable("verbose", "true");
|
||||||
// Info<<"compile " << name_ << " sha1: "
|
// Info<<"compile " << codeName() << " sha1: "
|
||||||
// << context.sha1() << endl;
|
// << context.sha1() << endl;
|
||||||
|
|
||||||
// Define Make/options
|
// 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
|
void Foam::codedFunctionObject::clearRedirect() const
|
||||||
{
|
{
|
||||||
redirectFunctionObjectPtr_.clear();
|
redirectFunctionObjectPtr_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::dictionary& Foam::codedFunctionObject::codeDict() const
|
|
||||||
{
|
|
||||||
return dict_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const Foam::wordList& Foam::codedFunctionObject::codeKeys() const
|
|
||||||
{
|
|
||||||
return codeKeys_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::codedFunctionObject::codedFunctionObject
|
Foam::codedFunctionObject::codedFunctionObject
|
||||||
@ -133,11 +116,10 @@ Foam::codedFunctionObject::codedFunctionObject
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
functionObject(name),
|
functionObject(name),
|
||||||
codedBase(),
|
CodedBase<functionObject>(dict),
|
||||||
time_(time),
|
time_(time)
|
||||||
dict_(dict)
|
|
||||||
{
|
{
|
||||||
read(dict_);
|
read(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,12 +135,12 @@ Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const
|
|||||||
{
|
{
|
||||||
if (!redirectFunctionObjectPtr_.valid())
|
if (!redirectFunctionObjectPtr_.valid())
|
||||||
{
|
{
|
||||||
dictionary constructDict(dict_);
|
dictionary constructDict(codeDict());
|
||||||
constructDict.set("type", name_);
|
constructDict.set("type", codeName());
|
||||||
|
|
||||||
redirectFunctionObjectPtr_ = functionObject::New
|
redirectFunctionObjectPtr_ = functionObject::New
|
||||||
(
|
(
|
||||||
name_,
|
codeName(),
|
||||||
time_,
|
time_,
|
||||||
constructDict
|
constructDict
|
||||||
);
|
);
|
||||||
@ -169,35 +151,28 @@ Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const
|
|||||||
|
|
||||||
bool Foam::codedFunctionObject::execute()
|
bool Foam::codedFunctionObject::execute()
|
||||||
{
|
{
|
||||||
updateLibrary(name_);
|
updateLibrary(codeName());
|
||||||
return redirectFunctionObject().execute();
|
return redirectFunctionObject().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::codedFunctionObject::write()
|
bool Foam::codedFunctionObject::write()
|
||||||
{
|
{
|
||||||
updateLibrary(name_);
|
updateLibrary(codeName());
|
||||||
return redirectFunctionObject().write();
|
return redirectFunctionObject().write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::codedFunctionObject::end()
|
bool Foam::codedFunctionObject::end()
|
||||||
{
|
{
|
||||||
updateLibrary(name_);
|
updateLibrary(codeName());
|
||||||
return redirectFunctionObject().end();
|
return redirectFunctionObject().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
// The name keyword is "name". "redirectType" is also maintained here
|
updateLibrary(codeName());
|
||||||
// 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_);
|
|
||||||
return redirectFunctionObject().read(dict);
|
return redirectFunctionObject().read(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ SourceFiles
|
|||||||
#define functionObjects_codedFunctionObject_H
|
#define functionObjects_codedFunctionObject_H
|
||||||
|
|
||||||
#include "functionObject.H"
|
#include "functionObject.H"
|
||||||
#include "codedBase.H"
|
#include "CodedBase.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -86,47 +86,27 @@ namespace Foam
|
|||||||
class codedFunctionObject
|
class codedFunctionObject
|
||||||
:
|
:
|
||||||
public functionObject,
|
public functionObject,
|
||||||
public codedBase
|
public CodedBase<functionObject>
|
||||||
{
|
{
|
||||||
protected:
|
// Private Data
|
||||||
|
|
||||||
// Protected static data
|
|
||||||
|
|
||||||
//- The keywords associated with source code
|
|
||||||
static const wordList codeKeys_;
|
|
||||||
|
|
||||||
|
|
||||||
// Protected data
|
|
||||||
|
|
||||||
//- Reference to the time database
|
//- Reference to the time database
|
||||||
const Time& time_;
|
const Time& time_;
|
||||||
|
|
||||||
//- Input dictionary
|
|
||||||
dictionary dict_;
|
|
||||||
|
|
||||||
//- Name of the dynamically generated functionObject
|
|
||||||
word name_;
|
|
||||||
|
|
||||||
//- The dynamically generated functionObject pointer
|
//- The dynamically generated functionObject pointer
|
||||||
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
||||||
|
|
||||||
|
|
||||||
// Protected Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
||||||
|
|
||||||
//- Return a description (type + name) for the output
|
|
||||||
virtual string description() const;
|
|
||||||
|
|
||||||
//- Clear any redirected objects
|
//- Clear any redirected objects
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
//- Get the dictionary to initialize the codeContext
|
//- Compile, link and return the now coded functionObject
|
||||||
virtual const dictionary& codeDict() const;
|
functionObject& redirectFunctionObject() const;
|
||||||
|
|
||||||
//- Get the keywords associated with source code
|
|
||||||
virtual const wordList& codeKeys() const;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -155,9 +135,6 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Dynamically compiled functionObject
|
|
||||||
functionObject& redirectFunctionObject() const;
|
|
||||||
|
|
||||||
//- Called at each ++ or += of the time-loop.
|
//- Called at each ++ or += of the time-loop.
|
||||||
// postProcess overrides the usual executeControl behaviour and
|
// postProcess overrides the usual executeControl behaviour and
|
||||||
// forces execution (used in post-processing mode)
|
// forces execution (used in post-processing mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user