Skip to main content

codedFixedValue

Description

The codedFixedValue is a fixed-value boundary condition that provides an interface to prescribe a user-coded condition and constructs a new boundary condition on-the-fly (derived from fixedValue condition) which is then used to evaluate.

Usage

The condition requires entries in both the boundary and field files.

Boundary file

<patchName>
{
type <type>;
...
}

Field file

<patchName>
{
// Mandatory entries
type codedFixedValue;
name <word>;

// Optional entries
codeInclude
#{
#include "fvCFD.H"
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};

codeLibs
#{
-lfiniteVolume \
-lmeshTools
#};

localCode
#{
// OpenFOAM C++ code
#};

codeContext <dict>;

// Conditional entries

// if the 'code' keyword is present
code
#{
// OpenFOAM C++ code
#};

// if the 'code' keyword is not present,
// read the code from a dictionary from 'system/codeDict'
<patchName>
{
code
#{
// OpenFOAM C++ code
#};
}

// Inherited entries
...
}

where:

PropertyDescriptionTypeRequiredDefault
typeType name: codedFixedValuewordyes-
nameName of the generated conditionwordyes-
codeOpenFOAM C++ code for patch value assignmentcodeyes-
codeIncludeInclude files-no-
codeOptionsCompiler line: added to EXE_INC (Make/options)-no-
codeLibsLinker line: added to LIB_LIBS (Make/options)-no-
localCodeLocal static functions-no-
codeContextAdditional dictionary context for the codedictno-

The inherited entries are elaborated in:

A simple example showing how to ramp the patch values as a function of time

p=min(10,0.1t) p = \min (10, 0.1 t)

is specified in the field file using:

<patchName>
{
type codedFixedValue;
value uniform 0;

name rampedFixedValue;

code
#{
const scalar t = this->db().time().value();
operator==(min(10, 0.1*t));
#};
}

Only basic functionality is offered by default, e.g. access to the mesh (Foam::fvMesh) and time (Foam::Time) databases. For more complex conditions access to additional classes is enabled via the optional codeInclude and codeOptions entries, e.g.

codeInclude
#{
#include "fvCFD.H"
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude
#};

This is equivalent to the required entries in the Make/options file when building code libraries.

Further information

Tutorial:

Source code:

API:

History: Introduced in version 2.0.0