codedFunctionObject Class Reference

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

Inheritance diagram for codedFunctionObject:
[legend]
Collaboration diagram for codedFunctionObject:
[legend]

Public Member Functions

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

Static Public Attributes

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

Protected Member Functions

virtual dlLibraryTablelibs () const
 Mutable access to the loaded dynamic libraries. More...
 
virtual void prepare (dynamicCode &, const dynamicCodeContext &) const
 Adapt the context for the current object. More...
 
virtual string description () const
 Return a description (type + name) for the output. More...
 
virtual void clearRedirect () const
 Clear any redirected objects. More...
 
virtual const dictionarycodeDict () const
 The dictionary to initialize the codeContext. More...
 
 codedFunctionObject (const codedFunctionObject &)=delete
 No copy construct. More...
 
void operator= (const codedFunctionObject &)=delete
 No copy assignment. More...
 
- Protected Member Functions inherited from timeFunctionObject
void clearOutputObjects (const wordList &objNames)
 Remove specified items from "functionObjectObjects". More...
 
 timeFunctionObject (const timeFunctionObject &)=delete
 No copy construct. More...
 
void operator= (const timeFunctionObject &)=delete
 No copy assignment. More...
 
- Protected Member Functions inherited from functionObject
word scopedName (const word &name) const
 Return a scoped name, e.g. used to construct local field names. More...
 
- Protected Member Functions inherited from codedBase
void setCodeContext (const dictionary &dict)
 Set code context from a dictionary. More...
 
void append (const std::string &str)
 Add content to SHA1 hashing. More...
 
void updateLibrary (const word &name, const dynamicCodeContext &context) const
 Update library as required, using the given context. More...
 
void updateLibrary (const word &name, const dictionary &dict) const
 
void updateLibrary (const word &name) const
 
 codedBase (const codedBase &)=delete
 No copy construct. More...
 
void operator= (const codedBase &)=delete
 No copy assignment. More...
 

Protected Attributes

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

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. More...
 
- Public Attributes inherited from functionObject
bool log
 Flag to write log into Info. More...
 
- Static Protected Member Functions inherited from codedBase
static void writeCodeDict (Ostream &os, const dictionary &dict)
 Write code-dictionary contents. More...
 

Detailed Description

Provides a general interface to enable dynamic code compilation.

The entries are:

codeInclude : include files
codeOptions : include paths; inserted into EXE_INC in Make/options
codeLibs : link line; inserted into LIB_LIBS in Make/options
codeData : c++; local member data (null constructed);
localCode : c++; local static functions;
codeRead : c++; upon functionObject::read();
codeExecute : c++; upon functionObject::execute();
codeWrite : c++; upon functionObject::write()
codeEnd : c++; upon functionObject::end();
Usage
Example of function object specification:
difference
{
    type coded;
    libs (utilityFunctionObjects);

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

        // Write
        mag(U)().write();
    #};
}
See also
Foam::functionObject Foam::codedBase
Source files

Definition at line 131 of file codedFunctionObject.H.

Constructor & Destructor Documentation

◆ codedFunctionObject() [1/2]

codedFunctionObject ( const codedFunctionObject )
protecteddelete

No copy construct.

◆ codedFunctionObject() [2/2]

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

Construct from Time and dictionary.

Definition at line 125 of file codedFunctionObject.C.

References Foam::read().

Here is the call graph for this function:

◆ ~codedFunctionObject()

virtual ~codedFunctionObject ( )
virtualdefault

Destructor.

Member Function Documentation

◆ libs()

Foam::dlLibraryTable & libs ( ) const
protectedvirtual

Mutable access to the loaded dynamic libraries.

Implements codedBase.

Definition at line 97 of file codedFunctionObject.C.

References Time::libs(), and timeFunctionObject::time_.

Here is the call graph for this function:

◆ prepare()

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

Adapt the context for the current object.

Implements codedBase.

Definition at line 56 of file codedFunctionObject.C.

References dynamicCode::addCompileFile(), dynamicCode::addCopyFile(), dynamicCodeContext::libs(), dynamicCodeContext::options(), dynamicCode::setFilterVariable(), and dynamicCode::setMakeOptions().

Here is the call graph for this function:

◆ description()

Foam::string description ( ) const
protectedvirtual

Return a description (type + name) for the output.

Implements codedBase.

Definition at line 103 of file codedFunctionObject.C.

References Foam::name().

Here is the call graph for this function:

◆ clearRedirect()

void clearRedirect ( ) const
protectedvirtual

Clear any redirected objects.

Implements codedBase.

Definition at line 109 of file codedFunctionObject.C.

◆ codeDict()

const Foam::dictionary & codeDict ( ) const
protectedvirtual

The dictionary to initialize the codeContext.

Implements codedBase.

Definition at line 116 of file codedFunctionObject.C.

◆ operator=()

void operator= ( const codedFunctionObject )
protecteddelete

No copy assignment.

◆ TypeName()

TypeName ( "coded"  )

Runtime type information.

◆ redirectFunctionObject()

Foam::functionObject & redirectFunctionObject ( ) const

Dynamically compiled functionObject.

Definition at line 145 of file codedFunctionObject.C.

References functionObject::New(), and dictionary::set().

Here is the call 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 163 of file codedFunctionObject.C.

◆ 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 170 of file codedFunctionObject.C.

◆ 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 177 of file codedFunctionObject.C.

◆ read()

bool read ( const dictionary dict)
virtual

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

Reimplemented from functionObject.

Definition at line 184 of file codedFunctionObject.C.

References dynamicCodeContext::addLineDirective(), codedBase::append(), dict, Foam::endl(), dynamicCodeContext::inplaceExpand(), IOWarningInFunction, keyType::LITERAL, Foam::nl, functionObject::read(), entry::readEntry(), codedBase::setCodeContext(), and entry::startLineNumber().

Here is the call graph for this function:

Member Data Documentation

◆ dict_

dictionary dict_
protected

Input dictionary.

Definition at line 141 of file codedFunctionObject.H.

◆ name_

word name_
protected

Definition at line 143 of file codedFunctionObject.H.

◆ codeData_

string codeData_
protected

Definition at line 145 of file codedFunctionObject.H.

◆ codeRead_

string codeRead_
protected

Definition at line 146 of file codedFunctionObject.H.

◆ codeExecute_

string codeExecute_
protected

Definition at line 147 of file codedFunctionObject.H.

◆ codeWrite_

string codeWrite_
protected

Definition at line 148 of file codedFunctionObject.H.

◆ codeEnd_

string codeEnd_
protected

Definition at line 149 of file codedFunctionObject.H.

◆ redirectFunctionObjectPtr_

autoPtr<functionObject> redirectFunctionObjectPtr_
mutableprotected

Underlying functionObject.

Definition at line 152 of file codedFunctionObject.H.

◆ codeTemplateC

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

Name of the C code template to be used.

Definition at line 186 of file codedFunctionObject.H.

◆ codeTemplateH

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

Name of the H code template to be used.

Definition at line 190 of file codedFunctionObject.H.


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