Loading...
Searching...
No Matches
codedFunctionObject Class Reference

Provides a general interface to enable dynamic code compilation. More...

#include <codedFunctionObject.H>

Inheritance diagram for codedFunctionObject:
Collaboration diagram for codedFunctionObject:

Public Member Functions

 TypeName ("coded")
 Runtime type information.
 codedFunctionObject (const word &name, const Time &runTime, const dictionary &dict)
 Construct from name, Time and dictionary.
virtual ~codedFunctionObject ()=default
 Destructor.
functionObjectredirectFunctionObject () const
 Dynamically compiled functionObject.
virtual bool execute ()
 Called at each ++ or += of the time-loop.
virtual bool write ()
 Called at each ++ or += of the time-loop.
virtual bool end ()
 Called when Time::run() determines that the time-loop exits.
virtual bool read (const dictionary &)
 Read and set the function object if its data have changed.
Public Member Functions inherited from timeFunctionObject
 timeFunctionObject (const word &name, const Time &runTime)
 Construct from Time.
virtual ~timeFunctionObject ()=default
 Destructor.
const Timetime () const
 Return time database.
objectRegistrystoredObjects ()
 Write access to the output objects ("functionObjectObjects") registered on Time.
const objectRegistrystoredObjects () const
 Const access to the output objects ("functionObjectObjects") registered on Time.
Public Member Functions inherited from functionObject
 declareRunTimeSelectionTable (autoPtr, functionObject, dictionary,(const word &name, const Time &runTime, const dictionary &dict),(name, runTime, dict))
 functionObject (const word &name, const bool withNamePrefix=defaultUseNamePrefix)
 Construct from components.
autoPtr< functionObjectclone () const
 Return clone.
virtual ~functionObject ()=default
 Destructor.
virtual const wordtype () const =0
 Runtime type information.
const wordname () const noexcept
 Return the name of this functionObject.
bool useNamePrefix () const noexcept
 Return the flag for adding a scoping name prefix.
bool useNamePrefix (bool on) noexcept
 Modify the flag for adding a scoping name prefix.
virtual bool execute (const label subIndex)
 Execute using the specified subIndex.
virtual bool adjustTimeStep ()
 Called at the end of Time::adjustDeltaT() if adjustTime is true.
virtual bool filesModified () const
 Did any file get changed during execution?
virtual void updateMesh (const mapPolyMesh &mpm)
 Update for changes of mesh.
virtual void movePoints (const polyMesh &mesh)
 Update for changes of mesh.
Public Member Functions inherited from codedBase
 ClassName ("codedBase")
 Runtime type information.
 codedBase (const codedBase &)=delete
 No copy construct.
void operator= (const codedBase &)=delete
 No copy assignment.
 codedBase ()=default
 Default construct.
virtual ~codedBase ()=default
 Destructor.

Static Public Attributes

static constexpr const char *const codeTemplateC = "functionObjectTemplate.C"
 Name of the C code template to be used.
static constexpr const char *const codeTemplateH = "functionObjectTemplate.H"
 Name of the H code template to be used.
Static Public Attributes inherited from functionObject
static int debug
 Flag to execute debug content.
static bool postProcess
 Global post-processing mode switch.
static bool defaultUseNamePrefix
 Global default for useNamePrefix.
static word outputPrefix
 Directory prefix.

Protected Member Functions

virtual dlLibraryTablelibs () const
 Mutable access to the loaded dynamic libraries.
virtual string description () const
 Description (type + name) for the output.
virtual void clearRedirect () const
 Clear redirected object(s).
virtual const dictionarycodeContext () const
 Additional 'codeContext' dictionary to pass through.
virtual const dictionarycodeDict () const
 The code dictionary.
virtual void prepare (dynamicCode &, const dynamicCodeContext &) const
 Adapt the context for the current object.
 codedFunctionObject (const codedFunctionObject &)=delete
 No copy construct.
void operator= (const codedFunctionObject &)=delete
 No copy assignment.
Protected Member Functions inherited from timeFunctionObject
void clearOutputObjects (const wordList &objNames)
 Remove specified items from "functionObjectObjects".
 timeFunctionObject (const timeFunctionObject &)=delete
 No copy construct.
void operator= (const timeFunctionObject &)=delete
 No copy assignment.
Protected Member Functions inherited from functionObject
word scopedName (const word &name) const
 Return a scoped (prefixed) name.
Protected Member Functions inherited from codedBase
dynamicCodeContextcodeContext ()
 Access to the dynamic code context.
