My Project
programmer's documentation
|
Additional source terms for variable equations. 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"
Functions | |
void | cs_user_source_terms (cs_domain_t *domain, int f_id, cs_real_t *st_exp, cs_real_t *st_imp) |
Additional user-defined source terms for variable equations (momentum, scalars, turbulence...). More... | |
Additional source terms for variable equations.
See Examples of data settings for source terms (cs_user_source_terms.c) for examples.
void cs_user_source_terms | ( | cs_domain_t * | domain, |
int | f_id, | ||
cs_real_t * | st_exp, | ||
cs_real_t * | st_imp | ||
) |
Additional user-defined source terms for variable equations (momentum, scalars, turbulence...).
This function is called at each time step, for each relevant field. It is therefore necessary to test the value of the field id or name to separate the treatments of the different variables.
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:
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 (or a value defined through the GUI or defined by a model) before entering the function. It is generally not useful to reset them here.
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 check for the negativity of st_imp.
When using the second-order in time scheme, one should supply:
If the variable is a temperature, the resulting equation solved 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:
In case of a complex, non-linear source term, say F(f), for variable f, the easiest method is to implement the source term explicitly.
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
[in,out] | domain | pointer to a cs_domain_t structure |
[in] | f_id | field id of the variable |
[out] | st_exp | explicit source term |
[out] | st_imp | implicit part of the source term |