programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions | Variables
cs_source_term.c File Reference
#include "cs_defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <float.h>
#include <bft_mem.h>
#include "cs_basis_func.h"
#include "cs_evaluate.h"
#include "cs_hho_builder.h"
#include "cs_log.h"
#include "cs_math.h"
#include "cs_volume_zone.h"
#include "cs_source_term.h"
Include dependency graph for cs_source_term.c:

Macros

#define CS_SOURCE_TERM_DBG   0
 

Functions

static char * _get_name (const char *name, const char *base_name, int id)
 Allocate and initialize a name (copy or generic name) More...
 
static void _set_mask (const cs_xdef_t *st, int st_id, cs_mask_t *cell_mask)
 Update the mask associated to each cell from the mask related to the given source term structure. More...
 
static void _hho_add_tetra (const cs_xdef_analytic_input_t *anai, const cs_basis_func_t *cbf, const cs_real_3_t xv1, const cs_real_3_t xv2, const cs_real_3_t xv3, const cs_real_3_t xv4, const double vol, cs_cell_builder_t *cb, cs_real_t array[])
 Compute the reduction onto the cell polynomial space of a function defined by an analytical expression depending on the location and the current time. More...
 
void cs_source_term_set_shared_pointers (const cs_cdo_quantities_t *quant, const cs_cdo_connect_t *connect, const cs_time_step_t *time_step)
 Set shared pointers to main domain members. More...
 
cs_flag_t cs_source_term_set_default_flag (cs_space_scheme_t scheme)
 Set the default flag related to a source term according to the numerical scheme chosen for discretizing an equation. More...
 
void cs_source_term_set_reduction (cs_xdef_t *st, cs_flag_t flag)
 Set advanced parameters which are defined by default in a source term structure. More...
 
cs_flag_t cs_source_term_get_flag (const cs_xdef_t *st)
 Get metadata related to the given source term structure. More...
 
cs_flag_t cs_source_term_init (cs_space_scheme_t space_scheme, const int n_source_terms, const cs_xdef_t **source_terms, cs_source_term_cellwise_t *compute_source[], cs_flag_t *sys_flag, cs_mask_t *source_mask[])
 Initialize data to build the source terms. More...
 
void cs_source_term_compute_cellwise (const int n_source_terms, const cs_xdef_t **source_terms, const cs_cell_mesh_t *cm, const cs_mask_t *source_mask, cs_source_term_cellwise_t *compute_source[], void *input, cs_cell_builder_t *cb, cs_cell_sys_t *csys)
 Compute the local contributions of source terms in a cell. More...
 
void cs_source_term_compute_from_density (cs_flag_t loc, const cs_xdef_t *source, double *p_values[])
 Compute the contribution related to a source term in the case of an input data which is a density. More...
 
void cs_source_term_compute_from_potential (cs_flag_t loc, const cs_xdef_t *source, double *p_values[])
 Compute the contribution related to a source term in the case of an input data which is a potential. More...
 