void setCodeContext (const dictionary &dict)
 Set code context from a dictionary.
void append (const std::string &str)
 Add content to SHA1 hashing.
void updateLibrary (const word &name, const dynamicCodeContext &context) const
 Update library as required, using the given context.
void updateLibrary (const word &name, const dictionary &dict) const
 Update library as required, using the given code dictionary to use for the context.
void updateLibrary (const word &name) const
 Update library as required, using the predefined context or use the codeDict() to generate one.

Protected Attributes

dictionary dict_
 Input dictionary.
word name_
string codeData_
string codeRead_
string codeExecute_
string codeWrite_
string codeEnd_
autoPtr< functionObjectredirectFunctionObjectPtr_
 Underlying functionObject.
Protected Attributes inherited from timeFunctionObject
const Timetime_
 Reference to the time database.

Additional Inherited Members

Static Public Member Functions inherited from functionObject
static autoPtr< functionObjectNew (const word &name, const Time &runTime, const dictionary &dict)
 Select from dictionary, based on its "type" entry.
Public Attributes inherited from functionObject
bool log
 Flag to write log into Info.
Static Protected Member Functions inherited from codedBase
static void writeCodeDict (Ostream &os, const dictionary &dict)
 Write code-dictionary contents.
static const dictionarycodeDict (const objectRegistry &obr, const word &dictName="codeDict")
 Return "codeDict" from objectRegistry or read from disk.

Detailed Description

Provides a general interface to enable dynamic code compilation.

Usage
Minimal example by using system/controlDict.functions:
difference
{
    // Mandatory entries
    type                coded;
    libs                (utilityFunctionObjects);

    // Name of on-the-fly generated functionObject
    name                <word>;  // writeMagU;
    codeWrite
    #{
        // Lookup U
        const volVectorField& U = mesh().lookupObject<volVectorField>("U");

        // Write
        mag(U)().write();
    #};
    ...

    // Inherited entries
    ...
}

where the entries mean:

Property Description Type Reqd Deflt
type Type name: coded word yes -
libs Library name: utilityFunctionObjects word yes -
name Name of the function object word yes -
codeInclude include files word no -
codeOptions compiler line: added to EXE_INC (Make/options) word no -
codeLibs linker line: added to LIB_LIBS (Make/options) word no -
codeData c++; local member data (default constructed) word no -
localCode c++; local static functions word no -
codeRead c++; upon functionObject::read() word no -
codeExecute c++; upon functionObject::execute() word no -
codeWrite c++; upon functionObject::write() word no -
codeEnd c++; upon functionObject::end() word no -
codeContext additional dictionary context for the code word no -

The inherited entries are elaborated in:

Definition at line 188 of file codedFunctionObject.H.

Constructor & Destructor Documentation

◆ codedFunctionObject() [1/2]

codedFunctionObject ( const codedFunctionObject & )
protecteddelete

No copy construct.

References codedFunctionObject().

