Loading...
Searching...
No Matches
fvExpressionField Class Reference

Function object that generates or modifies a field based on expressions. More...

#include <fvExpressionField.H>

Inheritance diagram for fvExpressionField:
Collaboration diagram for fvExpressionField:

Public Types

enum  actionType : unsigned char { opNone = 0 , opNew , opModify }
 Action type enumeration. More...

Public Member Functions

 TypeName ("exprField")
 Runtime type information.
 fvExpressionField (const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false)
 Construct from name, Time and dictionary.
 fvExpressionField (const fvExpressionField &)=delete
 No copy construct.
void operator= (const fvExpressionField &)=delete
 No copy assignment.
virtual ~fvExpressionField ()
 Destructor.
virtual word fieldName () const
 Qualified/unqualified field name (depends on action).
virtual bool read (const dictionary &dict)
 Read the function-object dictionary.
virtual bool execute ()
 Execute the function-object operations.
virtual bool write ()
 Write the function-object results.
Public Member Functions inherited from fvMeshFunctionObject
 TypeName ("fvMeshFunctionObject")
 Runtime type information.
 fvMeshFunctionObject (const word &name, const Time &runTime, const dictionary &dict)
 Construct from Time and dictionary.
 fvMeshFunctionObject (const word &name, const objectRegistry &obr, const dictionary &dict)
 Construct from the region objectRegistry and dictionary.
virtual ~fvMeshFunctionObject ()=default
 Destructor.
Public Member Functions inherited from regionFunctionObject
 TypeName ("regionFunctionObject")
 Runtime type information.
 regionFunctionObject (const word &name, const Time &runTime, const dictionary &dict)
 Construct from Time and dictionary.
 regionFunctionObject (const word &name, const objectRegistry &obr, const dictionary &dict)
 Construct from the region objectRegistry and dictionary.
virtual ~regionFunctionObject ()=default
 Destructor.
template<class ObjectType>
const ObjectType * lookupObjectPtr (const word &fieldName) const
 Deprecated(2018-10).
template<class ObjectType>
ObjectType * lookupObjectRefPtr (const word &fieldName) const
 Deprecated(2018-10).
Public Member Functions inherited from stateFunctionObject
 stateFunctionObject (const word &name, const Time &runTime)
 Construct from components.
virtual ~stateFunctionObject ()=default
 Destructor.
dictionarypropertyDict ()
 Return access to the property dictionary.
bool foundProperty (const word &entryName) const
 Return true if the property exists.
void clearTrigger ()
 Remove the trigger index from the properties.
label getTrigger () const
 Get the current trigger index.
bool setTrigger (const label triggeri)
 Set new trigger index.
bool getDict (const word &entryName, dictionary &dict) const
 Set dictionary, return true if set.
bool getObjectDict (const word &objectName, const word &entryName, dictionary &dict) const
 Set dictionary from named object, return true if set.
template<class Type>
Type getProperty (const word &entryName, const Type &defaultValue=Type(Zero)) const
 Retrieve generic property.
template<class Type>
bool getProperty (const word &entryName, Type &value) const
 Set generic property, return true if set.
template<class Type>
void setProperty (const word &entryName, const Type &value)
 Add generic property.
