8.1
general documentation
Minimalist example to solve a Laplacian using CDO schemes

Introduction

Here is a minimalist example to solve a scalar-valued Laplacian problem (an isotropic diffusion equation). Since one considers the CDO framework to solve this problem, this enables a quick start with this framework. This simple example is performed in three steps:

For a very beginner, one strongly advises to read the page Case directory structure.

In a terminal, write the following syntax for the creation of a new study with a new case:

code_saturne create --study STUDY CASE_NAME1

which creates a study directory STUDY with case sub-directory CASE_NAME1. If no case name is given, a default case directory called CASE1 is created.

First step: Preprocessing

One assumes that the mesh is a Cartesian mesh generated using the GUI but other ways are also possible. A more detail description of the different preprocessing possibilities is available here

GUI: Cartesian mesh definition

The generated Cartesian is built with 6 mesh face groups collecting boundary faces and named X0, X1, Y0, Y1, Z0 and Z1. These mesh face groups are used to define the two boundary zones needed for this example. One proceeds as detailed in the GUI screenshot.

Second step: Activate CDO and add a user-defined equation

The second step corresponds to the edition of the user source file named cs_user_parameters.c and especially the function cs_user_model

Click on the icon displayed just below in the GUI toolbar which corresponds to "Open the source file editor"

Then right-click on the file named REFERENCE/cs_user_parameters.c and select Copy to SRC. Then, you can choose your favorite file editor to add in the function cs_user_model the following lines.

{
/* Activate CDO/HHO mode */
/* Add a user-defined equation */
cs_equation_add_user("Laplacian", /* equation name */
"potential", /* associated variable field name */
1, /* dimension of the unknown */
CS_PARAM_BC_HMG_NEUMANN); /* default boundary condition */
}
cs_equation_t * cs_equation_add_user(const char *eqname, const char *varname, int dim, cs_param_bc_type_t default_bc)
Add a new user equation structure and set a first set of parameters.
Definition: cs_equation.c:1606
void cs_param_cdo_mode_set(cs_param_cdo_mode_t mode)
Set the global variable storing the mode of activation to apply to CDO/HHO schemes....
Definition: cs_param_cdo.c:113
@ CS_PARAM_CDO_MODE_ONLY
Definition: cs_param_cdo.h:94
@ CS_PARAM_BC_HMG_NEUMANN
Definition: cs_param_types.h:480

This first activates the CDO module (please refer to Activation of CDO/HHO schemes for more details) and then add a new scalar equation called Laplacian with an unknown named potential. This will be the name of the associated variable field. A default boundary condition is also defined and it corresponds to an homogeneous Neumann boundary condition. If no other boundary condition is defined, then all the boundary faces will be associated to this default definition.

Third step: Define the equation to solve

The last step corresponds to the modification of the function cs_user_finalize_setup in the file cs_user_parameters.c

{
/* The property named "unity" is defined by default. Associate this
property to the diffusion term and add it to the equation settings. */
/* Boundary conditions (One assumes that two boundary zones named "X0" and
"X1" exist. This is the case for instance if a Cartesian mesh is
generated from the GUI. The two boundary zones are added in the
GUI. Label is set to "X0" (resp. "X1") and selection criterion "X0"
(resp. "X1").
*/
cs_real_t T0 = 0, T1 = 1;
}
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_equation_param_t * cs_equation_param_by_name(const char *eqname)
Return the cs_equation_param_t structure associated to a cs_equation_t structure based on the equatio...
Definition: cs_equation.c:614
cs_xdef_t * cs_equation_add_bc_by_value(cs_equation_param_t *eqp, const cs_param_bc_type_t bc_type, const char *z_name, cs_real_t *values)
Define and initialize a new structure to set a boundary condition related to the given equation struc...
Definition: cs_equation_param.c:2590
void cs_equation_add_diffusion(cs_equation_param_t *eqp, cs_property_t *property)
Associate a new term related to the Laplacian operator for the equation associated to the given cs_eq...
Definition: cs_equation_param.c:3343
@ CS_PARAM_BC_DIRICHLET
Definition: cs_param_types.h:479
cs_property_t * cs_property_by_name(const char *name)
Find the related property definition from its name.
Definition: cs_property.c:1088
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition: cs_equation_param.h:192

After having retrieved the structure cs_equation_param_t associated to the equation to solve, one first add a diffusion term which is associated to the default property named unity. Then, one defines two Dirichlet boundary conditions: a first one on the left side (X0) with a value equal to 0 and a second one on the right side (X1) with a value equal to 1.

Last step: Run the computation

For a very beginner, one strongly advises to read the page Running a calculation.

In a terminal, write the following syntax when your current directory corresponds to one of the sub-directories of a case.

code_saturne run

To go beyond

In order to change the numerical settings related to an equation call the function cs_equation_param_set inside the user function named cs_user_parameters in the file cs_user_parameters.c

Here are some examples of numerical settings:

{
/* The modification of the space discretization should be apply first */
/* Modify other parameters than the space discretization */
/* Linear algebra settings */
#if defined(HAVE_PETSC)
#else
#endif
}
void cs_equation_param_set(cs_equation_param_t *eqp, cs_equation_key_t key, const char *keyval)
Set a parameter attached to a keyname in a cs_equation_param_t structure.
Definition: cs_equation_param.c:1789
@ CS_EQKEY_ITSOL_RTOL
Definition: cs_equation_param.h:1238
@ CS_EQKEY_SOLVER_FAMILY
Definition: cs_equation_param.h:1248
@ CS_EQKEY_VERBOSITY
Definition: cs_equation_param.h:1252
@ CS_EQKEY_ITSOL_MAX_ITER
Definition: cs_equation_param.h:1235
@ CS_EQKEY_ITSOL
Definition: cs_equation_param.h:1231
@ CS_EQKEY_HODGE_DIFF_COEF
Definition: cs_equation_param.h:1228
@ CS_EQKEY_HODGE_DIFF_ALGO
Definition: cs_equation_param.h:1227
@ CS_EQKEY_ITSOL_RESNORM_TYPE
Definition: cs_equation_param.h:1236
@ CS_EQKEY_PRECOND
Definition: cs_equation_param.h:1240
@ CS_EQKEY_ADV_SCHEME
Definition: cs_equation_param.h:1216
@ CS_EQKEY_SPACE_SCHEME
Definition: cs_equation_param.h:1249

This relies on a key value principle. The available keys are listed here

For the reader willing to get a better understanding of the mathematical concepts underpinning the CDO schemes, one refers to the PhD thesis entitled Compatible Discrete Operator schemes on polyhedral meshes for elliptic and Stokes equations [3]