void cs_source_term_pvsp_by_value (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices by a constant value. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure. More...
 
void cs_source_term_pvsp_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices by an analytical function. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure. More...
 
void cs_source_term_dcsd_by_value (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by a value. More...
 
void cs_source_term_dcsd_bary_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use the barycentric approximation as quadrature to evaluate the integral. Exact for linear function. More...
 
void cs_source_term_dcsd_q1o1_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a the barycentric approximation as quadrature to evaluate the integral. Exact for linear function. More...
 
void cs_source_term_dcsd_q10o2_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a ten-point quadrature rule to evaluate the integral. Exact for quadratic function. More...
 
void cs_source_term_dcsd_q5o3_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a five-point quadrature rule to evaluate the integral. Exact for cubic function. This function may be expensive since many evaluations are needed. Please use it with care. More...
 
void cs_source_term_vcsp_by_value (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices and cells by a constant value. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure. More...
 
void cs_source_term_vcsp_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices and cells by an analytical function. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure. More...
 
void cs_source_term_fbsd_by_value (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density (sd) defined on primal cells by a value. Case of face-based schemes. More...
 
void cs_source_term_fbsd_bary_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at primal cells by an analytical function. Use the barycentric approximation as quadrature to evaluate the integral. Exact for linear function. Case of face-based schemes. More...
 
void cs_source_term_hhosd_by_value (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution of a source term for a cell and add it to the given array of values. Case of a scalar density (sd) defined on primal cells by a value. Case of HHO schemes. More...
 
void cs_source_term_hhosd_by_analytic (const cs_xdef_t *source, const cs_cell_mesh_t *cm, cs_cell_builder_t *cb, void *input, double *values)
 Compute the contribution of a source term for a cell and add it to the given array of values. Case of a scalar density (sd) defined on primal cells by an analytic function. Case of HHO schemes. More...
 

Variables

static const char _err_empty_st []
 
static const cs_cdo_quantities_tcs_cdo_quant
 
static const cs_cdo_connect_tcs_cdo_connect
 
static const cs_time_step_tcs_time_step
 

Macro Definition Documentation

#define CS_SOURCE_TERM_DBG   0

Function Documentation

static char* _get_name ( const char *  name,
const char *  base_name,
int  id 
)
inlinestatic

Allocate and initialize a name (copy or generic name)

Parameters
[in]nameinput name
[in]basenamegeneric name by default if input name is NULL
[in]idid related to this name
Returns
a pointer to a new allocated string
static void _hho_add_tetra ( const cs_xdef_analytic_input_t anai,
const cs_basis_func_t cbf,
const cs_real_3_t  xv1,
const cs_real_3_t  xv2,
const cs_real_3_t  xv3,
const cs_real_3_t  xv4,
const double  vol,
cs_cell_builder_t cb,
cs_real_t  array[] 
)
static

Compute the reduction onto the cell polynomial space of a function defined by an analytical expression depending on the location and the current time.

Parameters
[in]anaipointer to an analytical definition
[in]cbfpointer to a structure for face basis functions
[in]xv1first vertex
[in]xv2second vertex
[in]xv3third vertex
[in]xv4third vertex
[in]volvolume of the tetrahedron
[in,out]cbpointer to a cs_cell_builder_structure_t
[in,out]arrayarray storing values to compute
static void _set_mask ( const cs_xdef_t st,
int  st_id,
cs_mask_t cell_mask 
)
static

Update the mask associated to each cell from the mask related to the given source term structure.

Parameters
[in]stpointer to a cs_xdef_t structure
[in]st_maskid related to this source term
[in,out]cell_maskmask related to each cell to be updated
void cs_source_term_compute_cellwise ( const int  n_source_terms,
const cs_xdef_t **  source_terms,
const cs_cell_mesh_t cm,
const cs_mask_t source_mask,
cs_source_term_cellwise_t compute_source[],
void *  input,
cs_cell_builder_t cb,
cs_cell_sys_t csys 
)

Compute the local contributions of source terms in a cell.

Parameters
[in]n_source_termsnumber of source terms
[in]source_termspointer to the definitions of source terms
[in]cmpointer to a cs_cell_mesh_t structure
[in]source_maskarray storing in a compact way which source term is defined in a given cell
[in]compute_sourcearray of function pointers
[in,out]inputpointer to an element cast on-the-fly
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]csyscellwise algebraic system
void cs_source_term_compute_from_density ( cs_flag_t  loc,
const cs_xdef_t source,
double *  p_values[] 
)

Compute the contribution related to a source term in the case of an input data which is a density.

Parameters
[in]locdescribe where is located the associated DoF
[in]sourcepointer to a cs_xdef_t structure
[in,out]p_valuespointer to the computed values (allocated if NULL)
void cs_source_term_compute_from_potential ( cs_flag_t  loc,
const cs_xdef_t source,
double *  p_values[] 
)

Compute the contribution related to a source term in the case of an input data which is a potential.

Parameters
[in]locdescribe where is located the associated DoF
[in]sourcepointer to a cs_xdef_t structure
[in,out]p_valuespointer to the computed values (allocated if NULL)
void cs_source_term_dcsd_bary_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use the barycentric approximation as quadrature to evaluate the integral. Exact for linear function.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_dcsd_by_value ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by a value.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_dcsd_q10o2_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a ten-point quadrature rule to evaluate the integral. Exact for quadratic function.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_dcsd_q1o1_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a the barycentric approximation as quadrature to evaluate the integral. Exact for linear function.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_dcsd_q5o3_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at dual cells by an analytical function. Use a five-point quadrature rule to evaluate the integral. Exact for cubic function. This function may be expensive since many evaluations are needed. Please use it with care.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_fbsd_bary_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density defined at primal cells by an analytical function. Use the barycentric approximation as quadrature to evaluate the integral. Exact for linear function. Case of face-based schemes.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]valuespointer to the computed values
void cs_source_term_fbsd_by_value ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar density (sd) defined on primal cells by a value. Case of face-based schemes.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed value
cs_flag_t cs_source_term_get_flag ( const cs_xdef_t st)

Get metadata related to the given source term structure.

Parameters
[in,out]stpointer to a cs_xdef_t structure
Returns
the value of the flag related to this source term
void cs_source_term_hhosd_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution of a source term for a cell and add it to the given array of values. Case of a scalar density (sd) defined on primal cells by an analytic function. Case of HHO schemes.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed value
void cs_source_term_hhosd_by_value ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution of a source term for a cell and add it to the given array of values. Case of a scalar density (sd) defined on primal cells by a value. Case of HHO schemes.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed value
cs_flag_t cs_source_term_init ( cs_space_scheme_t  space_scheme,
const int  n_source_terms,
const cs_xdef_t **  source_terms,
cs_source_term_cellwise_t compute_source[],
cs_flag_t sys_flag,
cs_mask_t source_mask[] 
)

Initialize data to build the source terms.

Parameters
[in]space_schemescheme used to discretize in space
[in]n_source_termsnumber of source terms
[in]source_termspointer to the definitions of source terms
[in,out]compute_sourcearray of function pointers
[in,out]sys_flagmetadata about the algebraic system
[in,out]source_maskpointer to an array storing in a compact way which source term is defined in a given cell
Returns
a flag which indicates what to build in a cell mesh structure
void cs_source_term_pvsp_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices by an analytical function. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_pvsp_by_value ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices by a constant value. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
cs_flag_t cs_source_term_set_default_flag ( cs_space_scheme_t  scheme)

Set the default flag related to a source term according to the numerical scheme chosen for discretizing an equation.

Parameters
[in]schemenumerical scheme used for the discretization
Returns
a default flag
void cs_source_term_set_reduction ( cs_xdef_t st,
cs_flag_t  flag 
)

Set advanced parameters which are defined by default in a source term structure.

Parameters
[in,out]stpointer to a cs_xdef_t structure
[in]flagCS_FLAG_DUAL or CS_FLAG_PRIMAL
void cs_source_term_set_shared_pointers ( const cs_cdo_quantities_t quant,
const cs_cdo_connect_t connect,
const cs_time_step_t time_step 
)

Set shared pointers to main domain members.

Parameters
[in]quantadditional mesh quantities struct.
[in]connectpointer to a cs_cdo_connect_t struct.
[in]time_steppointer to a time step structure
void cs_source_term_vcsp_by_analytic ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices and cells by an analytical function. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values
void cs_source_term_vcsp_by_value ( const cs_xdef_t source,
const cs_cell_mesh_t cm,
cs_cell_builder_t cb,
void *  input,
double *  values 
)

Compute the contribution for a cell related to a source term and add it the given array of values. Case of a scalar potential defined at primal vertices and cells by a constant value. A discrete Hodge operator has to be computed before this call and stored inside a cs_cell_builder_t structure.

Parameters
[in]sourcepointer to a cs_xdef_t structure
[in]cmpointer to a cs_cell_mesh_t structure
[in,out]cbpointer to a cs_cell_builder_t structure
[in,out]inputpointer to an element cast on-the-fly (or NULL)
[in,out]valuespointer to the computed values

Variable Documentation

const char _err_empty_st[]
static
Initial value:
=
" Stop setting an empty cs_xdef_t structure.\n"
" Please check your settings.\n"
const cs_cdo_connect_t* cs_cdo_connect
static
const cs_cdo_quantities_t* cs_cdo_quant
static
const cs_time_step_t* cs_time_step
static