template<class Type>
Type getObjectProperty (const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
 Retrieve generic property from named object.
template<class Type>
bool getObjectProperty (const word &objectName, const word &entryName, Type &value) const
 Set generic property from named object, return true if set.
template<class Type>
void setObjectProperty (const word &objectName, const word &entryName, const Type &value)
 Add generic property from named object.
bool getObjectResultDict (const word &objectName, dictionary &dict) const
template<class Type>
void setResult (const word &entryName, const Type &value)
 Add result.
template<class Type>
void setObjectResult (const word &objectName, const word &entryName, const Type &value)
 Add result from named object.
template<class Type>
Type getResult (const word &entryName, const Type &defaultValue=Type(Zero)) const
 Retrieve result.
template<class Type>
Type getObjectResult (const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
 Retrieve result from named object.
template<class Type>
bool getObjectResult (const word &objectName, const word &entryName, Type &value) const
 Set result from named object, return true if set.
word resultType (const word &entryName) const
 Retrieve the result type.
word objectResultType (const word &objectName, const word &entryName) const
 Return the type of result.
wordList objectResultEntries () const
 Retrieve the result entries.
wordList objectResultEntries (const word &objectName) const
 Return result entries for named object.
void writeResultEntries (Ostream &os) const
 Write the results entries for all objects to stream.
void writeResultEntries (const word &objectName, Ostream &os) const
 Write the results entries for named object to stream.
void writeAllResultEntries (Ostream &os) const
 Write the results entries for all objects to stream.
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 end ()
 Called when Time::run() determines that the time-loop exits.
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.

Static Public Attributes

static const Enum< actionTypeactionNames_
 Action type names.
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

template<class FieldType>
bool loadAndStore (const IOobject &io)
 Attempt load from io, store on database if successful.
template<class Type>
bool loadField (const IOobject &io)
 Forward to loadAndStore for supported types.
label loadFields (const UList< word > &fieldSet_)
 Attempt to load specified fields.
template<class GeoField>
bool setField (GeoField &output, const GeoField &evaluated, const boolField &cond)
 Sets the values of the output field based on a condition.
bool performAction (bool doWrite)
 Execute the requested action.
Protected Member Functions inherited from fvMeshFunctionObject
 fvMeshFunctionObject (const fvMeshFunctionObject &)=delete
 No copy construct.
void operator= (const fvMeshFunctionObject &)=delete
 No copy assignment.
Protected Member Functions inherited from regionFunctionObject
virtual const objectRegistryobr () const
 The region or sub-region registry being used.
template<class ObjectType>
bool foundObject (const word &fieldName) const
 Find object (eg, a field) in the (sub) objectRegistry.
template<class ObjectType>
const ObjectType * cfindObject (const word &fieldName) const
 Return const pointer to the object (eg, a field) in the (sub) objectRegistry.
template<class ObjectType>
const ObjectType * findObject (const word &fieldName) const
 Return const pointer to the object (eg, a field) in the (sub) objectRegistry.
template<class ObjectType>
ObjectType * findObject (const word &fieldName)
 Return non-const pointer to the object of the given Type, (sub) objectRegistry.
template<class ObjectType>
ObjectType * getObjectPtr (const word &fieldName) const
 Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a mutable.
template<class ObjectType>
const ObjectType & lookupObject (const word &fieldName) const
 Lookup and return object (eg, a field) from the (sub) objectRegistry.
template<class ObjectType>
ObjectType & lookupObjectRef (const word &fieldName) const
 Lookup and return object (eg, a field) from the (sub) objectRegistry.
template<class ObjectType>
bool store (word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
 Store the field in the (sub) objectRegistry under the given name.
template<class ObjectType>
bool storeInDb (const word &fieldName, const tmp< ObjectType > &tfield, const objectRegistry &obr)
 Store the field in an optional objectRegistry under the given name.
bool writeObject (const word &fieldName)
 Write field if present in the (sub) objectRegistry.
bool clearObject (const word &fieldName)
 Clear field from the (sub) objectRegistry if present.
void clearObjects (const wordList &objNames)
 Clear fields from the (sub) objectRegistry if present.
 regionFunctionObject (const regionFunctionObject &)=delete
 No copy construct.
void operator= (const regionFunctionObject &)=delete
 No copy assignment.
Protected Member Functions inherited from stateFunctionObject
const functionObjects::propertiesstateDict () const
 Return a const reference to the state dictionary.
functionObjects::propertiesstateDict ()
 Return non-const access to the state dictionary.
 stateFunctionObject (const stateFunctionObject &)=delete
 No copy construct.
void operator= (const stateFunctionObject &)=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 Attributes

dictionary dict_
 The context dictionary.
word fieldName_
 Name of the field.
wordList preloadFields_
 Names fields to preload.
expressions::exprString maskExpr_
 The field-mask expression (modify mode).
expressions::exprString valueExpr_
 Expression to evaluate.
dimensionSet dimensions_
 Dimensions for new field.
actionType action_
 Operation mode.
bool autowrite_
 Set AUTO_WRITE for new field.
bool store_
 Store calculated field.
bool hasDimensions_
 True if dimensions_ should be used (creation).
bool loadFromFiles_
 Load fields from files (not from objectRegistry).
autoPtr< expressions::volumeExprDriverdriver_
Protected Attributes inherited from fvMeshFunctionObject
const fvMeshmesh_
 Reference to the fvMesh.
Protected Attributes inherited from regionFunctionObject
word subRegistryName_
 Name for alternative object registry.
const objectRegistryobr_
 Reference to the region objectRegistry.
const objectRegistryobrPtr_
 Pointer to alternative (eg, sub-region) objectRegistry.
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.

Detailed Description

Function object that generates or modifies a field based on expressions.

Usage
A minimal example:
exprFieldFO
{
    // Mandatory entries
    type            exprField;
    libs            (fieldFunctionObjects);
    field           <word>;  // pTotal;
    expression      "p + 0.5*(rho*magSqr(U))";

    // Optional entries
    action          <word>;            // none, new, modify
    autowrite       <bool>;
    store           <bool>;
    dimensions      [ Pa ];         // for new field only
    readFields      (<wordList>);   // (p U rho), for post-process mode only
    useNamePrefix   false;          // for new field only

    // Inherited entries
    ...
}

// Modify an existing field
<name2>
{
    type    exprField;
    libs    (fieldFunctionObjects);
    field   pTotal;
    action  modify;

    // Static pressure only in these regions
    fieldMask   "(mag(pos()) < 0.05) && (pos().y() > 0)";
    expression  "p";
}

where the entries mean:

Property Description Type Reqd Deflt
type Type name: exprField word yes
libs Libraries: fieldFunctionObjects wordList yes
field Name of input or output field word yes
expression Field evaluation expression string yes
action Type of operation: see below word no new
autowrite Add AUTO_WRITE to created field bool no false
store Store calculated field bool no true
fieldMask Masking as logical expression string no ""
dimensions Apply specified dimensions to created field dim-spec no
readFields Preload named fields (post-process mode) wordList no
useNamePrefix Add prefix scoping to output name bool no false

Options for the action entry:

none :No operation
new :Define field based on expression (default)
modify :Adjust field according to expression and fieldMask

The inherited entries are elaborated in:

Note
The useNamePrefix entry is always ignored for the modify action.
Source files

Definition at line 204 of file fvExpressionField.H.

Member Enumeration Documentation

◆ actionType

enum actionType : unsigned char

Action type enumeration.

Enumerator
opNone 

No operation.

opNew 

Create/overwrite field (default).

opModify 

Modify existing field.

Definition at line 215 of file fvExpressionField.H.

Constructor & Destructor Documentation

◆ fvExpressionField() [1/2]

fvExpressionField ( const word & name,
const Time & runTime,
const dictionary & dict,
const bool loadFromFiles = false )

Construct from name, Time and dictionary.

Definition at line 288 of file fvExpressionField.C.

References action_, autowrite_, dict, dict_, dimensions_, fieldName_, fvMeshFunctionObject::fvMeshFunctionObject(), hasDimensions_, loadFromFiles_, maskExpr_, Foam::name(), opNew, preloadFields_, read(), runTime, store_, and valueExpr_.

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

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

◆ fvExpressionField() [2/2]

fvExpressionField ( const fvExpressionField & )
delete

No copy construct.

References fvExpressionField().

Here is the call graph for this function:

◆ ~fvExpressionField()

~fvExpressionField ( )
virtual

Destructor.

Definition at line 315 of file fvExpressionField.C.

Member Function Documentation

◆ loadAndStore()

template<class FieldType>
bool loadAndStore ( const IOobject & io)
protected

Attempt load from io, store on database if successful.

Definition at line 125 of file fvExpressionField.C.

References Foam::endl(), io, Log, fvMeshFunctionObject::mesh_, and regIOobject::store().

Referenced by loadField().

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

◆ loadField()

template<class Type>
bool loadField ( const IOobject & io)
protected

Forward to loadAndStore for supported types.

|| loadAndStore<VolumeInternalField<Type>>(io)

Definition at line 142 of file fvExpressionField.C.

References io, and loadAndStore().

Referenced by loadFields().

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

◆ loadFields()

Foam::label loadFields ( const UList< word > & fieldSet_)
protected

Attempt to load specified fields.

Definition at line 153 of file fvExpressionField.C.

References DebugInfo, Foam::endl(), fieldName(), io, loadField(), fvMeshFunctionObject::mesh_, IOobjectOption::MUST_READ, and IOobjectOption::NO_WRITE.

Referenced by performAction().

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

◆ setField()

template<class GeoField>
bool setField ( GeoField & output,
const GeoField & evaluated,
const boolField & cond )
protected

Sets the values of the output field based on a condition.

Definition at line 214 of file fvExpressionField.C.

References action_, dimensions_, Foam::doCorrectBoundaryConditions(), UList< T >::empty(), Foam::endl(), forAll, hasDimensions_, Foam::Info, name, Foam::nl, opModify, Foam::reduce(), and Foam::returnReduce().

Here is the call graph for this function:

◆ performAction()

bool performAction ( bool doWrite)
protected

◆ TypeName()

TypeName ( "exprField" )

Runtime type information.

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

Here is the call graph for this function:

◆ operator=()

void operator= ( const fvExpressionField & )
delete

No copy assignment.

References dict, and fvExpressionField().

Here is the call graph for this function:

◆ fieldName()

Foam::word fieldName ( ) const
virtual

Qualified/unqualified field name (depends on action).

Definition at line 321 of file fvExpressionField.C.

References action_, fieldName_, word::null, opModify, opNew, opNone, and functionObject::scopedName().

Referenced by loadFields(), performAction(), and read().

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

◆ read()

bool read ( const dictionary & dict)
virtual

Read the function-object dictionary.

Reimplemented from regionFunctionObject.

Definition at line 343 of file fvExpressionField.C.

References action_, actionNames_, autowrite_, dict, dict_, dimensions_, driver_, Foam::endl(), fieldName(), fieldName_, hasDimensions_, loadFromFiles_, Log, maskExpr_, fvMeshFunctionObject::mesh_, name, Foam::nl, opModify, opNew, opNone, preloadFields_, functionObject::read(), exprDriver::SEARCH_FILES, exprDriver::SEARCH_REGISTRY, store_, Foam::type(), and valueExpr_.

Referenced by fvExpressionField().

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

◆ execute()

bool execute ( )
virtual

Execute the function-object operations.

Implements functionObject.

Definition at line 672 of file fvExpressionField.C.

References performAction().

Here is the call graph for this function:

◆ write()

bool write ( )
virtual

Write the function-object results.

Implements functionObject.

Definition at line 678 of file fvExpressionField.C.

References performAction().

Here is the call graph for this function:

Member Data Documentation

◆ actionNames_

Action type names.

Definition at line 225 of file fvExpressionField.H.

Referenced by performAction(), and read().

◆ dict_

dictionary dict_
protected

The context dictionary.

Definition at line 235 of file fvExpressionField.H.

Referenced by fvExpressionField(), and read().

◆ fieldName_

word fieldName_
protected

Name of the field.

Definition at line 240 of file fvExpressionField.H.

Referenced by fieldName(), fvExpressionField(), and read().

◆ preloadFields_

wordList preloadFields_
protected

Names fields to preload.

Definition at line 245 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ maskExpr_

expressions::exprString maskExpr_
protected

The field-mask expression (modify mode).

Definition at line 250 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ valueExpr_

expressions::exprString valueExpr_
protected

Expression to evaluate.

Definition at line 255 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ dimensions_

dimensionSet dimensions_
protected

Dimensions for new field.

Definition at line 260 of file fvExpressionField.H.

Referenced by fvExpressionField(), read(), and setField().

◆ action_

actionType action_
protected

Operation mode.

Definition at line 265 of file fvExpressionField.H.

Referenced by fieldName(), fvExpressionField(), performAction(), read(), and setField().

◆ autowrite_

bool autowrite_
protected

Set AUTO_WRITE for new field.

Definition at line 270 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ store_

bool store_
protected

Store calculated field.

Definition at line 275 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ hasDimensions_

bool hasDimensions_
protected

True if dimensions_ should be used (creation).

Definition at line 280 of file fvExpressionField.H.

Referenced by fvExpressionField(), read(), and setField().

◆ loadFromFiles_

bool loadFromFiles_
protected

Load fields from files (not from objectRegistry).

Definition at line 285 of file fvExpressionField.H.

Referenced by fvExpressionField(), performAction(), and read().

◆ driver_

Definition at line 287 of file fvExpressionField.H.

Referenced by performAction(), and read().


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