My Project
programmer's 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-2019 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 "cs_base.h"
39 #include "cs_field.h"
40 #include "cs_restart.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*============================================================================
51  * Type definitions
52  *============================================================================*/
53 
54 /* Moment type */
55 
56 typedef enum {
57 
60 
62 
63 /* Moment restart behavior */
64 
65 typedef enum {
66 
70 
72 
73 /*----------------------------------------------------------------------------
74  * Function pointer for computation of data values for moments computation.
75  *
76  * If the matching values are multidimensional, they must be interleaved.
77  *
78  * Note: if the input pointer is non-NULL, it must point to valid data
79  * when the selection function is called, so either:
80  * - that value or structure should not be temporary (i.e. local);
81  * - post-processing output must be ensured using cs_post_write_meshes()
82  * with a fixed-mesh writer before the data pointed to goes out of scope;
83  *
84  * parameters:
85  * input <-- pointer to optional (untyped) value or structure.
86  * vals --> pointer to values (size: n_local elements*dimension)
87  *----------------------------------------------------------------------------*/
88 
89 typedef void
91  cs_real_t *vals);
92 
93 /*=============================================================================
94  * Global variables
95  *============================================================================*/
96 
97 /* Names associated with moment types */
98 
99 extern const char *cs_time_moment_type_name[];
100 
101 /*============================================================================
102  * Public function prototypes
103  *============================================================================*/
104 
105 /*----------------------------------------------------------------------------
106  * Destroy all moments management metadata.
107  *----------------------------------------------------------------------------*/
108 
109 void
111 
112 /*----------------------------------------------------------------------------
113  * Map time step values array for temporal moments.
114  *
115  * If this function is not called, the field referenced by field pointer
116  * CS_F_(dt) will be used instead.
117  *----------------------------------------------------------------------------*/
118 
119 void
121 
122 /*----------------------------------------------------------------------------
123  * Update all moment accumulators.
124  *----------------------------------------------------------------------------*/
125 
126 void
128 
129 /*----------------------------------------------------------------------------
130  * Return 1 if a moment is active, 0 if it is not active yet.
131  *
132  * parameters:
133  * moment_id <-- id of associated moment
134  *
135  * returns:
136  * 0 in case of success, 1 if moment accumulation has not started yet
137  *----------------------------------------------------------------------------*/
138 
139 int
140 cs_time_moment_is_active(int moment_id);
141 
142 /*----------------------------------------------------------------------------*/
168 int
169 cs_time_moment_define_by_field_ids(const char *name,
170  int n_fields,
171  const int field_id[],
172  const int component_id[],
174  int nt_start,
175  double t_start,
176  cs_time_moment_restart_t restart_mode,
177  const char *restart_name);
178 
179 /*----------------------------------------------------------------------------
180  * Define a moment whose data values will be computed using a
181  * specified function.
182  *
183  * If of dimension > 1, the moment array is always interleaved.
184  *
185  * parameters:
186  * name <-- name of associated moment
187  * location_id <-- id of associated mesh location
188  * dim <-- dimension associated with element data
189  * data_func <-- function used to define data values
190  * data_input <-- pointer to optional (untyped) value or structure
191  * to be used by data_func
192  * weight_func <-- function used to define weight values
193  * weight_input <-- pointer to optional (untyped) value or structure
194  * to be used by weight_func
195  * type <-- moment type
196  * nt_start <-- starting time step (or -1 to use t_start)
197  * t_start <-- starting time
198  * restart_mode <-- behavior in case of restart (reset, auto, or strict)
199  * restart_name <-- if not NULL, previous name in case of restart
200  *
201  * returns:
202  * id of new moment in case of success, -1 in case of error.
203  *----------------------------------------------------------------------------*/
204 
205 int
206 cs_time_moment_define_by_func(const char *name,
207  int location_id,
208  int dim,
209  cs_time_moment_data_t *data_func,
210  const void *data_input,
211  cs_time_moment_data_t *w_data_func,
212  void *w_data_input,
214  int nt_start,
215  double t_start,
216  cs_time_moment_restart_t restart_mode,
217  const char *restart_name);
218 
219 /*----------------------------------------------------------------------------
220  * Return the number of defined time moments.
221  *
222  * returns:
223  * number of defined time moments
224  *----------------------------------------------------------------------------*/
225 
226 int
228 
229 /*----------------------------------------------------------------------------
230  * Return the number of time moments in the restart file, if any
231  *
232  * returns:
233  * number of defined moments in restart file, or 0
234  *----------------------------------------------------------------------------*/
235 
236 int
238 
239 /*----------------------------------------------------------------------------
240  * Define a moment restart mode and name by an id.
241  *
242  * This is a utility function, to allow simplification of automatic setups.
243  * It must be called just before defining a moment to work properly if
244  * restart_id < -1 (automatic mode).
245  *
246  * parameters:
247  * restart_id <-- -2: automatic, -1: reset, >= 0: id of
248  * matching moment in restart data
249  * restart_mode --> matching restart mode
250  * restart_name --> matching restart name
251  *----------------------------------------------------------------------------*/
252 
253 void
255  cs_time_moment_restart_t *restart_mode,
256  const char **restart_name);
257 
258 /*----------------------------------------------------------------------------
259  * Return name of a given time moments in the restart file, if any
260  * (check also \ref cs_time_moment_n_moments_restart).
261  *
262  * parameters:
263  * restart_id <-- id of time moment in restart data
264  *
265  * returns:
266  * name of defined moment in restart file, or NULL
267  *----------------------------------------------------------------------------*/
268 
269 const char *
270 cs_time_moment_restart_name(int restart_id);
271 
272 /*----------------------------------------------------------------------------
273  * Return pointer to field associated with a given moment.
274  *
275  * For moments defined automatically to assist computation of higher
276  * order moments, which do not have an associated field, NULL is returned.
277  *
278  * parameters:
279  * moment_id <-- id of associated moment
280  *
281  * returns:
282  * pointer to field associated with given moment, or NULL
283  *----------------------------------------------------------------------------*/
284 
285 cs_field_t *
286 cs_time_moment_get_field(int moment_id);
287 
288 /*----------------------------------------------------------------------------
289  * Return 1 if moment is active, 0 if it is not active yet.
290  *
291  * parameters:
292  * moment_id <-- id of associated moment
293  *
294  * returns:
295  * 1 if moment is active, 0 if it is not active yet
296  *----------------------------------------------------------------------------*/
297 
298 int
299 cs_time_moment_is_active(int moment_id);
300 
301 /*----------------------------------------------------------------------------*/
307 /*----------------------------------------------------------------------------*/
308 
309 void
310 cs_time_moment_reset(int moment_id);
311 
312 /*----------------------------------------------------------------------------
313  * Update all moment accumulators.
314  ----------------------------------------------------------------------------*/
315 
316 void
318 
319 /*----------------------------------------------------------------------------
320  * Log moment definition setup information.
321  *----------------------------------------------------------------------------*/
322 
323 void
325 
326 /*----------------------------------------------------------------------------
327  * Log moment definition information for a given iteration.
328  *----------------------------------------------------------------------------*/
329 
330 void
332 
333 /*----------------------------------------------------------------------------
334  * Indicate if restart API should use "main" instead of "auxiliary" file.
335  *
336  * parameters:
337  * use_main <-- use "main" restart if nonzero, "auxiliary" otherwise
338  *----------------------------------------------------------------------------*/
339 
340 void
341 cs_time_moment_restart_use_main(int use_main);
342 
343 /*----------------------------------------------------------------------------
344  * Read restart moment data
345  *
346  * parameters:
347  * <-> restart associated restart file pointer
348  *----------------------------------------------------------------------------*/
349 
350 void
352 
353 /*----------------------------------------------------------------------------
354  * Checkpoint moment data
355  *
356  * parameters:
357  * <-> restart associated restart file pointer
358  *----------------------------------------------------------------------------*/
359 
360 void
362 
363 /*----------------------------------------------------------------------------*/
364 
366 
367 #endif /* __CS_TIME_MOMENT_H__ */
cs_time_moment_type_t
cs_time_moment_type_t
Moment type.
Definition: cs_time_moment.h:56
input
static int input(void)
cs_time_moment_restart_options_by_id
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.c:1783
CS_TIME_MOMENT_VARIANCE
Definition: cs_time_moment.h:59
cs_time_moment_restart_use_main
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.c:2542
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
CS_TIME_MOMENT_RESTART_EXACT
Definition: cs_time_moment.h:69
cs_time_moment_log_iteration
void cs_time_moment_log_iteration(void)
Log moment definition information for a given iteration.
Definition: cs_time_moment.c:2349
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_time_moment_restart_t
cs_time_moment_restart_t
Moment restart behavior.
Definition: cs_time_moment.h:65
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_time_moment_type_name
const char * cs_time_moment_type_name[]
Definition: cs_time_moment.c:241
cs_time_moment_restart_write
void cs_time_moment_restart_write(cs_restart_t *restart)
Checkpoint moment data.
Definition: cs_time_moment.c:2627
cs_time_moment_restart_read
void cs_time_moment_restart_read(cs_restart_t *restart)
Read restart moment data.
Definition: cs_time_moment.c:2559
cs_time_moment_log_setup
void cs_time_moment_log_setup(void)
Log moment definition setup information.
Definition: cs_time_moment.c:2177
CS_TIME_MOMENT_MEAN
Definition: cs_time_moment.h:58
cs_time_moment_restart_name
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.c:1813
CS_TIME_MOMENT_RESTART_AUTO
Definition: cs_time_moment.h:68
cs_time_moment_is_active
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.c:1866
cs_time_moment_map_cell_dt
void cs_time_moment_map_cell_dt(const cs_real_t *dt)
Map time step values array for temporal moments.
Definition: cs_time_moment.c:1960
cs_field.h
cs_time_moment_update_all
void cs_time_moment_update_all(void)
Update all moment accumulators.
Definition: cs_time_moment.c:1972
cs_restart_t
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:87
cs_time_moment_data_t
void() cs_time_moment_data_t(const void *input, cs_real_t *vals)
Definition: cs_time_moment.h:90
cs_time_moment_define_by_func
int cs_time_moment_define_by_func(const char *name, int location_id, int dim, 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)
Define a moment whose data values will be computed using a specified function.
Definition: cs_time_moment.c:1577
cs_time_moment_n_moments
int cs_time_moment_n_moments(void)
Return the number of defined time moments.
Definition: cs_time_moment.c:1740
cs_time_moment_get_field
cs_field_t * cs_time_moment_get_field(int moment_id)
Return pointer to field associated with a given moment.
Definition: cs_time_moment.c:1842
dt
Definition: cs_field_pointer.h:65
CS_TIME_MOMENT_RESTART_RESET
Definition: cs_time_moment.h:67
cs_restart.h
cs_time_moment_reset
void cs_time_moment_reset(int moment_id)
Reset a time moment.
Definition: cs_time_moment.c:1891
cs_field_t
Field descriptor.
Definition: cs_field.h:124
cs_time_moment_destroy_all
void cs_time_moment_destroy_all(void)
Destroy all moments management metadata.
Definition: cs_time_moment.c:1485
cs_time_moment_define_by_field_ids
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)
Define a moment of a product of existing field components.
Definition: cs_time_moment.c:1520
type
void const cs_int_t * type
Definition: cs_measures_util.h:425
cs_base.h
cs_time_moment_n_moments_restart
int cs_time_moment_n_moments_restart(void)
Return the number of time moments in the restart file, if any.
Definition: cs_time_moment.c:1754