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
 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. More...
 
autoPtr< functionObjectclone () const
 Return clone. More...
 
virtual ~functionObject ()=default
 Destructor. More...
 
virtual const wordtype () const =0
 Runtime type information. More...
 
const wordname () const noexcept
 Return the name of this functionObject. More...
 
bool useNamePrefix () const noexcept
 Return the flag for adding a scoping name prefix. More...
 
bool useNamePrefix (bool on) noexcept
 Modify the flag for adding a scoping name prefix. 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 bool defaultUseNamePrefix
 Global default for useNamePrefix. More...
 
static word outputPrefix
 Directory prefix. More...
 

Protected Member Functions

virtual dlLibraryTablelibs () const
 Mutable access to the loaded dynamic libraries. More...
 
virtual string description () const
 Description (type + name) for the output. More...
 
virtual void clearRedirect () const
 Clear redirected object(s) More...
 
virtual const dictionarycodeContext () const
 Additional 'codeContext' dictionary to pass through. More...
 
virtual const dictionarycodeDict () const
 The code dictionary. More...
 
virtual void prepare (dynamicCode &, const dynamicCodeContext &) const
 Adapt the context for the current object. 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 (prefixed) name. More...
 
- Protected Member Functions inherited from codedBase
dynamicCodeContextcodeContext ()
 Access to the dynamic code context. More...
 
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...
 
static const dictionarycodeDict (const objectRegistry &obr, const word &dictName="codeDict")
 Return "codeDict" from objectRegistry or read from disk. More...
 

Detailed Description

Provides a general interface to enable dynamic code compilation.

The entries are:

codeInclude : include files
codeOptions : compiler line: added to EXE_INC (Make/options)
codeLibs : linker line: added to LIB_LIBS (Make/options)
codeData : c++; local member data (default 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()
codeContext : additional dictionary context for the code
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();
    #};
}
Note
The code context dictionary can be supplied separately as the codeContext entry.
See also
Foam::functionObject Foam::codedBase
Source files

Definition at line 140 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 135 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 57 of file codedFunctionObject.C.

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

Here is the call graph for this function:

◆ description()

Foam::string description ( ) const
protectedvirtual

Description (type + name) for the output.

Implements codedBase.

Definition at line 63 of file codedFunctionObject.C.

References Foam::name().

Here is the call graph for this function:

◆ clearRedirect()

void clearRedirect ( ) const
protectedvirtual

Clear redirected object(s)

Implements codedBase.

Definition at line 69 of file codedFunctionObject.C.

◆ codeContext()

const Foam::dictionary & codeContext ( ) const
protectedvirtual

Additional 'codeContext' dictionary to pass through.

Definition at line 76 of file codedFunctionObject.C.

References dictionary::findDict(), keyType::LITERAL, and dictionary::null.

Here is the call graph for this function:

◆ codeDict()

const Foam::dictionary & codeDict ( ) const
protectedvirtual

The code dictionary.

Implements codedBase.

Definition at line 84 of file codedFunctionObject.C.

◆ prepare()

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

Adapt the context for the current object.

Implements codedBase.

Definition at line 91 of file codedFunctionObject.C.

References dynamicCode::addCompileFile(), dynamicCode::addCopyFile(), DetailInfo, Foam::endl(), dynamicCodeContext::libs(), dynamicCodeContext::options(), dynamicCode::setFilterVariable(), dynamicCode::setMakeOptions(), and dynamicCodeContext::sha1().

Here is the call graph for this function:

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

References dictionaryContent::dict(), functionObject::New(), Foam::nl, dictionary::set(), and WarningInFunction.

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 189 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 196 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 203 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 210 of file codedFunctionObject.C.

References codedBase::codeContext(), dict, Foam::endl(), IOWarningInFunction, Foam::nl, functionObject::read(), and codedBase::setCodeContext().

Here is the call graph for this function:

Member Data Documentation

◆ dict_

dictionary dict_
protected

Input dictionary.

Definition at line 150 of file codedFunctionObject.H.

◆ name_

word name_
protected

Definition at line 152 of file codedFunctionObject.H.

◆ codeData_

string codeData_
protected

Definition at line 154 of file codedFunctionObject.H.

◆ codeRead_

string codeRead_
protected

Definition at line 155 of file codedFunctionObject.H.

◆ codeExecute_

string codeExecute_
protected

Definition at line 156 of file codedFunctionObject.H.

◆ codeWrite_

string codeWrite_
protected

Definition at line 157 of file codedFunctionObject.H.

◆ codeEnd_

string codeEnd_
protected

Definition at line 158 of file codedFunctionObject.H.

◆ redirectFunctionObjectPtr_

autoPtr<functionObject> redirectFunctionObjectPtr_
mutableprotected

Underlying functionObject.

Definition at line 161 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 198 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 202 of file codedFunctionObject.H.


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