![]() |
programmer's documentation
|
The routine is called for each scalar, user or specific physisc. It is therefore necessary to test the value of the scalar number iscal to separate the treatments of the different scalars (if (iscal.eq.p) then ....)
.
The additional source term is decomposed into an explicit part and an implicit part
that must be provided here. The resulting equation solved by the code for a scalar
is:
The and
arrays are already initialized to 0 before entering the the routine. It is not needed to do it in the routine (waste of CPU time).
For stability reasons, Code_Saturne
will not add -crvimp
directly to the diagonal of the matrix, but Max(-crvimp,0).
This way, the crvimp
term is treated implicitely only if it strengthens the diagonal of the matrix. However, when using the second-order in time scheme, this limitation cannot be done anymore and -crvimp
is added directly. The user should therefore test the negativity of crvimp
by himself.
When using the second-order in time scheme, one should supply:
crvexp
at time ncrvimp
at time n+1/2The selection of cells where to apply the source terms is based on a getcel command. For more info on the syntax of the getcel command, refer to the user manual or to the comments on the similar command getfbr in the routine cs_user_boundary_conditions.
In case of a complex, non-linear source term, say , for scalar
, the easiest method is to implement the source term explicitely.
where is the value of
at time
, the beginning of the time step.
This yields :
crvexp = volume*F(f(n))
crvimp = 0
However, if the source term is potentially steep, this fully explicit method will probably generate instabilities. It is therefore wiser to partially implicit the term by writing:
This yields:
crvexp = volume*( F(f(n)) - dF/df*f(n) )
crvimp = volume*dF/df
The following initialization block needs to be added for the following examples:
At the end of the subroutine, it is recommended to deallocate the work array:
In theory Fortran 95 deallocates locally-allocated arrays automatically, but deallocating arrays in a symmetric manner to their alloacation is good pratice, and avoids using a different logic between C and Fortran.
Remaining initialization
Index number of the variable associated to scalar iscal
Name of the variable associated to scalar iscal
Indicator of variance scalars
iscavr(iscal) = 0
: the scalar iscal
is not a variance iscavr(iscal) > 0
and iscavr(iscal) < nscal + 1:
the scalar iscal
is the variance of the scalar iscavr(iscal)
Density
Example of arbitrary source term for the scalar f, 2nd scalar in the calculation.
appearing in the equation under the form
In the following example:
with:
which yields:
crvimp(iel) = volume(iel)*A = -volume(iel)*rho/tauf
crvexp(iem) = volume(iel)*B= volume(iel)*rho*prod_f
Source term applied to second scalar
Example of arbitrary volumic heat term in the equation for enthalpy h.
In the considered example, a uniform volumic source of heating is imposed in the cells with coordinate X in [0;1.2] and Y in [3.1;4].
The global heating power if Pwatt
(in ) and the total volume of the selected cells is
volf
(in ).
This yields:
crvimp(iel) = 0
crvexp(iel) = volume(iel)* pwatt/volf
with pwatt = 100.d0