My Project
programmer's documentation
Functions | Variables
cs_lagr_stat.c File Reference
#include "cs_defs.h"
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bft_printf.h"
#include "bft_error.h"
#include "bft_mem.h"
#include "cs_base.h"
#include "cs_file.h"
#include "cs_math.h"
#include "cs_mesh.h"
#include "cs_mesh_location.h"
#include "cs_mesh_quantities.h"
#include "cs_order.h"
#include "cs_parall.h"
#include "cs_restart_default.h"
#include "cs_timer_stats.h"
#include "cs_time_step.h"
#include "cs_log.h"
#include "cs_array_reduce.h"
#include "cs_field.h"
#include "cs_field_pointer.h"
#include "cs_lagr_tracking.h"
#include "cs_lagr.h"
#include "cs_lagr_stat.h"
Include dependency graph for cs_lagr_stat.c:

Functions

static void _class_name (const char *name, int class_id, char class_name[64])
 Define mesh-based statistic based on particles or particle events. More...
 
static void _group_name (cs_lagr_stat_group_t group, char group_name[64])
 Build group name for logging. More...
 
static void _log_setup_start_time (int nt_start, double t_start, int allow_reset)
 Log moment definition start time for moment or accumulator. More...
 
static const cs_real_t_dt_val (void)
 Return pointer to time step values. More...
 
static void _unit_value_m_elts (const void *input, const cs_lagr_event_set_t *events, int location_id, int class_id, cs_real_t vals[])
 
static void _vol_fraction (const void *input, const cs_lagr_event_set_t *events, int location_id, int class_id, cs_real_t vals[])
 
static void _bdy_mass_flux_update (const void *input, const cs_lagr_event_set_t *events, int location_id, int class_id, cs_real_t vals[])
 
static void _bdy_mass_flux (const void *input, const cs_lagr_event_set_t *events, int location_id, int class_id, cs_real_t vals[])
 