Referenced by codedFunctionObject(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ codedFunctionObject() [2/2]

codedFunctionObject ( const word & name,
const Time & runTime,
const dictionary & dict )

Construct from name, Time and dictionary.

Definition at line 127 of file codedFunctionObject.C.

References codedBase::codedBase(), dict, dict_, functionObject::name(), name_, read(), redirectFunctionObject(), runTime, timeFunctionObject::timeFunctionObject(), and codedBase::updateLibrary().

Here is the call graph for this function:

◆ ~codedFunctionObject()

virtual ~codedFunctionObject ( )
virtualdefault

Destructor.

References functionObject::functionObject().

Here is the call graph for this function:

Member Function Documentation

◆ libs()

Foam::dlLibraryTable & libs ( ) const
protectedvirtual

Mutable access to the loaded dynamic libraries.

Implements codedBase.

Definition at line 50 of file codedFunctionObject.C.

References timeFunctionObject::time_.

◆ description()

Foam::string description ( ) const
protectedvirtual

Description (type + name) for the output.

Implements codedBase.

Definition at line 56 of file codedFunctionObject.C.

References name.

◆ clearRedirect()

void clearRedirect ( ) const
protectedvirtual

Clear redirected object(s).

Implements codedBase.

Definition at line 62 of file codedFunctionObject.C.

References redirectFunctionObjectPtr_.

◆ codeContext()

const Foam::dictionary & codeContext ( ) const
protectedvirtual

Additional 'codeContext' dictionary to pass through.

Definition at line 69 of file codedFunctionObject.C.

References dict_, keyType::LITERAL, and dictionary::null.

Referenced by redirectFunctionObject().

Here is the caller graph for this function:

◆ codeDict()

const Foam::dictionary & codeDict ( ) const
protectedvirtual

The code dictionary.

Implements codedBase.

Definition at line 77 of file codedFunctionObject.C.

References dict_.

◆ prepare()

void prepare ( dynamicCode & dynCode,
const dynamicCodeContext & context ) const
protectedvirtual

◆ operator=()

void operator= ( const codedFunctionObject & )
protecteddelete

No copy assignment.

References codedFunctionObject().

Here is the call graph for this function:

◆ TypeName()

TypeName ( "coded" )

Runtime type information.

References dict, functionObject::name(), and runTime.

Here is the call graph for this function:

◆ redirectFunctionObject()

Foam::functionObject & redirectFunctionObject ( ) const

Dynamically compiled functionObject.

Definition at line 148 of file codedFunctionObject.C.

References codeContext(), dict_, name_, functionObject::New(), Foam::nl, redirectFunctionObjectPtr_, dictionary::set(), timeFunctionObject::time_, and WarningInFunction.

Referenced by codedFunctionObject(), end(), execute(), read(), and write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute()

bool execute ( )
virtual

Called at each ++ or += of the time-loop.

postProcess overrides the usual executeControl behaviour and forces execution (used in post-processing mode)

Implements functionObject.

Definition at line 182 of file codedFunctionObject.C.

References name_, redirectFunctionObject(), and codedBase::updateLibrary().

Here is the call graph for this function:

◆ write()

bool write ( )
virtual

Called at each ++ or += of the time-loop.

postProcess overrides the usual writeControl behaviour and forces writing always (used in post-processing mode)

Implements functionObject.

Definition at line 189 of file codedFunctionObject.C.

References name_, redirectFunctionObject(), and codedBase::updateLibrary().

Here is the call graph for this function:

◆ end()

bool end ( )
virtual

Called when Time::run() determines that the time-loop exits.

By default it simply calls execute().

Reimplemented from functionObject.

Definition at line 196 of file codedFunctionObject.C.

References name_, redirectFunctionObject(), and codedBase::updateLibrary().

Here is the call graph for this function:

◆ read()

bool read ( const dictionary & dict)
virtual

Read and set the function object if its data have changed.

Reimplemented from functionObject.

Definition at line 203 of file codedFunctionObject.C.

References codedBase::codeContext(), codeData_, codeEnd_, codeExecute_, codeRead_, codeWrite_, dict, Foam::endl(), IOWarningInFunction, name_, Foam::nl, functionObject::read(), redirectFunctionObject(), codedBase::setCodeContext(), and codedBase::updateLibrary().

Referenced by codedFunctionObject().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dict_

dictionary dict_
protected

Input dictionary.

Definition at line 200 of file codedFunctionObject.H.

Referenced by codeContext(), codedFunctionObject(), codeDict(), and redirectFunctionObject().

◆ name_

word name_
protected

◆ codeData_

string codeData_
protected

Definition at line 204 of file codedFunctionObject.H.

Referenced by prepare(), and read().

◆ codeRead_

string codeRead_
protected

Definition at line 205 of file codedFunctionObject.H.

Referenced by prepare(), and read().

◆ codeExecute_

string codeExecute_
protected

Definition at line 206 of file codedFunctionObject.H.

Referenced by prepare(), and read().

◆ codeWrite_

string codeWrite_
protected

Definition at line 207 of file codedFunctionObject.H.

Referenced by prepare(), and read().

◆ codeEnd_

string codeEnd_
protected

Definition at line 208 of file codedFunctionObject.H.

Referenced by prepare(), and read().

◆ redirectFunctionObjectPtr_

autoPtr<functionObject> redirectFunctionObjectPtr_
mutableprotected

Underlying functionObject.

Definition at line 213 of file codedFunctionObject.H.

Referenced by clearRedirect(), and redirectFunctionObject().

◆ codeTemplateC

const char* const codeTemplateC = "functionObjectTemplate.C"
staticconstexpr

Name of the C code template to be used.

Definition at line 267 of file codedFunctionObject.H.

Referenced by prepare().

◆ codeTemplateH

const char* const codeTemplateH = "functionObjectTemplate.H"
staticconstexpr

Name of the H code template to be used.

Definition at line 273 of file codedFunctionObject.H.

Referenced by prepare().


The documentation for this class was generated from the following files: