The coded option provides several hooks that can be implemented in C++ code to manipulate the system of equations, e.g. by including additional source terms and modifying the equation matrices.
The coded option is available to all primitive field types, i.e.
scalarCodedSource: scalar equationsvectorCodedSource: vector equationssphericalTensorCodedSource: vector equationssymmTensorCodedSource: vector equationstensorCodedSource: vector equationsIt provides hooks to:
codeAddSupcodeSetValuecodeCorrectAn example showing how to add a source to the energy equation of the form
\[ S_h = \frac{1}{V} 100000 \sin(200 C_x) \]
is shown below:
codedSource
{
type coded;
selectionMode all;
fields (h);
name sourceTime;
codeAddSup
#{
const Time& time = mesh().time();
const scalarField& V = mesh_.V();
scalarField& heSource = eqn.source();
// Start time
const scalar startTime = 2.0;
// Retrieve the x component of the cell centres
const scalarField& cellx = mesh_.C().component(0);
// Only apply when we have reached the start time
if (time.value() > startTime)
{
// Apply the source
forAll(cellx, i)
{
// cell volume specific source
heSource[i] += 1e5*sin(200*cellx[i])*V[i];
};
}
#};
}
By default the coded option links against the following libraries:
finiteVolume: finite volume machinerymeshTools: mesh toolssampling: samplingThese can be extended using the following options:
codeInclude : include additional header filescodeOptions : path to additional header filescodeLibs : linking additional librariesTutorials
Source code
| Would you like to suggest an improvement to this page? | Create an issue |
Copyright © 2018 OpenCFD Ltd.