7.3
general documentation
cs_restart.h
Go to the documentation of this file.
1 #ifndef __CS_RESTART_H__
2 #define __CS_RESTART_H__
3 
4 /*============================================================================
5  * Manage checkpoint / restart files
6  *============================================================================*/
7 
8 /*
9  This file is part of code_saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2022 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_defs.h"
39 
40 #include "cs_time_step.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /* Predefined checkpoint interval */
51 
52 #define CS_RESTART_INTERVAL_NONE -2
53 #define CS_RESTART_INTERVAL_ONLY_AT_END -1
54 #define CS_RESTART_INTERVAL_DEFAULT 0
55 
56 /* Error codes */
57 
58 #define CS_RESTART_SUCCESS 0
59 #define CS_RESTART_ERR_FILE_NUM -1
60 #define CS_RESTART_ERR_LOCATION -2
61 #define CS_RESTART_ERR_VAL_TYPE -3
62 #define CS_RESTART_ERR_N_VALS -4
63 #define CS_RESTART_ERR_MODE -5
64 #define CS_RESTART_ERR_EXISTS -6
65 #define CS_RESTART_ERR_NO_MAP -7
68 /*============================================================================
69  * Local type definitions
70  *============================================================================*/
71 
74 typedef enum {
75 
80 
81 /* Datatype enumeration to transmit a data's type to a function */
82 
83 typedef enum {
89 
90 /*
91  Pointer associated with a restart file structure. The structure itself
92  is defined in "cs_restart.c", and is opaque outside that unit.
93 */
94 
95 typedef struct _cs_restart_t cs_restart_t;
96 
97 /*----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------*/
118 
119 typedef int
121  void *context,
122  const char *sec_name,
123  int location_id,
124  int n_location_vals,
125  cs_restart_val_type_t val_type);
126 
127 /*----------------------------------------------------------------------------*/
147 /*----------------------------------------------------------------------------*/
148 
149 typedef int
151  void *context,
152  const char *sec_name,
153  int location_id,
154  int n_location_vals,
155  cs_restart_val_type_t val_type,
156  void *val);
157 
158 /*----------------------------------------------------------------------------*/
175 /*----------------------------------------------------------------------------*/
176 
177 typedef void
179  void *context,
180  const char *sec_name,
181  int location_id,
182  int n_location_vals,
183  cs_restart_val_type_t val_type,
184  const void *val);
185 
186 /*=============================================================================
187  * Global variables
188  *============================================================================*/
189 
190 /*============================================================================
191  * Public Fortran function prototypes
192  *============================================================================*/
193 
194 /*----------------------------------------------------------------------------
195  * Indicate if a restart directory is present.
196  *
197  * Fortran interface
198  *
199  * subroutine dflsui (ntsuit, ttsuit, wtsuit)
200  * *****************
201  *
202  * integer ntsuit : <-- : > 0: checkpoint time step interval
203  * : : 0: default interval
204  * : : -1: checkpoint at end
205  * : : -2: no checkpoint
206  * double precision ttsuit : <-- : if> 0, checkpoint time interval
207  * double precision wtsuit : <-- : if> 0, checkpoint wall time interval
208  *----------------------------------------------------------------------------*/
209 
210 void CS_PROCF (dflsui, DFLSUI)
211 (
212  int *ntsuit,
213  cs_real_t *ttsuit,
214  cs_real_t *wtsuit
215 );
216 
217 /*----------------------------------------------------------------------------
218  * Check if checkpointing is recommended at a given time.
219  *
220  * Fortran interface
221  *
222  * subroutine reqsui (iisuit)
223  * *****************
224  *
225  * integer iisuit : --> : 0 if no restart required, 1 otherwise
226  *----------------------------------------------------------------------------*/
227 
228 void CS_PROCF (reqsui, REQSUI)
229 (
230  int *iisuit
231 );
232 
233 /*----------------------------------------------------------------------------
234  * Indicate checkpointing has been done at a given time.
235  *
236  * This updates the status for future checks to determine
237  * if checkpointing is recommended at a given time.
238  *
239  * Fortran interface
240  *
241  * subroutine stusui
242  * *****************
243  *----------------------------------------------------------------------------*/
244 
245 void CS_PROCF (stusui, STUSUI)
246 (
247  void
248 );
249 
250 /*----------------------------------------------------------------------------
251  * Save output mesh for turbomachinery if needed
252  *
253  * Fortran interface
254  *
255  * subroutine trbsui
256  * *****************
257  *----------------------------------------------------------------------------*/
258 
259 void CS_PROCF (trbsui, TRBSUI)
260 (
261  void
262 );
263 
264 /*----------------------------------------------------------------------------
265  * Indicate if a restart directory is present.
266  *
267  * Fortran interface
268  *
269  * subroutine indsui (isuite)
270  * *****************
271  *
272  * integer isuite : --> : 1 for restart, 0 otherwise
273  *----------------------------------------------------------------------------*/
274 
275 void CS_PROCF (indsui, INDSUI)
276 (
277  int *isuite
278 );
279 
280 /*============================================================================
281  * Public function prototypes
282  *============================================================================*/
283 
284 /*----------------------------------------------------------------------------*/
295 /*----------------------------------------------------------------------------*/
296 
297 void
298 cs_restart_checkpoint_set_defaults(int nt_interval,
299  double t_interval,
300  double wt_interval);
301 
302 /*----------------------------------------------------------------------------*/
320 /*----------------------------------------------------------------------------*/
321 
322 void
324 
325 /*----------------------------------------------------------------------------*/
331 /*----------------------------------------------------------------------------*/
332 
333 void
335 
336 /*----------------------------------------------------------------------------*/
342 /*----------------------------------------------------------------------------*/
343 
344 void
346 
347 /*----------------------------------------------------------------------------*/
353 /*----------------------------------------------------------------------------*/
354 
355 void
356 cs_restart_checkpoint_set_next_tv(double t_next);
357 
358 /*----------------------------------------------------------------------------*/
364 /*----------------------------------------------------------------------------*/
365 
366 void
367 cs_restart_checkpoint_set_next_wt(double wt_next);
368 
369 /*----------------------------------------------------------------------------*/
377 /*----------------------------------------------------------------------------*/
378 
379 bool
381 
382 /*----------------------------------------------------------------------------*/
391 /*----------------------------------------------------------------------------*/
392 
393 void
395 
396 /*----------------------------------------------------------------------------*/
402 /*----------------------------------------------------------------------------*/
403 
404 int
405 cs_restart_present(void);
406 
407 /*----------------------------------------------------------------------------*/
418 /*----------------------------------------------------------------------------*/
419 
420 cs_restart_t *
421 cs_restart_create(const char *name,
422  const char *path,
423  cs_restart_mode_t mode);
424 
425 /*----------------------------------------------------------------------------*/
431 /*----------------------------------------------------------------------------*/
432 
433 void
435 
436 /*----------------------------------------------------------------------------*/
450 /*----------------------------------------------------------------------------*/
451 
452 void
454  bool *match_cell,
455  bool *match_i_face,
456  bool *match_b_face,
457  bool *match_vertex);
458 
459 /*----------------------------------------------------------------------------*/
471 /*----------------------------------------------------------------------------*/
472 
473 int
475  const char *location_name,
476  cs_gnum_t n_glob_ents,
477  cs_lnum_t n_ents,
478  const cs_gnum_t *ent_global_num);
479 
480 /*----------------------------------------------------------------------------*/
491 /*----------------------------------------------------------------------------*/
492 
493 void
494 cs_restart_add_location_ref(const char *location_name,
495  cs_gnum_t n_glob_ents,
496  cs_lnum_t n_ents,
497  const cs_gnum_t *ent_global_num);
498 
499 /*----------------------------------------------------------------------------*/
503 /*----------------------------------------------------------------------------*/
504 
505 void
507 
508 /*----------------------------------------------------------------------------*/
522 /*----------------------------------------------------------------------------*/
523 
524 void
525 cs_restart_set_context(void *context);
526 
527 /*----------------------------------------------------------------------------*/
537 /*----------------------------------------------------------------------------*/
538 
541 
542 /*----------------------------------------------------------------------------*/
553 /*----------------------------------------------------------------------------*/
554 
557 
558 /*----------------------------------------------------------------------------*/
569 /*----------------------------------------------------------------------------*/
570 
573 
574 /*----------------------------------------------------------------------------*/
582 /*----------------------------------------------------------------------------*/
583 
584 const char *
585 cs_restart_get_name(const cs_restart_t *restart);
586 
587 /*----------------------------------------------------------------------------*/
597 /*----------------------------------------------------------------------------*/
598 
599 cs_lnum_t
601  int location_id);
602 
603 /*----------------------------------------------------------------------------*/
609 /*----------------------------------------------------------------------------*/
610 
611 void
612 cs_restart_dump_index(const cs_restart_t *restart);
613 
614 /*----------------------------------------------------------------------------*/
627 /*----------------------------------------------------------------------------*/
628 
629 int
631  const char *sec_name,
632  int location_id,
633  int n_location_vals,
634  cs_restart_val_type_t val_type);
635 
636 /*----------------------------------------------------------------------------*/
650 /*----------------------------------------------------------------------------*/
651 
652 int
654  const char *sec_name,
655  int location_id,
656  int n_location_vals,
657  cs_restart_val_type_t val_type,
658  void *val);
659 
660 /*----------------------------------------------------------------------------*/
671 /*----------------------------------------------------------------------------*/
672 
673 void
675  const char *sec_name,
676  int location_id,
677  int n_location_vals,
678  cs_restart_val_type_t val_type,
679  const void *val);
680 
681 /*----------------------------------------------------------------------------*/
693 /*----------------------------------------------------------------------------*/
694 
695 int
697  const char *name,
698  cs_lnum_t *n_particles);
699 
700 /*----------------------------------------------------------------------------*/
712 /*----------------------------------------------------------------------------*/
713 
714 int
716  int particles_location_id,
717  cs_lnum_t *particle_cell_id,
718  cs_real_t *particle_coords);
719 
720 /*----------------------------------------------------------------------------*/
740 /*----------------------------------------------------------------------------*/
741 
742 int
744  const char *name,
745  bool number_by_coords,
746  cs_lnum_t n_particles,
747  const cs_lnum_t *particle_cell_id,
748  const cs_real_t *particle_coords);
749 
750 /*----------------------------------------------------------------------------*/
772 /*----------------------------------------------------------------------------*/
773 
774 int
776  const char *sec_name,
777  int location_id,
778  int ref_location_id,
779  cs_lnum_t ref_id_base,
780  cs_lnum_t *ref_id);
781 
782 /*----------------------------------------------------------------------------*/
797 /*----------------------------------------------------------------------------*/
798 
799 void
801  const char *sec_name,
802  int location_id,
803  int ref_location_id,
804  cs_lnum_t ref_id_base,
805  const cs_lnum_t *ref_id);
806 
807 /*----------------------------------------------------------------------------*/
823 /*----------------------------------------------------------------------------*/
824 
825 int
827  const char *sec_name,
828  const char *old_name,
829  int location_id,
830  int n_location_vals,
831  cs_restart_val_type_t val_type,
832  void *val);
833 
834 /*----------------------------------------------------------------------------*/
853 /*----------------------------------------------------------------------------*/
854 
855 int
857  const char *sec_name,
858  const char *old_name_x,
859  const char *old_name_y,
860  const char *old_name_z,
861  int location_id,
862  cs_real_3_t *val);
863 
864 /*----------------------------------------------------------------------------*/
886 /*----------------------------------------------------------------------------*/
887 
888 int
890  const char *sec_name,
891  const char *old_name_xx,
892  const char *old_name_yy,
893  const char *old_name_zz,
894  const char *old_name_xy,
895  const char *old_name_yz,
896  const char *old_name_xz,
897  int location_id,
898  cs_real_6_t *val);
899 
900 /*----------------------------------------------------------------------------*/
922 /*----------------------------------------------------------------------------*/
923 
924 int
926  const char *sec_name,
927  const char *old_name_xx,
928  const char *old_name_yy,
929  const char *old_name_zz,
930  const char *old_name_xy,
931  const char *old_name_yz,
932  const char *old_name_xz,
933  int location_id,
934  cs_real_66_t *val);
935 
936 /*----------------------------------------------------------------------------*/
940 /*----------------------------------------------------------------------------*/
941 
942 void
944 
945 /*----------------------------------------------------------------------------*/
951 /*----------------------------------------------------------------------------*/
952 
953 int
955 
956 /*----------------------------------------------------------------------------*/
962 /*----------------------------------------------------------------------------*/
963 
964 int
966 
967 /*----------------------------------------------------------------------------*/
980 /*----------------------------------------------------------------------------*/
981 
982 void
983 cs_restart_set_n_max_checkpoints(int n_checkpoints);
984 
985 /*----------------------------------------------------------------------------*/
989 /*----------------------------------------------------------------------------*/
990 
991 void
993 
994 /*----------------------------------------------------------------------------*/
998 /*----------------------------------------------------------------------------*/
999 
1000 void
1002 
1003 /*----------------------------------------------------------------------------*/
1004 
1006 
1007 #endif /* __CS_RESTART_H__ */
Definition: cs_restart.h:88
int cs_restart_read_section(cs_restart_t *restart, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type, void *val)
Read a section from a restart file.
Definition: cs_restart.c:2791
time step descriptor
Definition: cs_time_step.h:64
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:301
cs_restart_write_section_t * cs_restart_set_write_section_func(cs_restart_write_section_t *func)
Associate a function and its input to all restart section write operations.
Definition: cs_restart.c:2658
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:337
int cs_restart_write_particles(cs_restart_t *restart, const char *name, bool number_by_coords, cs_lnum_t n_particles, const cs_lnum_t *particle_cell_id, const cs_real_t *particle_coords)
Write basic particles information to a restart file.
Definition: cs_restart.c:3178
void cs_restart_dump_index(const cs_restart_t *restart)
Print the index associated with a restart file in read mode.
Definition: cs_restart.c:2719
void cs_restart_checkpoint_done(const cs_time_step_t *ts)
Indicate checkpointing has been done at a given time.
Definition: cs_restart.c:2055
void cs_restart_clear_locations_ref(void)
Clear reference location definitions with a private copy.
Definition: cs_restart.c:2569
void cs_restart_checkpoint_set_defaults(int nt_interval, double t_interval, double wt_interval)
Define default checkpoint interval.
Definition: cs_restart.c:1881
void cs_restart_print_stats(void)
Print statistics associated with restart files.
Definition: cs_restart.c:3975
cs_restart_t * cs_restart_create(const char *name, const char *path, cs_restart_mode_t mode)
Initialize a restart file.
Definition: cs_restart.c:2123
integer, save ntsuit
saving period of the restart files
Definition: entsor.f90:52
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:345
#define BEGIN_C_DECLS
Definition: cs_defs.h:512
void cs_restart_write_section(cs_restart_t *restart, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type, const void *val)
Write a section to a restart file.
Definition: cs_restart.c:2834
cs_restart_check_section_t * cs_restart_set_check_section_func(cs_restart_check_section_t *func)
Associate a function to restart section check operations.
Definition: cs_restart.c:2614
cs_restart_mode_t
Definition: cs_restart.h:75
const char * cs_restart_get_name(const cs_restart_t *restart)
Return name of restart file.
Definition: cs_restart.c:2677
Definition: cs_restart.h:85
void cs_restart_add_location_ref(const char *location_name, cs_gnum_t n_glob_ents, cs_lnum_t n_ents, const cs_gnum_t *ent_global_num)
Add a reference location definition with a private copy.
Definition: cs_restart.c:2527
int cs_restart_read_section_compat(cs_restart_t *restart, const char *sec_name, const char *old_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type, void *val)
Read a section from a restart file, when that section may have used a different name in a previous ve...
Definition: cs_restart.c:3519
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
integer, save isuite
Indicator of a calculation restart (=1) or not (=0). This value is set automatically by the code; dep...
Definition: optcal.f90:229
void cs_restart_set_n_max_checkpoints(int n_checkpoints)
Set the number of checkpoint files to keep.
Definition: cs_restart.c:4051
int cs_restart_read_real_3_t_compat(cs_restart_t *restart, const char *sec_name, const char *old_name_x, const char *old_name_y, const char *old_name_z, int location_id, cs_real_3_t *val)
Read a cs_real_3_t vector section from a restart file, when that section may have used a different na...
Definition: cs_restart.c:3596
void reqsui(int *iisuit)
Definition: cs_restart.c:1797
int cs_restart_read_real_66_t_compat(cs_restart_t *restart, const char *sec_name, const char *old_name_xx, const char *old_name_yy, const char *old_name_zz, const char *old_name_xy, const char *old_name_yz, const char *old_name_xz, int location_id, cs_real_66_t *val)
Read a cs_real_66_t tensor section from a restart file, when that section may have used a different n...
Definition: cs_restart.c:3852
void cs_restart_checkpoint_set_last_ts(int nt_last)
Define last forced checkpoint time step.
Definition: cs_restart.c:1925
bool cs_restart_checkpoint_required(const cs_time_step_t *ts)
Check if checkpointing is recommended at a given time.
Definition: cs_restart.c:1983
cs_restart_read_section_t * cs_restart_set_read_section_func(cs_restart_read_section_t *func)
Associate a function and its input to all restart section read operations.
Definition: cs_restart.c:2636
int cs_restart_present(void)
Check if we have a restart directory.
Definition: cs_restart.c:2094
Definition: cs_restart.h:87
void() cs_restart_write_section_t(cs_restart_t *restart, void *context, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type, const void *val)
Function pointer for modifying behavior when writing a section.
Definition: cs_restart.h:179
int cs_restart_check_if_restart_from_ncfd(cs_restart_t *r)
Checks if restart is done from a NCFD checkpoint file.
Definition: cs_restart.c:3998
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:96
void stusui(void)
Definition: cs_restart.c:1820
void cs_restart_checkpoint_set_next_ts(int nt_next)
Define next forced checkpoint time step.
Definition: cs_restart.c:1939
int cs_restart_read_particles_info(cs_restart_t *restart, const char *name, cs_lnum_t *n_particles)
Read basic particles information from a restart file.
Definition: cs_restart.c:2874
int cs_restart_read_ids(cs_restart_t *restart, const char *sec_name, int location_id, int ref_location_id, cs_lnum_t ref_id_base, cs_lnum_t *ref_id)
Read a referenced location id section from a restart file.
Definition: cs_restart.c:3313
int cs_restart_read_real_6_t_compat(cs_restart_t *restart, const char *sec_name, const char *old_name_xx, const char *old_name_yy, const char *old_name_zz, const char *old_name_xy, const char *old_name_yz, const char *old_name_xz, int location_id, cs_real_6_t *val)
Read a cs_real_6_t tensor section from a restart file, when that section may have used a different na...
Definition: cs_restart.c:3710
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:335
int cs_restart_check_section(cs_restart_t *restart, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type)
Check the presence of a given section in a restart file.
Definition: cs_restart.c:2758
void cs_restart_clean_multiwriters_history(void)
Remove all previous checkpoints which are not to be retained.
Definition: cs_restart.c:4073
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
Definition: cs_restart.h:78
void indsui(int *isuite)
Definition: cs_restart.c:1856
void cs_restart_checkpoint_set_next_wt(double wt_next)
Define next forced checkpoint wall-clock time value.
Definition: cs_restart.c:1967
cs_restart_val_type_t
Definition: cs_restart.h:84
#define END_C_DECLS
Definition: cs_defs.h:513
int cs_restart_is_from_ncfd(void)
Returns if restart is done from a NCFD checkpoint file.
Definition: cs_restart.c:4027
void cs_restart_checkpoint_set_next_tv(double t_next)
Define next forced checkpoint time value.
Definition: cs_restart.c:1953
int cs_restart_read_particles(cs_restart_t *restart, int particles_location_id, cs_lnum_t *particle_cell_id, cs_real_t *particle_coords)
Read basic particles information from a restart file.
Definition: cs_restart.c:3061
void trbsui(void)
Definition: cs_restart.c:1837
#define CS_PROCF(x, y)
Definition: cs_defs.h:526
Definition: cs_restart.h:86
void dflsui(int *ntsuit, cs_real_t *ttsuit, cs_real_t *wtsuit)
Definition: cs_restart.c:1776
void cs_restart_set_context(void *context)
Associate a context to restart section check operations.
Definition: cs_restart.c:2596
cs_lnum_t cs_restart_get_n_location_elts(const cs_restart_t *restart, int location_id)
Return local number of elements associated with a given restart location.
Definition: cs_restart.c:2697
void cs_restart_destroy(cs_restart_t **restart)
Destroy structure associated with a restart file (and close the file).
Definition: cs_restart.c:2318
void cs_restart_check_base_location(const cs_restart_t *restart, bool *match_cell, bool *match_i_face, bool *match_b_face, bool *match_vertex)
Check the locations associated with a restart file.
Definition: cs_restart.c:2374
void cs_restart_multiwriters_destroy_all(void)
Destroy the multiwriter structure at the end of the computation.
Definition: cs_restart.c:4132
void cs_restart_checkpoint_set_mesh_mode(int mode)
Define checkpoint behavior for mesh.
Definition: cs_restart.c:1911
Definition: cs_restart.h:77
int cs_restart_add_location(cs_restart_t *restart, const char *location_name, cs_gnum_t n_glob_ents, cs_lnum_t n_ents, const cs_gnum_t *ent_global_num)
Add a location definition.
Definition: cs_restart.c:2432
int() cs_restart_check_section_t(cs_restart_t *restart, void *context, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type)
Function pointer for modifying behavior when checking a section&#39;s presence.
Definition: cs_restart.h:121
void cs_restart_write_ids(cs_restart_t *restart, const char *sec_name, int location_id, int ref_location_id, cs_lnum_t ref_id_base, const cs_lnum_t *ref_id)
Write a referenced location id section to a restart file.
Definition: cs_restart.c:3416
int() cs_restart_read_section_t(cs_restart_t *restart, void *context, const char *sec_name, int location_id, int n_location_vals, cs_restart_val_type_t val_type, void *val)
Function pointer for modifying behavior when reading a section.
Definition: cs_restart.h:151