static void _boundary_impact_angle (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _boundary_impact_velocity (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _boundary_resuspension_weight (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _boundary_fouling_weight (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _boundary_fouling_diameter (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _boundary_fouling_coke_fraction (const void *input, const cs_lagr_event_set_t *events, cs_lnum_t id_range[2], cs_real_t vals[])
 
static void _check_moment_type (int type)
 Check statistics type is in possible range. More...
 
static int _n_stat_types (void)
 Return number of possible statistics types. More...
 
static int _n_e_stat_types (void)
 Return number of possible statistics types including events. More...
 
static void _statistical_weight_name (cs_lagr_stat_group_t stat_group, int class, char name[64])
 Create statistical weight. More...
 
static void _attr_moment_name (int attr_id, int component_id, int class_id, cs_lagr_stat_moment_t moment_type, char name[64])
 Create moment name for a moment associated with a particle or event attribute. More...
 
static void _moment_name (const char *base_name, int component_id, int class_id, cs_lagr_stat_moment_t moment_type, char name[64])
 Create moment name. More...
 
static cs_real_t_mwa_val (cs_lagr_moment_wa_t *mwa)
 Return pointer to weight accumulator values. More...
 
static const cs_real_t_mwa_const_val (const cs_lagr_moment_wa_t *mwa)
 Return pointer to weight accumulator values. More...
 
static cs_lnum_t _n_w_elts (const cs_lagr_moment_wa_t *mwa)
 Return number of elements associated with a weight accumulator. More...
 
static void _ensure_init_wa (cs_lagr_moment_wa_t *mwa)
 Initialize weight accumulator if required and reset to 0. More...
 
static void _ensure_init_moment (cs_lagr_moment_t *mt)
 Initialize moment value if required. More...
 
static void _cs_lagr_stat_update_mesh_stats (cs_time_step_t *ts)
 Update particle-based mesh statistics. More...
 
static void _prepare_mesh_stat (cs_lagr_mesh_stat_t *ms)
 Initialize statistics value if required. More...
 
static void _assert_restart_success (int retcode)
 
static int _check_restart (const char *name, const cs_time_step_t *ts, cs_lagr_moment_restart_info_t *ri, int location_id, int wa_location_id, int dim, int moment_type, int stat_type, cs_lagr_stat_group_t stat_group, int class_id, int *nt_start, double *t_start, cs_lagr_stat_restart_t restart_mode)
 Check if a moment can use previous data. More...
 
static void _restart_info_read_auxiliary (cs_restart_t *r)
 
static void _restart_info_read (void)
 
static void _restart_info_free (void)
 
static void _cs_lagr_moment_restart_read (void)
 Read restart moment data. More...
 
static void _init_vars_attribute (void)
 
static void _init_events_attribute (void)
 
static int _find_or_add_wa (cs_lagr_moment_p_data_t *p_data_func, cs_lagr_moment_e_data_t *e_data_func, cs_lagr_moment_m_data_t *m_data_func, const void *data_input, cs_lagr_stat_group_t stat_group, int class_id, int location_id, int nt_start, double t_start, int prev_wa_id)
 Add or find moment weight and time accumulator. More...
 
static cs_field_t_cs_lagr_moment_associate_field (const char *name, int location_id, int dim, bool have_previous)
 Create and associate a field to a moment. More...
 
static int _find_or_add_moment (int location_id, int component_id, int class_id, int stat_type, int dim, cs_lagr_moment_p_data_t *p_data_func, cs_lagr_moment_e_data_t *e_data_func, cs_lagr_moment_m_data_t *m_data_func, const void *data_input, cs_lagr_stat_moment_t m_type, int wa_id, int prev_id)
 Add or find moment structure. . More...
 
static int _find_or_add_mesh_stat (int location_id, int class_id, cs_lagr_stat_group_t stat_group, int dim, cs_lagr_moment_m_data_t *data_func, const void *data_input, int nt_start, double t_start)
 Add or find mesh statistics structure. More...
 
static void _update_wa_m (cs_lagr_moment_wa_t *mwa, cs_real_t *restrict w)
 Update weight accumulator for a mesh-based weight array. More...
 
static void _vv_mesh_location_cells (int location_id_y, const cs_real_t x[], cs_real_t y[])
 Vector-vector multiplication, where the multiplying vector is defined on cells, and the multiplied vector defined on a given mesh location. More...
 
static cs_real_t_compute_current_weight_m (cs_lagr_moment_wa_t *mwa, const cs_real_t *restrict dt, cs_real_t w0[1])
 Compute current weight if weight is based on a mesh (not particle) based function. More...
 
static void _cs_lagr_stat_reset_unsteady (cs_lagr_stat_group_t stat_group, const cs_time_step_t *ts)
 Reset unsteady stats (all accumulators and particle-based moments). More...
 
static void _cs_lagr_stat_update_mesh_moment (cs_lagr_moment_t *mt, const cs_lagr_moment_wa_t *mwa, const cs_real_t *restrict w, int nt_cur)
 Update a given mesh based data function moment. More...
 
static int _location_attr (int location_id)
 Return location attribute to use for an event-based moment or accumulator. More...
 
static void _cs_lagr_stat_update_all (void)
 Update all particle-based moment and time moment accumulators. More...
 
static void _cs_lagr_stat_set_active_event_time (cs_lagr_stat_group_t group, int nt_cur)
 Modify current time for active event-based moment accumulators. More...
 
static void _free_all_moments (void)
 
static void _free_all_wa (void)
 Free all moment weight and time accumulators. More...
 
static void _free_all_mesh_stats (void)
 
static int _stat_moment_define (const char *name, int location_id, int stat_type, cs_lagr_stat_group_t stat_group, cs_lagr_stat_moment_t m_type, int class_id, int dim, int component_id, cs_lagr_moment_p_data_t *p_data_func, cs_lagr_moment_e_data_t *e_data_func, cs_lagr_moment_m_data_t *m_data_func, void *data_input, cs_lagr_moment_p_data_t *w_p_data_func, cs_lagr_moment_e_data_t *w_e_data_func, cs_lagr_moment_m_data_t *w_m_data_func, void *w_data_input, int nt_start, double t_start, cs_lagr_stat_restart_t restart_mode)
 Define a particle statistic. More...
 
static void _event_stat_initialize (void)
 Lagrangian statistics initialization. More...
 
int cs_lagr_stat_particle_define (const char *name, int location_id, int stat_type, cs_lagr_stat_moment_t m_type, int class_id, int dim, int component_id, cs_lagr_moment_p_data_t *data_func, void *data_input, cs_lagr_moment_p_data_t *w_data_func, void *w_data_input, int nt_start, double t_start, cs_lagr_stat_restart_t restart_mode)
 Define a particle-based statistic. More...
 
int cs_lagr_stat_event_define (const char *name, int location_id, int stat_type, cs_lagr_stat_group_t stat_group, cs_lagr_stat_moment_t m_type, int class_id, int dim, int component_id, cs_lagr_moment_e_data_t *data_func, void *data_input, cs_lagr_moment_e_data_t *w_data_func, void *w_data_input, int nt_start, double t_start, cs_lagr_stat_restart_t restart_mode)
 Define an event-based statistic. More...
 
int cs_lagr_stat_mesh_define (const char *name, int location_id, cs_lagr_stat_group_t stat_group, int class_id, int dim, cs_lagr_moment_m_data_t *data_func, void *data_input, int nt_start, double t_start)
 Define mesh-based statistic based on particles or particle events. More...
 
int cs_lagr_stat_accumulator_define (const char *name, int location_id, cs_lagr_stat_group_t stat_group, int class_id, cs_lagr_moment_p_data_t *p_data_func, cs_lagr_moment_e_data_t *e_data_func, void *data_input, int nt_start, double t_start, cs_lagr_stat_restart_t restart_mode)
 Define a particle weight type statistic. More...
 
int cs_lagr_stat_time_moment_define (const char *name, int location_id, int stat_type, cs_lagr_stat_moment_t m_type, int class_id, int dim, int component_id, cs_lagr_moment_m_data_t *data_func, void *data_input, int nt_start, double t_start, cs_lagr_stat_restart_t restart_mode)
 Define a time moment associated to particle statistics. More...
 
void cs_lagr_stat_activate (int stat_type)
 Activate Lagrangian statistics for a given statistics type. More...
 
void cs_lagr_stat_activate_time_moment (int stat_type, cs_lagr_stat_moment_t moment)
 Activate time moment for some predefined Lagrangian statistics types. More...
 
void cs_lagr_stat_deactivate (int stat_type)
 Deactivate Lagrangian statistics for a given statistics type. More...
 
void cs_lagr_stat_activate_attr (int attr_id)
 Activate Lagrangian statistics for a given particle attribute. More...
 
void cs_lagr_stat_deactivate_attr (int attr_id)
 Deactivate Lagrangian statistics for a given particle attribute. More...
 
int cs_lagr_stat_type_from_attr_id (int attr_id)
 Return statistics type associated with a given particle attribute id. More...
 
int cs_lagr_stat_type_to_attr_id (int stat_type)
 Return attribute id associated with a given statistics type. More...
 
int cs_lagr_stat_type_by_name (const char *name)
 Determine a basic statistic type by its base name. More...
 
void cs_lagr_stat_map_cell_dt (const cs_real_t *dt)
 Map time step values array for Lagrangian statistics. More...
 
void cs_lagr_stat_initialize (void)
 Lagrangian statistics initialization. More...
 
bool cs_lagr_stat_is_active (cs_lagr_stat_group_t group)
 Indicate if a given statistics type has active statistics. More...
 
void cs_lagr_stat_restart_read (void)
 Read particle statistics restart info if needed. More...
 
void cs_lagr_stat_prepare (void)
 Prepare particle statistics for a given time step. More...
 
void cs_lagr_stat_update (void)
 Update particle statistics for a given time step. More...
 
void cs_lagr_stat_update_event (cs_lagr_event_set_t *events, cs_lagr_stat_group_t group)
 Update event-based moment accumulators. More...
 
void cs_lagr_stat_finalize (void)
 Destroy all moments management metadata. More...
 
void cs_lagr_stat_log_setup (void)
 Log moment definition setup information. More...
 
void cs_lagr_stat_log_iteration (void)
 Log moment definition information for a given iteration. More...
 
void cs_lagr_stat_restart_write (cs_restart_t *restart)
 Checkpoint moment data. More...
 
cs_field_tcs_lagr_stat_get_moment (int stat_type, cs_lagr_stat_group_t stat_group, cs_lagr_stat_moment_t m_type, int class_id, int component_id)
 Return field associated with a given Lagrangian statistic, given a statistics type (i.e. variable), group (particles or event), moment order, statistical class, and component id. More...
 
cs_field_tcs_lagr_stat_get_stat_weight (int class_id)
 Return statistical weight. More...
 
cs_real_t cs_lagr_stat_get_age (void)
 Return global volume statistics age. More...
 
cs_real_t cs_lagr_stat_get_moment_age (cs_field_t *f)
 Return statistics age for a given moment. More...
 

Variables

static char * _base_stat_activate = NULL
 
static bool _restart_info_checked = false
 
static cs_lagr_moment_restart_info_t * _restart_info = NULL
 
static cs_lagr_moment_wa_t * _lagr_moments_wa = NULL
 
static cs_lagr_moment_t * _lagr_moments = NULL
 
static cs_lagr_mesh_stat_t * _lagr_mesh_stats = NULL
 
static int _n_lagr_moments_wa = 0
 
static int _n_lagr_moments_wa_max = 0
 
static int _n_lagr_moments = 0
 
static int _n_lagr_moments_max = 0
 
static int _n_lagr_mesh_stats = 0
 
static int _n_lagr_mesh_stats_max = 0
 
static double _t_prev_iter = 0.
 
static bool _is_active [CS_LAGR_STAT_GROUP_N_GROUPS] = {false, false}
 
static const cs_real_t_p_dt = NULL
 
const char * cs_lagr_moment_type_name []
 
static const char * _lagr_stat_names []
 
static cs_lagr_stat_options_t _lagr_stat_options
 
cs_lagr_stat_options_tcs_glob_lagr_stat_options = &_lagr_stat_options
 
static int _bdy_mass_flux_filter [2]
 
static int _bdy_resusp_mass_flux_filter [2] = {0, CS_EVENT_RESUSPENSION}
 
static int _bdy_fouling_mass_flux_filter [2] = {0, CS_EVENT_FOULING}
 

Function Documentation

◆ _assert_restart_success()

static void _assert_restart_success ( int  retcode)
static

◆ _attr_moment_name()

static void _attr_moment_name ( int  attr_id,
int  component_id,
int  class_id,
cs_lagr_stat_moment_t  moment_type,
char  name[64] 
)
static

Create moment name for a moment associated with a particle or event attribute.

Parameters
[in]attr_idparticle statistics type
[in]component_idcomponent id, or -1
[in]class_idstatistical class id, or 0
[in]moment_typemoment type
[out]nameresulting name

◆ _bdy_mass_flux()

static void _bdy_mass_flux ( const void *  input,
const cs_lagr_event_set_t events,
int  location_id,
int  class_id,
cs_real_t  vals[] 
)
static

◆ _bdy_mass_flux_update()

static void _bdy_mass_flux_update ( const void *  input,
const cs_lagr_event_set_t events,
int  location_id,
int  class_id,
cs_real_t  vals[] 
)
static

◆ _boundary_fouling_coke_fraction()

static void _boundary_fouling_coke_fraction ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _boundary_fouling_diameter()

static void _boundary_fouling_diameter ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _boundary_fouling_weight()

static void _boundary_fouling_weight ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _boundary_impact_angle()

static void _boundary_impact_angle ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _boundary_impact_velocity()

static void _boundary_impact_velocity ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _boundary_resuspension_weight()

static void _boundary_resuspension_weight ( const void *  input,
const cs_lagr_event_set_t events,
cs_lnum_t  id_range[2],
cs_real_t  vals[] 
)
static

◆ _check_moment_type()

static void _check_moment_type ( int  type)
static

Check statistics type is in possible range.

Parameters
[in]typemoment type

◆ _check_restart()

static int _check_restart ( const char *  name,
const cs_time_step_t ts,
cs_lagr_moment_restart_info_t *  ri,
int  location_id,
int  wa_location_id,
int  dim,
int  moment_type,
int  stat_type,
cs_lagr_stat_group_t  stat_group,
int  class_id,
int *  nt_start,
double *  t_start,
cs_lagr_stat_restart_t  restart_mode 
)
static

Check if a moment can use previous data.

Depending on the restart mode, restart time and time step may also be updated.

Parameters
[in]namemoment name
[in]tstime step status
[in]rirestart info
[in]location_idid of associated mesh location
[in]wa_location_idassociated weight accumulator mesh location id
[in]dimdimension associated with moment
[in]moment_typemoment type
[in]stat_typepredefined statistics type, or -1
[in]stat_groupstatistics group (particle or event)
[in]class_idparticle class id, or 0 for all
[in]nt_startstarting time step
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ _class_name()

static void _class_name ( const char *  name,
int  class_id,
char  class_name[64] 
)
static

Define mesh-based statistic based on particles or particle events.

This type of statistic is reinitialized and evaluated during each time step, but may be computed incrementally when based on particle events, so the associated data function must uptate the statistics without reinitializing them at each call.

As this type of statistic does not need to keep state between time steps, it is ignored by the lagragian statistics checkpoint/restart mechanism.

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]class_idparticle class id, or 0 for all
[out]class_namebase name with class id appended if > 0

◆ _compute_current_weight_m()

static cs_real_t* _compute_current_weight_m ( cs_lagr_moment_wa_t *  mwa,
const cs_real_t *restrict  dt,
cs_real_t  w0[1] 
)
static

Compute current weight if weight is based on a mesh (not particle) based function.

When applicable, this function either returns a pointer to an allocated array, or to w0. If the returned value is different from w0 (i.e. allocated), the caller is responsible for freeing it.

When not applicable (i.e. when no mesh-based weight computation function is defined), NULL is returned.

Parameters
[in,out]mwamoment weight accumulator
[in]dtcell time step values
[in,out]w0pointer to buffer in case weight values is of size 1
Returns
pointer to weight array (w0 or allocated array), or NULL

◆ _cs_lagr_moment_associate_field()

static cs_field_t* _cs_lagr_moment_associate_field ( const char *  name,
int  location_id,
int  dim,
bool  have_previous 
)
static

Create and associate a field to a moment.

Parameters
[in]namefield name
[in]location_idmesh location id
[in]dimfield dimension
[in]have_previousdo we save the previous time values
Returns
associated field

◆ _cs_lagr_moment_restart_read()

static void _cs_lagr_moment_restart_read ( void  )
static

Read restart moment data.

◆ _cs_lagr_stat_reset_unsteady()

static void _cs_lagr_stat_reset_unsteady ( cs_lagr_stat_group_t  stat_group,
const cs_time_step_t ts 
)
static

Reset unsteady stats (all accumulators and particle-based moments).

Parameters
[in]stat_groupstatistics group (particle or event)
[in]tstime step

◆ _cs_lagr_stat_set_active_event_time()

static void _cs_lagr_stat_set_active_event_time ( cs_lagr_stat_group_t  group,
int  nt_cur 
)
static

Modify current time for active event-based moment accumulators.

This allows resetting the previous time after partial updates, and setting the current time at the end of a time loop.

Parameters
[in]groupevent group to update
[in]nt_curcurrent time step to set

◆ _cs_lagr_stat_update_all()

static void _cs_lagr_stat_update_all ( void  )
static

Update all particle-based moment and time moment accumulators.

◆ _cs_lagr_stat_update_mesh_moment()

static void _cs_lagr_stat_update_mesh_moment ( cs_lagr_moment_t *  mt,
const cs_lagr_moment_wa_t *  mwa,
const cs_real_t *restrict  w,
int  nt_cur 
)
static

Update a given mesh based data function moment.

Parameters
[in,out]mtpointer to associated moment
[in]mwapointer to associated weight accumulator
[in]wweight values for current time step
[in]nt_cur

◆ _cs_lagr_stat_update_mesh_stats()

static void _cs_lagr_stat_update_mesh_stats ( cs_time_step_t ts)
static

Update particle-based mesh statistics.

Parameters
[in]tstime step structure

◆ _dt_val()

static const cs_real_t* _dt_val ( void  )
static

Return pointer to time step values.

Returns
pointer to time step values

◆ _ensure_init_moment()

static void _ensure_init_moment ( cs_lagr_moment_t *  mt)
static

Initialize moment value if required.

Parameters
[in,out]mtmoment

◆ _ensure_init_wa()

static void _ensure_init_wa ( cs_lagr_moment_wa_t *  mwa)
static

Initialize weight accumulator if required and reset to 0.

Parameters
[in,out]mwamoment weight accumulator

◆ _event_stat_initialize()

static void _event_stat_initialize ( void  )
static

Lagrangian statistics initialization.

Statistics activated or deactivated by previous calls to cs_lagr_stat_activate, cs_lagr_stat_deactivate, cs_lagr_stat_activate_attr, and cs_lagr_stat_deactivate_attr will be initialized here.

Restart info will be used after to fill in the moments structure

◆ _find_or_add_mesh_stat()

static int _find_or_add_mesh_stat ( int  location_id,
int  class_id,
cs_lagr_stat_group_t  stat_group,
int  dim,
cs_lagr_moment_m_data_t data_func,
const void *  data_input,
int  nt_start,
double  t_start 
)
static

Add or find mesh statistics structure.

Parameters
[in]location_idid of associated mesh location
[in]class_idstatistical class
[in]stat_groupstatistics group (particle or event)
[in]dimdimension associated with element data
[in]data_funcmesh-based function used to define data values
[in]data_inputpointer to optional value or structure to be used by data_func
[in]m_typemoment type, mean or variance
[in]wa_idweight accumulator id
[in]prev_idrestart moment id
Returns
id of matching moment

◆ _find_or_add_moment()

static int _find_or_add_moment ( int  location_id,
int  component_id,
int  class_id,
int  stat_type,
int  dim,
cs_lagr_moment_p_data_t p_data_func,
cs_lagr_moment_e_data_t e_data_func,
cs_lagr_moment_m_data_t m_data_func,
const void *  data_input,
cs_lagr_stat_moment_t  m_type,
int  wa_id,
int  prev_id 
)
static

Add or find moment structure. .

Parameters
[in]location_idid of associated mesh location
[in]component_idattribute component id, or < 0 for all
[in]class_idstatistical class
[in]stat_typestatistics type id, or -1
[in]dimdimension associated with element data
[in]p_data_funcparticle-based function used to define data values, or NULL
[in]e_data_funcevent-based function used to define data values, or NULL
[in]m_data_funcmesh-based function used to define data values, or NULL
[in]data_inputpointer to optional value or structure to be used by data_func
[in]m_typemoment type, mean or variance
[in]wa_idweight accumulator id
[in]prev_idrestart moment id
Returns
id of matching moment

◆ _find_or_add_wa()

static int _find_or_add_wa ( cs_lagr_moment_p_data_t p_data_func,
cs_lagr_moment_e_data_t e_data_func,
cs_lagr_moment_m_data_t m_data_func,
const void *  data_input,
cs_lagr_stat_group_t  stat_group,
int  class_id,
int  location_id,
int  nt_start,
double  t_start,
int  prev_wa_id 
)
static

Add or find moment weight and time accumulator.

If no data function is provided, a constant weight of 1 is assumed (this weight will be multiplied by the time step).

Note that if the data_input associated with a data_func pointer is not NULL, the lifecycle of the data pointed to must be handled separately (and the pointer must remain valid throughout the time moment updates).

Parameters
[in]m_typeassociated moment type
[in]p_data_funcparticle-based function used to define data values, or NULL
[in]e_data_funcevent-based function used to define data values, or NULL
[in]m_data_funcmesh-based function used to define data values, or NULL
[in]data_inputpointer to optional (untyped) value or structure
[in]stat_groupstatistics group (particle or event)
[in]class_idstatistical class number
[in]location_idassociated mesh location id
[in]nt_startstarting time step
[in]t_startstarting time
[in]prev_wa_idprevious weight accumulator id, or -1
Returns
id of matching time accumulator

◆ _free_all_mesh_stats()

static void _free_all_mesh_stats ( void  )
static

◆ _free_all_moments()

static void _free_all_moments ( void  )
static

◆ _free_all_wa()

static void _free_all_wa ( void  )
static

Free all moment weight and time accumulators.

◆ _group_name()

static void _group_name ( cs_lagr_stat_group_t  group,
char  group_name[64] 
)
static

Build group name for logging.

Parameters
[in]groupevent group to update
[out]namegroup log name

◆ _init_events_attribute()

static void _init_events_attribute ( void  )
static

◆ _init_vars_attribute()

static void _init_vars_attribute ( void  )
static

◆ _location_attr()

static int _location_attr ( int  location_id)
static

Return location attribute to use for an event-based moment or accumulator.

Parameters
[in]location_idid of moment or accumulator mesh location
Returns
associated event attribute id

◆ _log_setup_start_time()

static void _log_setup_start_time ( int  nt_start,
double  t_start,
int  allow_reset 
)
static

Log moment definition start time for moment or accumulator.

◆ _moment_name()

static void _moment_name ( const char *  base_name,
int  component_id,
int  class_id,
cs_lagr_stat_moment_t  moment_type,
char  name[64] 
)
static

Create moment name.

Parameters
[in]base_namemoment base name
[in]component_idcomponent id, or -1
[in]class_idstatistical class id, or 0
[in]moment_typemoment type
[out]nameresulting name

◆ _mwa_const_val()

static const cs_real_t* _mwa_const_val ( const cs_lagr_moment_wa_t *  mwa)
static

Return pointer to weight accumulator values.

Parameters
[in]mwapointer to weight accumulator structure
Returns
pointer to weight accumulator values

◆ _mwa_val()

static cs_real_t* _mwa_val ( cs_lagr_moment_wa_t *  mwa)
static

Return pointer to weight accumulator values.

Parameters
[in]mwapointer to weight accumulator structure
Returns
pointer to weight accumulator values

◆ _n_e_stat_types()

static int _n_e_stat_types ( void  )
inlinestatic

Return number of possible statistics types including events.

Returns
number of possible statistics types

◆ _n_stat_types()

static int _n_stat_types ( void  )
inlinestatic

Return number of possible statistics types.

Returns
number of possible statistics types

◆ _n_w_elts()

static cs_lnum_t _n_w_elts ( const cs_lagr_moment_wa_t *  mwa)
static

Return number of elements associated with a weight accumulator.

Returns
number of elements associated with a weight accumulator.

◆ _prepare_mesh_stat()

static void _prepare_mesh_stat ( cs_lagr_mesh_stat_t *  ms)
static

Initialize statistics value if required.

Parameters
[in,out]msmesh-based statistics

◆ _restart_info_free()

static void _restart_info_free ( void  )
static

◆ _restart_info_read()

static void _restart_info_read ( void  )
static

◆ _restart_info_read_auxiliary()

static void _restart_info_read_auxiliary ( cs_restart_t r)
static

◆ _stat_moment_define()

static int _stat_moment_define ( const char *  name,
int  location_id,
int  stat_type,
cs_lagr_stat_group_t  stat_group,
cs_lagr_stat_moment_t  m_type,
int  class_id,
int  dim,
int  component_id,
cs_lagr_moment_p_data_t p_data_func,
cs_lagr_moment_e_data_t e_data_func,
cs_lagr_moment_m_data_t m_data_func,
void *  data_input,
cs_lagr_moment_p_data_t w_p_data_func,
cs_lagr_moment_e_data_t w_e_data_func,
cs_lagr_moment_m_data_t w_m_data_func,
void *  w_data_input,
int  nt_start,
double  t_start,
cs_lagr_stat_restart_t  restart_mode 
)
static

Define a particle statistic.

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_typepredefined statistics type, or -1
[in]stat_groupstatistics group (particle or event)
[in]m_typemoment type
[in]class_idparticle class id, or 0 for all
[in]dimdimension associated with element data
[in]component_idattribute component id, or < 0 for all
[in]p_data_funcpointer to particle function to compute statistics (if stat_type < 0)
[in]e_data_funcpointer to eventfunction to compute statistics (if stat_type < 0)
[in]m_data_funcpointer to mesh location function to compute statistics (if stat_type < 0)
[in]data_inputassociated input
[in]w_p_data_funcpointer to particle function to compute weight (if NULL, statistic weight assumed)
[in]w_e_data_funcpointer to event function to compute weight (if NULL, statistic weight assumed)
[in]w_m_data_funcpointer to mesh location function to compute weight (if stat_type < 0)
[in]w_data_inputassociated input for w_data_func
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ _statistical_weight_name()

static void _statistical_weight_name ( cs_lagr_stat_group_t  stat_group,
int  class,
char  name[64] 
)
static

Create statistical weight.

Parameters
[in]stat_groupstatistics group (particle or event)
[in]classstatistical class id, or 0
[out]nameresulting name

◆ _unit_value_m_elts()

static void _unit_value_m_elts ( const void *  input,
const cs_lagr_event_set_t events,
int  location_id,
int  class_id,
cs_real_t  vals[] 
)
static

◆ _update_wa_m()

static void _update_wa_m ( cs_lagr_moment_wa_t *  mwa,
cs_real_t *restrict  w 
)
static

Update weight accumulator for a mesh-based weight array.

Parameters
[in,out]mwamoment weight accumulator
[in]wpointer to current weight values

◆ _vol_fraction()

static void _vol_fraction ( const void *  input,
const cs_lagr_event_set_t events,
int  location_id,
int  class_id,
cs_real_t  vals[] 
)
static

◆ _vv_mesh_location_cells()

static void _vv_mesh_location_cells ( int  location_id_y,
const cs_real_t  x[],
cs_real_t  y[] 
)
static

Vector-vector multiplication, where the multiplying vector is defined on cells, and the multiplied vector defined on a given mesh location.

Parameters
[in]location_id_ylocation id for y
[in]xmultiplier array
[in,out]ymultiplied array

◆ cs_lagr_stat_accumulator_define()

int cs_lagr_stat_accumulator_define ( const char *  name,
int  location_id,
cs_lagr_stat_group_t  stat_group,
int  class_id,
cs_lagr_moment_p_data_t p_data_func,
cs_lagr_moment_e_data_t e_data_func,
void *  data_input,
int  nt_start,
double  t_start,
cs_lagr_stat_restart_t  restart_mode 
)

Define a particle weight type statistic.

Weights are automatically associated to general statitistics, but defining them explicitely allows activation of standard logging and postprocessing for those weights, as well as defining specific weights.

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_groupstatistics group (particle or event)
[in]class_idparticle class id, or 0 for all
[in]p_data_funcpointer to function to compute particle weight (if NULL, statistic weight assumed)
[in]e_data_funcpointer to function to compute event weight (if NULL, statistic weight assumed)
[in]data_inputassociated input for data_func
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ cs_lagr_stat_activate()

void cs_lagr_stat_activate ( int  stat_type)

Activate Lagrangian statistics for a given statistics type.

This function is ignored if called after cs_lagr_stat_initialize.

Parameters
[in]stat_typeparticle statistics type

◆ cs_lagr_stat_activate_attr()

void cs_lagr_stat_activate_attr ( int  attr_id)

Activate Lagrangian statistics for a given particle attribute.

This function is ignored if called after cs_lagr_stat_initialize.

Parameters
[in]attr_idparticle attribute id

◆ cs_lagr_stat_activate_time_moment()

void cs_lagr_stat_activate_time_moment ( int  stat_type,
cs_lagr_stat_moment_t  moment 
)

Activate time moment for some predefined Lagrangian statistics types.

By default, statistics such as mass flows are based on a current time step, and time moments are not computed by default. This function allows forcing the associated moment level so that it is computed also.

Note that requesting a higher order moment will automatically include lower order moments, so activating the variance also activates the mean.

Parameters
[in]stat_typeparticle statistics type
[in]momentassociated time moment level

◆ cs_lagr_stat_deactivate()

void cs_lagr_stat_deactivate ( int  stat_type)

Deactivate Lagrangian statistics for a given statistics type.

This function is ignored if called after cs_lagr_stat_initialize.

Parameters
[in]stat_typeparticle statistics type

◆ cs_lagr_stat_deactivate_attr()

void cs_lagr_stat_deactivate_attr ( int  attr_id)

Deactivate Lagrangian statistics for a given particle attribute.

This function is ignored if called after cs_lagr_stat_initialize.

Parameters
[in]attr_idparticle attribute id

◆ cs_lagr_stat_event_define()

int cs_lagr_stat_event_define ( const char *  name,
int  location_id,
int  stat_type,
cs_lagr_stat_group_t  stat_group,
cs_lagr_stat_moment_t  m_type,
int  class_id,
int  dim,
int  component_id,
cs_lagr_moment_e_data_t data_func,
void *  data_input,
cs_lagr_moment_e_data_t w_data_func,
void *  w_data_input,
int  nt_start,
double  t_start,
cs_lagr_stat_restart_t  restart_mode 
)

Define an event-based statistic.

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_typepredefined statistics type, or -1
[in]stat_groupstatistics group (event type)
[in]m_typemoment type
[in]class_idparticle class id, or 0 for all
[in]dimdimension associated with element data
[in]component_idattribute component id, or < 0 for all
[in]data_funcpointer to function to compute statistics (if stat_type < 0)
[in]data_inputassociated input
[in]w_data_funcpointer to function to compute weight (if NULL, statistic weight assumed)
[in]w_data_inputassociated input for w_data_func
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ cs_lagr_stat_finalize()

void cs_lagr_stat_finalize ( void  )

Destroy all moments management metadata.

◆ cs_lagr_stat_get_age()

cs_real_t cs_lagr_stat_get_age ( void  )

Return global volume statistics age.

Returns
age of volume statistics, or -1 if statistics not active yet

◆ cs_lagr_stat_get_moment()

cs_field_t* cs_lagr_stat_get_moment ( int  stat_type,
cs_lagr_stat_group_t  stat_group,
cs_lagr_stat_moment_t  m_type,
int  class_id,
int  component_id 
)

Return field associated with a given Lagrangian statistic, given a statistics type (i.e. variable), group (particles or event), moment order, statistical class, and component id.

Parameters
[in]stat_typestatistics type
[in]stat_groupstatistics group (particle or event)
[in]m_typemoment type (mean or variance)
[in]class_idparticle statistical class
[in]component_idcomponent id, or -1 for all
Returns
pointer to the field associated to the corresponding moment

◆ cs_lagr_stat_get_moment_age()

cs_real_t cs_lagr_stat_get_moment_age ( cs_field_t f)

Return statistics age for a given moment.

Parameters
[in]ffield associated with given statistic
Returns
age of given statistic, or -1 if not active yet

◆ cs_lagr_stat_get_stat_weight()

cs_field_t* cs_lagr_stat_get_stat_weight ( int  class_id)

Return statistical weight.

Parameters
[in]class_idparticle statistical class
Returns
pointer to the field associated to the corresponding weight

◆ cs_lagr_stat_initialize()

void cs_lagr_stat_initialize ( void  )

Lagrangian statistics initialization.

Statistics activated or deactivated by previous calls to cs_lagr_stat_activate, cs_lagr_stat_deactivate, cs_lagr_stat_activate_attr, and cs_lagr_stat_deactivate_attr will be initialized here.

Restart info will be used after to fill in the moments structure

◆ cs_lagr_stat_is_active()

bool cs_lagr_stat_is_active ( cs_lagr_stat_group_t  group)

Indicate if a given statistics type has active statistics.

Parameters
[in]groupevent group to update
Returns
true if statistics are active for the given group

◆ cs_lagr_stat_log_iteration()

void cs_lagr_stat_log_iteration ( void  )

Log moment definition information for a given iteration.

◆ cs_lagr_stat_log_setup()

void cs_lagr_stat_log_setup ( void  )

Log moment definition setup information.

◆ cs_lagr_stat_map_cell_dt()

void cs_lagr_stat_map_cell_dt ( const cs_real_t dt)

Map time step values array for Lagrangian statistics.

If this function is not called, the field referenced by field pointer CS_F_(dt) will be used instead.

Parameters
[in]dtpointer to time step values array

◆ cs_lagr_stat_mesh_define()

int cs_lagr_stat_mesh_define ( const char *  name,
int  location_id,
cs_lagr_stat_group_t  stat_group,
int  class_id,
int  dim,
cs_lagr_moment_m_data_t data_func,
void *  data_input,
int  nt_start,
double  t_start 
)

Define mesh-based statistic based on particles or particle events.

This type of statistic is reinitialized and evaluated during each time step, but may be computed incrementally when based on particle events, so the associated data function must uptate the statistics without reinitializing them at each call.

As this type of statistic does not need to keep state between time steps, it is ignored by the lagragian statistics checkpoint/restart mechanism.

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_groupstatistics group (particle or event)
[in]class_idparticle class id, or 0 for all
[in]dimdimension associated with element data
[in]data_funcpointer to function to compute statistics
[in]data_inputassociated input
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
Returns
id of new moment in case of success, -1 in case of error.

◆ cs_lagr_stat_particle_define()

int cs_lagr_stat_particle_define ( const char *  name,
int  location_id,
int  stat_type,
cs_lagr_stat_moment_t  m_type,
int  class_id,
int  dim,
int  component_id,
cs_lagr_moment_p_data_t data_func,
void *  data_input,
cs_lagr_moment_p_data_t w_data_func,
void *  w_data_input,
int  nt_start,
double  t_start,
cs_lagr_stat_restart_t  restart_mode 
)

Define a particle-based statistic.

(DOXYGEN_SHOULD_SKIP_THIS)

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_typepredefined statistics type, or -1
[in]m_typemoment type
[in]class_idparticle class id, or 0 for all
[in]dimdimension associated with element data
[in]component_idattribute component id, or < 0 for all
[in]data_funcpointer to function to compute statistics (if stat_type < 0)
[in]data_inputassociated input
[in]w_data_funcpointer to function to compute weight (if NULL, statistic weight assumed)
[in]w_data_inputassociated input for w_data_func
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ cs_lagr_stat_prepare()

void cs_lagr_stat_prepare ( void  )

Prepare particle statistics for a given time step.

◆ cs_lagr_stat_restart_read()

void cs_lagr_stat_restart_read ( void  )

Read particle statistics restart info if needed.

◆ cs_lagr_stat_restart_write()

void cs_lagr_stat_restart_write ( cs_restart_t restart)

Checkpoint moment data.

Parameters
[in]restartassociated restart file pointer

◆ cs_lagr_stat_time_moment_define()

int cs_lagr_stat_time_moment_define ( const char *  name,
int  location_id,
int  stat_type,
cs_lagr_stat_moment_t  m_type,
int  class_id,
int  dim,
int  component_id,
cs_lagr_moment_m_data_t data_func,
void *  data_input,
int  nt_start,
double  t_start,
cs_lagr_stat_restart_t  restart_mode 
)

Define a time moment associated to particle statistics.

This is similar to general time moments (see cs_time_moment.c), with restart, logging, and unsteady reinitialization behavior aligned with other particle statistics.

Time moments must be based on values available at the end of each time step, so they cannot be based directly on events (though they can be based on fields defined through cs_lagr_stat_mesh_define, as the matching event-based fields will be updated first).

If dimension > 1, the val array is interleaved

Parameters
[in]namestatistics base name
[in]location_idid of associated mesh location
[in]stat_typepredefined statistics type, or -1
[in]m_typemoment type
[in]class_idparticle class id, or 0 for all
[in]dimdimension associated with element data
[in]component_idattribute component id, or < 0 for all
[in]data_funcpointer to function to compute statistics (if stat_type < 0)
[in]data_inputassociated input
[in]nt_startstarting time step (or -1 to use t_start, 0 to use idstnt)
[in]t_startstarting time
[in]restart_modebehavior in case of restart (reset, automatic, or strict)
Returns
id of new moment in case of success, -1 in case of error.

◆ cs_lagr_stat_type_by_name()

int cs_lagr_stat_type_by_name ( const char *  name)

Determine a basic statistic type by its base name.

Parameters
[in]nameparticle statistics base name (without class id)
Returns
matching stat type id, or -1 if not found

◆ cs_lagr_stat_type_from_attr_id()

int cs_lagr_stat_type_from_attr_id ( int  attr_id)

Return statistics type associated with a given particle attribute id.

Parameters
[in]attr_idparticle attribute id
Returns
associated particle statistics type id

◆ cs_lagr_stat_type_to_attr_id()

int cs_lagr_stat_type_to_attr_id ( int  stat_type)

Return attribute id associated with a given statistics type.

Parameters
[in]stat_typeparticle statistics type
Returns
attribute id, or -1 if not applicable

◆ cs_lagr_stat_update()

void cs_lagr_stat_update ( void  )

Update particle statistics for a given time step.

◆ cs_lagr_stat_update_event()

void cs_lagr_stat_update_event ( cs_lagr_event_set_t events,
cs_lagr_stat_group_t  group 
)

Update event-based moment accumulators.

Partial updates are allowed, so as to balance memory cost for storing events and repetition of mesh-location-based weigh updates.

Parameters
[in]eventspointer to event set
[in]groupevent group to update

Variable Documentation

◆ _base_stat_activate

char* _base_stat_activate = NULL
static

◆ _bdy_fouling_mass_flux_filter

int _bdy_fouling_mass_flux_filter[2] = {0, CS_EVENT_FOULING}
static

◆ _bdy_mass_flux_filter

int _bdy_mass_flux_filter[2]
static

◆ _bdy_resusp_mass_flux_filter

int _bdy_resusp_mass_flux_filter[2] = {0, CS_EVENT_RESUSPENSION}
static

◆ _is_active

bool _is_active[CS_LAGR_STAT_GROUP_N_GROUPS] = {false, false}
static

◆ _lagr_mesh_stats

cs_lagr_mesh_stat_t* _lagr_mesh_stats = NULL
static

◆ _lagr_moments

cs_lagr_moment_t* _lagr_moments = NULL
static

◆ _lagr_moments_wa

cs_lagr_moment_wa_t* _lagr_moments_wa = NULL
static

◆ _lagr_stat_names

const char* _lagr_stat_names[]
static
Initial value:
= {"particle_cumulative_weight",
"particle_volume_fraction",
"particle_events_weight",
"particle_resuspension_events_weight",
"particle_fouling_events_weight",
"particle_mass_flux",
"particle_resusp_mass_flux",
"particle_fouling_mass_flux",
"particle_impact_angle",
"particle_impact_velocity",
"particle_fouling_diameter",
"particle_fouling_coke_fraction"}

◆ _lagr_stat_options

cs_lagr_stat_options_t _lagr_stat_options
static
Initial value:
= {.isuist = 1,
.idstnt = 0,
.nstist = 0,
.threshold = 1e-12}

◆ _n_lagr_mesh_stats

int _n_lagr_mesh_stats = 0
static

◆ _n_lagr_mesh_stats_max

int _n_lagr_mesh_stats_max = 0
static

◆ _n_lagr_moments

int _n_lagr_moments = 0
static

◆ _n_lagr_moments_max

int _n_lagr_moments_max = 0
static

◆ _n_lagr_moments_wa

int _n_lagr_moments_wa = 0
static

◆ _n_lagr_moments_wa_max

int _n_lagr_moments_wa_max = 0
static

◆ _p_dt

const cs_real_t* _p_dt = NULL
static

◆ _restart_info

cs_lagr_moment_restart_info_t* _restart_info = NULL
static

◆ _restart_info_checked

bool _restart_info_checked = false
static

◆ _t_prev_iter

double _t_prev_iter = 0.
static

◆ cs_glob_lagr_stat_options

cs_lagr_stat_options_t* cs_glob_lagr_stat_options = &_lagr_stat_options

◆ cs_lagr_moment_type_name

const char* cs_lagr_moment_type_name[]
Initial value:
= {N_("MEAN"),
N_("VARIANCE")}
N_
#define N_(String)
Definition: cs_defs.h:56
CS_EVENT_INFLOW
#define CS_EVENT_INFLOW
Definition: cs_lagr_event.h:53
CS_EVENT_DEPOSITION
#define CS_EVENT_DEPOSITION
Definition: cs_lagr_event.h:62
CS_EVENT_OUTFLOW
#define CS_EVENT_OUTFLOW
Definition: cs_lagr_event.h:56
CS_EVENT_FOULING
#define CS_EVENT_FOULING
Definition: cs_lagr_event.h:74
CS_EVENT_RESUSPENSION
#define CS_EVENT_RESUSPENSION
Definition: cs_lagr_event.h:65