programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2014 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
90 (cs_time_moment_data_t) (const void *input,
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  * Return name of a given time moments in the restart file, if any
241  * (check also \ref cs_time_moment_n_moments_restart).
242  *
243  * parameters:
244  * restart_id <-- id of time moment in restart data
245  *
246  * returns:
247  * name of defined moment in restart file, or NULL
248  *----------------------------------------------------------------------------*/
249 
250 const char *
251 cs_time_moment_restart_name(int restart_id);
252 
253 /*----------------------------------------------------------------------------
254  * Return pointer to field associated with a given moment.
255  *
256  * For moments defined automatically to assist computation of higher
257  * order moments, which do not have an associated field, NULL is returned.
258  *
259  * parameters:
260  * moment_id <-- id of associated moment
261  *
262  * returns:
263  * pointer to field associated with given moment, or NULL
264  *----------------------------------------------------------------------------*/
265 
266 cs_field_t *
267 cs_time_moment_get_field(int moment_id);
268 
269 /*----------------------------------------------------------------------------
270  * Return 1 if moment is active, 0 if it is not active yet.
271  *
272  * parameters:
273  * moment_id <-- id of associated moment
274  *
275  * returns:
276  * 1 if moment is active, 0 if it is not active yet
277  *----------------------------------------------------------------------------*/
278 
279 int
280 cs_time_moment_is_active(int moment_id);
281 
282 /*----------------------------------------------------------------------------
283  * Update all moment accumulators.
284  ----------------------------------------------------------------------------*/
285 
286 void
288 
289 /*----------------------------------------------------------------------------
290  * Log moment definition setup information.
291  *----------------------------------------------------------------------------*/
292 
293 void
295 
296 /*----------------------------------------------------------------------------
297  * Log moment definition information for a given iteration.
298  *----------------------------------------------------------------------------*/
299 
300 void
302 
303 /*----------------------------------------------------------------------------
304  * Indicate if restart API should use "main" instead of "auxiliary" file.
305  *
306  * parameters:
307  * use_main <-- use "main" restart if nonzero, "auxiliary" otherwise
308  *----------------------------------------------------------------------------*/
309 
310 void
311 cs_time_moment_restart_use_main(int use_main);
312 
313 /*----------------------------------------------------------------------------
314  * Read restart moment data
315  *
316  * parameters:
317  * <-> restart associated restart file pointer
318  *----------------------------------------------------------------------------*/
319 
320 void
321 cs_time_moment_restart_read(cs_restart_t *restart);
322 
323 /*----------------------------------------------------------------------------
324  * Checkpoint moment data
325  *
326  * parameters:
327  * <-> restart associated restart file pointer
328  *----------------------------------------------------------------------------*/
329 
330 void
331 cs_time_moment_restart_write(cs_restart_t *restart);
332 
333 /*----------------------------------------------------------------------------*/
334 
336 
337 #endif /* __CS_TIME_MOMENT_H__ */
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:2129
void cs_time_moment_destroy_all(void)
Destroy all moments management metadata.
Definition: cs_time_moment.c:1836
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:2210
Field descriptor.
Definition: cs_field.h:98
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:1930
const char * cs_time_moment_type_name[]
int cs_time_moment_n_moments(void)
Return the number of defined time moments.
Definition: cs_time_moment.c:2090
#define BEGIN_C_DECLS
Definition: cs_defs.h:405
cs_time_moment_restart_t
Moment restart behavior.
Definition: cs_time_moment.h:65
void cs_time_moment_restart_write(cs_restart_t *restart)
Checkpoint moment data.
Definition: cs_time_moment.c:2840
void cs_time_moment_update_all(void)
Update all moment accumulators.
Definition: cs_time_moment.c:2222
void cs_time_moment_restart_read(cs_restart_t *restart)
Read restart moment data.
Definition: cs_time_moment.c:2765
cs_time_moment_type_t
Moment type.
Definition: cs_time_moment.h:56
Definition: cs_time_moment.h:58
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:2748
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:1871
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:2158
void cs_time_moment_log_iteration(void)
Log moment definition information for a given iteration.
Definition: cs_time_moment.c:2555
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:2104
void cs_time_moment_log_setup(void)
Log moment definition setup information.
Definition: cs_time_moment.c:2383
#define END_C_DECLS
Definition: cs_defs.h:406
double cs_real_t
Definition: cs_defs.h:296
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:2182
Definition: cs_time_moment.h:69
void( cs_time_moment_data_t)(const void *input, cs_real_t *vals)
Definition: cs_time_moment.h:90
Definition: cs_time_moment.h:68
Definition: cs_time_moment.h:59
Definition: cs_time_moment.h:67