9.2
general documentation
cs_time_moment.h
Go to the documentation of this file.
1#ifndef CS_TIME_MOMENT_H
2#define CS_TIME_MOMENT_H
3
4/*============================================================================
5 * Moments management
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Standard C library headers
32 *----------------------------------------------------------------------------*/
33
34/*----------------------------------------------------------------------------
35 * Local headers
36 *----------------------------------------------------------------------------*/
37
38#include "base/cs_base.h"
39#include "base/cs_field.h"
40#include "base/cs_restart.h"
41#include "base/cs_function.h"
42
43/*============================================================================
44 * Macro definitions
45 *============================================================================*/
46
47/*============================================================================
48 * Type definitions
49 *============================================================================*/
50
51/* Moment type */
52
54typedef enum {
55
61
62/* Moment restart behavior */
63
65typedef enum {
66
83
84/*----------------------------------------------------------------------------
85 * Function pointer for computation of data values for moments computation.
86 *
87 * If the matching values are multidimensional, they must be interleaved.
88 *
89 * Note: if the input pointer is non-null, it must point to valid data
90 * when the selection function is called, so either:
91 * - that value or structure should not be temporary (i.e. local);
92 * - when a single integer identifier is needed, the input pointer can be
93 * set to that value instead of an actual address;
94 *
95 * parameters:
96 * input <-- pointer to optional (untyped) value or structure.
97 * vals --> pointer to values (size: n_local elements*dimension)
98 *----------------------------------------------------------------------------*/
99
100typedef void
101(cs_time_moment_data_t) (const void *input,
102 cs_real_t *vals);
103
104/*=============================================================================
105 * Global variables
106 *============================================================================*/
107
108/* Names associated with moment types */
109
110extern const char *cs_time_moment_type_name[];
111
112/*============================================================================
113 * Public function prototypes
114 *============================================================================*/
115
116/*----------------------------------------------------------------------------
117 * Destroy all moments management metadata.
118 *----------------------------------------------------------------------------*/
119
120void
122
123/*----------------------------------------------------------------------------
124 * Map time step values array for temporal moments.
125 *
126 * If this function is not called, the field referenced by field pointer
127 * CS_F_(dt) will be used instead.
128 *----------------------------------------------------------------------------*/
129
130void
132
133/*----------------------------------------------------------------------------
134 * Update all moment accumulators.
135 *----------------------------------------------------------------------------*/
136
137void
139
140/*----------------------------------------------------------------------------
141 * Return 1 if a moment is active, 0 if it is not active yet.
142 *
143 * parameters:
144 * moment_id <-- id of associated moment
145 *
146 * returns:
147 * 0 in case of success, 1 if moment accumulation has not started yet
148 *----------------------------------------------------------------------------*/
149
150int
152
153/*----------------------------------------------------------------------------
154 * Define a moment of a product of existing field components
155 *
156 * Moments will involve the tensor products of their component fields,
157 * and only scalar, vector, or rank-2 tensors are handled (for
158 * post-processing output reasons), so a moment may not involve more than
159 * 2 vectors or 1 tensor, unless single components are specified.
160 *
161 * If of dimension > 1, the moment array is always interleaved.
162 *
163 * parameters:
164 * name <-- name of associated moment
165 * n_fields <-- number of associated fields
166 * field_id <-- ids of associated fields
167 * component_id <-- ids of matching field components (-1 for all)
168 * type <-- moment type
169 * nt_start <-- starting time step (or -1 to use t_start)
170 * t_start <-- starting time
171 * restart_mode <-- behavior in case of restart (reset, auto, or strict)
172 * restart_name <-- if non-null, previous name in case of restart
173 * ewa_time_scale <-- EWA time scale T (s); required (> 0) when type is
174 * CS_TIME_MOMENT_EWA, must be left unset (default -1)
175 * otherwise
176 *
177 * returns:
178 * id of new moment in case of success, -1 in case of error.
179 *----------------------------------------------------------------------------*/
180
181int
183 int n_fields,
184 const int field_id[],
185 const int component_id[],
187 int nt_start,
188 double t_start,
189 cs_time_moment_restart_t restart_mode,
190 const char *restart_name,
191 cs_real_t ewa_time_scale = -1.);
192
193/*----------------------------------------------------------------------------
194 * Define a time moment of an existing field.
195 *
196 * Moments will involve the tensor products of their component fields,
197 * and only scalar, vector, or rank-2 tensors are handled (for
198 * post-processing output reasons), so a 1st-order moment (i.e. mean) may
199 * involve a scalar, vector, or tensor, while a second-order moment
200 * (i.e. variance) may only involve a scalar or vector.
201 *
202 * parameters:
203 * name <-- name of associated moment
204 * f <-- pointer to associated field
205 * type <-- moment type
206 * nt_start <-- starting time step (or -1 to use t_start)
207 * t_start <-- starting time
208 * restart_mode <-- behavior in case of restart (reset, auto, or strict)
209 * restart_name <-- if non-null, previous name in case of restart
210 * ewa_time_scale <-- EWA time scale T (s); required (> 0) when type is
211 * CS_TIME_MOMENT_EWA, must be left unset (default -1)
212 * otherwise
213 *
214 * returns:
215 * id of new moment in case of success, -1 in case of error.
216 *----------------------------------------------------------------------------*/
217
218int
219cs_time_moment_define_by_field(const char *name,
220 const cs_field_t *f,
222 int nt_start,
223 double t_start,
224 cs_time_moment_restart_t restart_mode,
225 const char *restart_name,
226 cs_real_t ewa_time_scale = -1.);
227
228/*----------------------------------------------------------------------------
229 * Define a time moment based on an evaluation function.
230 *
231 * Moments will involve the tensor products of their component fields,
232 * and only scalar, vector, or rank-2 tensors are handled (for
233 * post-processing output reasons), so a 1st-order moment (i.e. mean) may
234 * involve a scalar, vector, or tensor, while a second-order moment
235 * (i.e. variance) may only involve a scalar or vector.
236 *
237 * parameters:
238 * name <-- name of associated moment
239 * f <-- pointer to function object
240 * type <-- moment type
241 * nt_start <-- starting time step (or -1 to use t_start)
242 * t_start <-- starting time
243 * restart_mode <-- behavior in case of restart (reset, auto, or strict)
244 * restart_name <-- if non-null, previous name in case of restart
245 * ewa_time_scale <-- EWA time scale T (s); required (> 0) when type is
246 * CS_TIME_MOMENT_EWA, must be left unset (default -1)
247 * otherwise
248 *
249 * returns:
250 * id of new moment in case of success, -1 in case of error.
251 *----------------------------------------------------------------------------*/
252
253int
254cs_time_moment_define_by_function(const char *name,
255 cs_function_t *f,
257 int nt_start,
258 double t_start,
259 cs_time_moment_restart_t restart_mode,
260 const char *restart_name,
261 cs_real_t ewa_time_scale = -1.);
262
263/*----------------------------------------------------------------------------
264 * Define a moment whose data values will be computed using a
265 * specified function.
266 *
267 * If of dimension > 1, the moment array is always interleaved.
268 *
269 * parameters:
270 * name <-- name of associated moment
271 * location_id <-- id of associated mesh location
272 * dim <-- dimension associated with element data
273 * is_intensive <-- is the time moment intensive?
274 * data_func <-- function used to define data values
275 * data_input <-- pointer to optional (untyped) value or structure
276 * to be used by data_func
277 * weight_func <-- function used to define weight values
278 * weight_input <-- pointer to optional (untyped) value or structure
279 * to be used by weight_func
280 * type <-- moment type
281 * nt_start <-- starting time step (or -1 to use t_start)
282 * t_start <-- starting time
283 * restart_mode <-- behavior in case of restart (reset, auto, or strict)
284 * restart_name <-- if non-null, previous name in case of restart
285 * ewa_time_scale <-- EWA time scale T (s); required (> 0) when type is
286 * CS_TIME_MOMENT_EWA, must be left unset (default -1)
287 * otherwise
288 *
289 * returns:
290 * id of new moment in case of success, -1 in case of error.
291 *----------------------------------------------------------------------------*/
292
293int
294cs_time_moment_define_by_func(const char *name,
295 int location_id,
296 int dim,
297 bool is_intensive,
298 cs_time_moment_data_t *data_func,
299 const void *data_input,
300 cs_time_moment_data_t *w_data_func,
301 void *w_data_input,
303 int nt_start,
304 double t_start,
305 cs_time_moment_restart_t restart_mode,
306 const char *restart_name,
307 cs_real_t ewa_time_scale = -1.);
308
309/*----------------------------------------------------------------------------
310 * Return the number of defined time moments.
311 *
312 * returns:
313 * number of defined time moments
314 *----------------------------------------------------------------------------*/
315
316int
318
319/*----------------------------------------------------------------------------
320 * Return the number of time moments in the restart file, if any
321 *
322 * returns:
323 * number of defined moments in restart file, or 0
324 *----------------------------------------------------------------------------*/
325
326int
328
329/*----------------------------------------------------------------------------
330 * Define a moment restart mode and name by an id.
331 *
332 * This is a utility function, to allow simplification of automatic setups.
333 * It must be called just before defining a moment to work properly if
334 * restart_id < -1 (automatic mode).
335 *
336 * parameters:
337 * restart_id <-- -2: automatic, -1: reset, >= 0: id of
338 * matching moment in restart data
339 * restart_mode --> matching restart mode
340 * restart_name --> matching restart name
341 *----------------------------------------------------------------------------*/
342
343void
345 cs_time_moment_restart_t *restart_mode,
346 const char **restart_name);
347
348/*----------------------------------------------------------------------------
349 * Return name of a given time moments in the restart file, if any
350 * (check also \ref cs_time_moment_n_moments_restart).
351 *
352 * parameters:
353 * restart_id <-- id of time moment in restart data
354 *
355 * returns:
356 * name of defined moment in restart file, or null
357 *----------------------------------------------------------------------------*/
358
359const char *
360cs_time_moment_restart_name(int restart_id);
361
362/*----------------------------------------------------------------------------
363 * Return pointer to field associated with a given moment.
364 *
365 * For moments defined automatically to assist computation of higher order
366 * moments, which do not have an associated field, a null pointer is returned.
367 *
368 * parameters:
369 * moment_id <-- id of associated moment
370 *
371 * returns:
372 * pointer to field associated with given moment, or null
373 *----------------------------------------------------------------------------*/
374
377
378/*----------------------------------------------------------------------------
379 * Return 1 if moment is active, 0 if it is not active yet.
380 *
381 * parameters:
382 * moment_id <-- id of associated moment
383 *
384 * returns:
385 * 1 if moment is active, 0 if it is not active yet
386 *----------------------------------------------------------------------------*/
387
388int
390
391/*----------------------------------------------------------------------------*/
392/*
393 * \brief Reset selected time step for starting time step of selected moment.
394 *
395 * All other time moments sharing the same start time will also start
396 * at the same time step.
397 *
398 * \param[in] moment_id id of associated moment, or -1 for all
399 * \param[in] nt_start starting time step
400 */
401/*----------------------------------------------------------------------------*/
402
403void
405 int nt_start);
406
407/*----------------------------------------------------------------------------*/
408/*
409 * \brief Reset selected time step for starting time step of selected moment.
410 *
411 * All other time moments sharing the same start time will also start
412 * at the same time step.
413 *
414 * \param[in] moment_id id of associated moment, or -1 for all
415 * \param[in] nt_start starting time value
416 */
417/*----------------------------------------------------------------------------*/
418
419void
421 double t_start);
422
423/*----------------------------------------------------------------------------*/
424/*
425 * \brief Set current iteration as starting time step of selected moment.
426 *
427 * All other time moments sharing the same start time should also be reset.
428 *
429 * \param[in] moment_id id of associated moment, or -1 for all.
430 */
431/*----------------------------------------------------------------------------*/
432
433void
435
436/*----------------------------------------------------------------------------
437 * Update all moment accumulators.
438 ----------------------------------------------------------------------------*/
439
440void
442
443/*----------------------------------------------------------------------------
444 * Log moment definition setup information.
445 *----------------------------------------------------------------------------*/
446
447void
449
450/*----------------------------------------------------------------------------
451 * Log moment definition information for a given iteration.
452 *----------------------------------------------------------------------------*/
453
454void
456
457/*----------------------------------------------------------------------------
458 * Indicate if restart API should use "main" instead of "auxiliary" file.
459 *
460 * parameters:
461 * use_main <-- use "main" restart if nonzero, "auxiliary" otherwise
462 *----------------------------------------------------------------------------*/
463
464void
466
467/*----------------------------------------------------------------------------
468 * Read restart moment data
469 *
470 * parameters:
471 * <-> restart associated restart file pointer
472 *----------------------------------------------------------------------------*/
473
474void
476
477/*----------------------------------------------------------------------------
478 * Checkpoint moment data
479 *
480 * parameters:
481 * <-> restart associated restart file pointer
482 *----------------------------------------------------------------------------*/
483
484void
486
487/*----------------------------------------------------------------------------*/
488
489#endif /* CS_TIME_MOMENT_H */
Field descriptor.
Definition: cs_field.h:275
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
@ dt
Definition: cs_field_pointer.h:61
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:91
void cs_time_moment_set_start_time(int moment_id, int nt_start)
Reset selected time step for starting time step of selected moment.
Definition: cs_time_moment.cpp:2045
void cs_time_moment_restart_use_main(int use_main)
Indicate if restart API should use "main" instead of "auxiliary" file.
Definition: cs_time_moment.cpp:2829
void cs_time_moment_destroy_all(void)
Destroy all moments management metadata.
Definition: cs_time_moment.cpp:1660
void cs_time_moment_restart_read(cs_restart_t *restart)
Read restart moment data.
Definition: cs_time_moment.cpp:2846
int cs_time_moment_define_by_function(const char *name, cs_function_t *f, cs_time_moment_type_t type, int nt_start, double t_start, cs_time_moment_restart_t restart_mode, const char *restart_name, cs_real_t ewa_time_scale=-1.)
Define a time moment based on an evaluation function.
Definition: cs_time_moment.cpp:1817
void cs_time_moment_log_setup(void)
Log moment definition setup information.
Definition: cs_time_moment.cpp:2462
void cs_time_moment_restart_options_by_id(int restart_id, cs_time_moment_restart_t *restart_mode, const char **restart_name)
Define a moment restart mode and name by an id.
Definition: cs_time_moment.cpp:1960
int cs_time_moment_n_moments(void)
Return the number of defined time moments.
Definition: cs_time_moment.cpp:1917
int cs_time_moment_define_by_field_ids(const char *name, int n_fields, const int field_id[], const int component_id[], cs_time_moment_type_t type, int nt_start, double t_start, cs_time_moment_restart_t restart_mode, const char *restart_name, cs_real_t ewa_time_scale=-1.)
Define a moment of a product of existing fields components.
Definition: cs_time_moment.cpp:1695
void() cs_time_moment_data_t(const void *input, cs_real_t *vals)
Definition: cs_time_moment.h:101
void cs_time_moment_log_iteration(void)
Log moment definition information for a given iteration.
Definition: cs_time_moment.cpp:2634
cs_field_t * cs_time_moment_get_field(int moment_id)
Return pointer to field associated with a given moment.
Definition: cs_time_moment.cpp:2019
int cs_time_moment_n_moments_restart(void)
Return the number of time moments in the restart file, if any.
Definition: cs_time_moment.cpp:1931
const char * cs_time_moment_type_name[]
Definition: cs_time_moment.cpp:220
int cs_time_moment_define_by_func(const char *name, int location_id, int dim, bool is_intensive, cs_time_moment_data_t *data_func, const void *data_input, cs_time_moment_data_t *w_data_func, void *w_data_input, cs_time_moment_type_t type, int nt_start, double t_start, cs_time_moment_restart_t restart_mode, const char *restart_name, cs_real_t ewa_time_scale=-1.)
Define a moment whose data values will be computed using a specified function.
Definition: cs_time_moment.cpp:1874
int cs_time_moment_define_by_field(const char *name, const cs_field_t *f, cs_time_moment_type_t type, int nt_start, double t_start, cs_time_moment_restart_t restart_mode, const char *restart_name, cs_real_t ewa_time_scale=-1.)
Define a time moment of an existing field.
Definition: cs_time_moment.cpp:1756
cs_time_moment_restart_t
Definition: cs_time_moment.h:65
@ CS_TIME_MOMENT_RESTART_AUTO
Definition: cs_time_moment.h:70
@ CS_TIME_MOMENT_RESTART_RESET
Definition: cs_time_moment.h:67
@ CS_TIME_MOMENT_RESTART_EXACT
Definition: cs_time_moment.h:76
cs_time_moment_type_t
Definition: cs_time_moment.h:54
@ CS_TIME_MOMENT_VARIANCE
Definition: cs_time_moment.h:57
@ CS_TIME_MOMENT_MEAN
Definition: cs_time_moment.h:56
@ CS_TIME_MOMENT_EWA
Definition: cs_time_moment.h:58
void cs_time_moment_restart_write(cs_restart_t *restart)
Checkpoint moment data.
Definition: cs_time_moment.cpp:2917
int cs_time_moment_is_active(int moment_id)
Return 1 if moment is active, 0 if it is not active yet.
Definition: cs_time_moment.cpp:2081
const char * cs_time_moment_restart_name(int restart_id)
Return name of a given time moments in the restart file, if any (check also cs_time_moment_n_moments_...
Definition: cs_time_moment.cpp:1990
void cs_time_moment_map_cell_dt(const cs_real_t *dt)
Map time step values for temporal moments.
Definition: cs_time_moment.cpp:2188
void cs_time_moment_reset(int moment_id)
Set current iteration as starting time step of selected moment.
Definition: cs_time_moment.cpp:2108
void cs_time_moment_update_all(void)
Update all moment accumulators.
Definition: cs_time_moment.cpp:2200
int moment_id
Definition: keywords.h:91
Definition: cs_function.h:117