My Project
programmer's documentation
Functions
cs_user_source_terms.c File Reference

Additional right-hand side source terms for variable equations (momentum, user scalars and specific physics scalars, turbulence...). More...

#include "cs_defs.h"
#include <assert.h>
#include <math.h>
#include <ple_coupling.h>
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "cs_base.h"
#include "cs_field.h"
#include "cs_field_pointer.h"
#include "cs_field_operator.h"
#include "cs_mesh.h"
#include "cs_mesh_quantities.h"
#include "cs_halo.h"
#include "cs_halo_perio.h"
#include "cs_log.h"
#include "cs_notebook.h"
#include "cs_parameters.h"
#include "cs_prototypes.h"
#include "cs_rotation.h"
#include "cs_time_moment.h"
#include "cs_time_step.h"
#include "cs_turbomachinery.h"
#include "cs_selector.h"
#include "cs_post.h"
Include dependency graph for cs_user_source_terms.c:

Functions

void cs_user_source_terms (cs_domain_t *domain, int f_id, cs_real_t *st_exp, cs_real_t *st_imp)
 Function called at each time step to define physical properties. More...
 

Detailed Description

Additional right-hand side source terms for variable equations (momentum, user scalars and specific physics scalars, turbulence...).

Usage

The routine is called for each variable. It is therefore necessary to test the value of the field id to separate the treatments of the different variables (if (f_id.eq.CS_F(p)->id) then ....).

The additional source term is decomposed into an explicit part (st_exp) and an implicit part (st_imp) that must be provided here. The resulting equation solved by the code for a scalar f is:

\[ \rho*volume*\frac{df}{dt} + .... = st\_imp*f + st\_exp \]

Note that st_exp and st_imp are defined after the Finite Volume integration over the cells, so they include the "volume" term. More precisely:

The st_exp and st_imp 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 -st_imp directly to the diagonal of the matrix, but Max(-st_imp,0). This way, the st_imp 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 -st_imp is added directly. The user should therefore test the negativity of st_imp by himself.

When using the second-order in time scheme, one should supply:

The 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.

WARNING: If variable is the temperature, the resulting equation solved by the code is:

rho*Cp*volume*dT/dt + .... = st_imp*T + st_exp

Note that st_exp and st_imp are defined after the Finite Volume integration over the cells, so they include the "volume" term. More precisely:

STEP SOURCE TERMS

In case of a complex, non-linear source term, say F(f), for variable f, the easiest method is to implement the source term explicitely.

df/dt = .... + F(f(n)) where f(n) is the value of f at time tn, the beginning of the time step.

This yields : st_exp = volume*F(f(n)) st_imp = 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:

df/dt = .... + dF/df*f(n+1) - dF/df*f(n) + F(f(n))

This yields: st_exp = volume*( F(f(n)) - dF/df*f(n) ) st_imp = volume*dF/df

Function Documentation

◆ cs_user_source_terms()

void cs_user_source_terms ( cs_domain_t domain,
int  f_id,
cs_real_t st_exp,
cs_real_t st_imp 
)

Function called at each time step to define physical properties.

Parameters
[in,out]domainpointer to a cs_domain_t structure
[in]f_idfield id of the variable
[out]st_expexplicit source term
[out]st_impimplicit part of the source term