My Project
programmer's 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-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_defs.h"
39 
40 #include "cs_time_step.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /* Error codes */
51 
52 #define CS_RESTART_SUCCESS 0
53 #define CS_RESTART_ERR_FILE_NUM -1
54 #define CS_RESTART_ERR_LOCATION -2
55 #define CS_RESTART_ERR_VAL_TYPE -3
56 #define CS_RESTART_ERR_N_VALS -4
57 #define CS_RESTART_ERR_MODE -5
58 #define CS_RESTART_ERR_EXISTS -6
60 /*============================================================================
61  * Local type definitions
62  *============================================================================*/
63 
66 typedef enum {
67 
72 
73 /* Datatype enumeration to transmit a data's type to a function */
74 
75 typedef enum {
81 
82 /*
83  Pointer associated with a restart file structure. The structure itself
84  is defined in "cs_restart.c", and is opaque outside that unit.
85 */
86 
87 typedef struct _cs_restart_t cs_restart_t;
88 
89 /*----------------------------------------------------------------------------*/
109 /*----------------------------------------------------------------------------*/
110 
111 typedef int
113  void *context,
114  const char *sec_name,
115  int location_id,
116  int n_location_vals,
117  cs_restart_val_type_t val_type);
118 
119 /*----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------*/
140 
141 typedef int
143  void *context,
144  const char *sec_name,
145  int location_id,
146  int n_location_vals,
147  cs_restart_val_type_t val_type,
148  void *val);
149 
150 /*----------------------------------------------------------------------------*/
167 /*----------------------------------------------------------------------------*/
168 
169 typedef void
171  void *context,
172  const char *sec_name,
173  int location_id,
174  int n_location_vals,
175  cs_restart_val_type_t val_type,
176  const void *val);
177 
178 /*=============================================================================
179  * Global variables
180  *============================================================================*/
181 
182 /*============================================================================
183  * Public Fortran function prototypes
184  *============================================================================*/
185 
186 /*----------------------------------------------------------------------------
187  * Indicate if a restart directory is present.
188  *
189  * Fortran interface
190  *
191  * subroutine dflsui (ntsuit, ttsuit, wtsuit)
192  * *****************
193  *
194  * integer ntsuit : <-- : > 0: checkpoint time step interval
195  * : : 0: default interval
196  * : : -1: checkpoint at end
197  * : : -2: no checkpoint
198  * double precision ttsuit : <-- : if> 0, checkpoint time interval
199  * double precision wtsuit : <-- : if> 0, checkpoint wall time interval
200  *----------------------------------------------------------------------------*/
201 
202 void CS_PROCF (dflsui, DFLSUI)
203 (
204  cs_int_t *ntsuit,
207 );
208 
209 /*----------------------------------------------------------------------------
210  * Check if checkpointing is recommended at a given time.
211  *
212  * Fortran interface
213  *
214  * subroutine reqsui (iisuit)
215  * *****************
216  *
217  * integer iisuit : --> : 0 if no restart required, 1 otherwise
218  *----------------------------------------------------------------------------*/
219 
220 void CS_PROCF (reqsui, REQSUI)
221 (
222  cs_int_t *iisuit
223 );
224 
225 /*----------------------------------------------------------------------------
226  * Indicate checkpointing has been done at a given time.
227  *
228  * This updates the status for future checks to determine
229  * if checkpointing is recommended at a given time.
230  *
231  * Fortran interface
232  *
233  * subroutine stusui
234  * *****************
235  *----------------------------------------------------------------------------*/
236 
237 void CS_PROCF (stusui, STUSUI)
238 (
239  void
240 );
241 
242 /*----------------------------------------------------------------------------
243  * Save output mesh for turbomachinery if needed
244  *
245  * Fortran interface
246  *
247  * subroutine trbsui
248  * *****************
249  *----------------------------------------------------------------------------*/
250 
251 void CS_PROCF (trbsui, TRBSUI)
252 (
253  void
254 );
255 
256 /*----------------------------------------------------------------------------
257  * Indicate if a restart directory is present.
258  *
259  * Fortran interface
260  *
261  * subroutine indsui (isuite)
262  * *****************
263  *
264  * integer isuite : --> : 1 for restart, 0 otherwise
265  *----------------------------------------------------------------------------*/
266 
267 void CS_PROCF (indsui, INDSUI)
268 (
270 );
271 
272 /*============================================================================
273  * Public function prototypes
274  *============================================================================*/
275 
276 /*----------------------------------------------------------------------------*/
287 /*----------------------------------------------------------------------------*/
288 
289 void
290 cs_restart_checkpoint_set_defaults(int nt_interval,
291  double t_interval,
292  double wt_interval);
293 
294 /*----------------------------------------------------------------------------*/
312 /*----------------------------------------------------------------------------*/
313 
314 void
316 
317 /*----------------------------------------------------------------------------*/
323 /*----------------------------------------------------------------------------*/
324 
325 void
327 
328 /*----------------------------------------------------------------------------*/
334 /*----------------------------------------------------------------------------*/
335 
336 void
338 
339 /*----------------------------------------------------------------------------*/
345 /*----------------------------------------------------------------------------*/
346 
347 void
348 cs_restart_checkpoint_set_next_tv(double t_next);
349 
350 /*----------------------------------------------------------------------------*/
356 /*----------------------------------------------------------------------------*/
357 
358 void
359 cs_restart_checkpoint_set_next_wt(double wt_next);
360 
361 /*----------------------------------------------------------------------------*/
369 /*----------------------------------------------------------------------------*/
370 
371 bool
373 
374 /*----------------------------------------------------------------------------*/
383 /*----------------------------------------------------------------------------*/
384 
385 void
387 
388 /*----------------------------------------------------------------------------*/
394 /*----------------------------------------------------------------------------*/
395 
396 int
397 cs_restart_present(void);
398 
399 /*----------------------------------------------------------------------------*/
410 /*----------------------------------------------------------------------------*/
411 
412 cs_restart_t *
413 cs_restart_create(const char *name,
414  const char *path,
416 
417 /*----------------------------------------------------------------------------*/
423 /*----------------------------------------------------------------------------*/
424 
425 void
427 
428 /*----------------------------------------------------------------------------*/
442 /*----------------------------------------------------------------------------*/
443 
444 void
446  bool *match_cell,
447  bool *match_i_face,
448  bool *match_b_face,
449  bool *match_vertex);
450 
451 /*----------------------------------------------------------------------------*/
463 /*----------------------------------------------------------------------------*/
464 
465 int
467  const char *location_name,
468  cs_gnum_t n_glob_ents,
469  cs_lnum_t n_ents,
470  const cs_gnum_t *ent_global_num);
471 
472 /*----------------------------------------------------------------------------*/
483 /*----------------------------------------------------------------------------*/
484 
485 void
486 cs_restart_add_location_ref(const char *location_name,
487  cs_gnum_t n_glob_ents,
488  cs_lnum_t n_ents,
489  const cs_gnum_t *ent_global_num);
490 
491 /*----------------------------------------------------------------------------*/
495 /*----------------------------------------------------------------------------*/
496 
497 void
499 
500 /*----------------------------------------------------------------------------*/
514 /*----------------------------------------------------------------------------*/
515 
516 void
517 cs_restart_set_context(void *context);
518 
519 /*----------------------------------------------------------------------------*/
529 /*----------------------------------------------------------------------------*/
530 
533 
534 /*----------------------------------------------------------------------------*/
545 /*----------------------------------------------------------------------------*/
546 
549 
550 /*----------------------------------------------------------------------------*/
561 /*----------------------------------------------------------------------------*/
562 
565 
566 /*----------------------------------------------------------------------------*/
574 /*----------------------------------------------------------------------------*/
575 
576 const char *
577 cs_restart_get_name(const cs_restart_t *restart);
578 
579 /*----------------------------------------------------------------------------*/
589 /*----------------------------------------------------------------------------*/
590 
591 cs_lnum_t
593  int location_id);
594 
595 /*----------------------------------------------------------------------------*/
601 /*----------------------------------------------------------------------------*/
602 
603 void
604 cs_restart_dump_index(const cs_restart_t *restart);
605 
606 /*----------------------------------------------------------------------------*/
619 /*----------------------------------------------------------------------------*/
620 
621 int
623  const char *sec_name,
624  int location_id,
625  int n_location_vals,
626  cs_restart_val_type_t val_type);
627 
628 /*----------------------------------------------------------------------------*/
642 /*----------------------------------------------------------------------------*/
643 
644 int
646  const char *sec_name,
647  int location_id,
648  int n_location_vals,
649  cs_restart_val_type_t val_type,
650  void *val);
651 
652 /*----------------------------------------------------------------------------*/
663 /*----------------------------------------------------------------------------*/
664 
665 void
667  const char *sec_name,
668  int location_id,
669  int n_location_vals,
670  cs_restart_val_type_t val_type,
671  const void *val);
672 
673 /*----------------------------------------------------------------------------*/
685 /*----------------------------------------------------------------------------*/
686 
687 int
689  const char *name,
690  cs_lnum_t *n_particles);
691 
692 /*----------------------------------------------------------------------------*/
704 /*----------------------------------------------------------------------------*/
705 
706 int
708  int particles_location_id,
709  cs_lnum_t *particle_cell_id,
710  cs_real_t *particle_coords);
711 
712 /*----------------------------------------------------------------------------*/
732 /*----------------------------------------------------------------------------*/
733 
734 int
736  const char *name,
737  bool number_by_coords,
738  cs_lnum_t n_particles,
739  const cs_lnum_t *particle_cell_id,
740  const cs_real_t *particle_coords);
741 
742 /*----------------------------------------------------------------------------*/
764 /*----------------------------------------------------------------------------*/
765 
766 int
768  const char *sec_name,
769  int location_id,
770  int ref_location_id,
771  cs_lnum_t ref_id_base,
772  cs_lnum_t *ref_id);
773 
774 /*----------------------------------------------------------------------------*/
789 /*----------------------------------------------------------------------------*/
790 
791 void
793  const char *sec_name,
794  int location_id,
795  int ref_location_id,
796  cs_lnum_t ref_id_base,
797  const cs_lnum_t *ref_id);
798 
799 /*----------------------------------------------------------------------------*/
814 /*----------------------------------------------------------------------------*/
815 
816 int
818  const char *sec_name,
819  const char *old_name,
820  int location_id,
821  int n_location_vals,
822  cs_restart_val_type_t val_type,
823  void *val);
824 
825 /*----------------------------------------------------------------------------*/
844 /*----------------------------------------------------------------------------*/
845 
846 int
848  const char *sec_name,
849  const char *old_name_x,
850  const char *old_name_y,
851  const char *old_name_z,
852  int location_id,
853  cs_real_3_t *val);
854 
855 /*----------------------------------------------------------------------------*/
877 /*----------------------------------------------------------------------------*/
878 
879 int
881  const char *sec_name,
882  const char *old_name_xx,
883  const char *old_name_yy,
884  const char *old_name_zz,
885  const char *old_name_xy,
886  const char *old_name_yz,
887  const char *old_name_xz,
888  int location_id,
889  cs_real_6_t *val);
890 
891 /*----------------------------------------------------------------------------*/
913 /*----------------------------------------------------------------------------*/
914 
915 int
917  const char *sec_name,
918  const char *old_name_xx,
919  const char *old_name_yy,
920  const char *old_name_zz,
921  const char *old_name_xy,
922  const char *old_name_yz,
923  const char *old_name_xz,
924  int location_id,
925  cs_real_66_t *val);
926 
927 /*----------------------------------------------------------------------------*/
931 /*----------------------------------------------------------------------------*/
932 
933 void
935 
936 /*----------------------------------------------------------------------------*/
937 
939 
940 #endif /* __CS_RESTART_H__ */
CS_RESTART_MODE_READ
Definition: cs_restart.h:68
cs_restart_checkpoint_done
void cs_restart_checkpoint_done(const cs_time_step_t *ts)
Indicate checkpointing has been done at a given time.
Definition: cs_restart.c:1874
cs_defs.h
ttsuit
void cs_real_t * ttsuit
Definition: cs_restart.h:205
cs_restart_write_section_t
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:170
CS_TYPE_cs_int_t
Definition: cs_restart.h:77
optcal::isuite
integer, save isuite
Indicator of a calculation restart (=1) or not (=0). This value is set automatically by the code; dep...
Definition: optcal.f90:312
cs_restart_checkpoint_set_next_ts
void cs_restart_checkpoint_set_next_ts(int nt_next)
Define next forced checkpoint time step.
Definition: cs_restart.c:1761
cs_restart_read_real_66_t_compat
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:3588
cs_restart_destroy
void cs_restart_destroy(cs_restart_t **restart)
Destroy structure associated with a restart file (and close the file).
Definition: cs_restart.c:2059
cs_restart_read_real_6_t_compat
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:3446
cs_real_3_t
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:315
CS_PROCF
void CS_PROCF(dflsui, DFLSUI)(cs_int_t *ntsuit
cs_restart_set_check_section_func
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:2355
cs_restart_mode_t
cs_restart_mode_t
Definition: cs_restart.h:66
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_restart_val_type_t
cs_restart_val_type_t
Definition: cs_restart.h:75
cs_restart_add_location
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:2173
cs_restart_read_particles
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:2798
cs_restart_read_section
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:2532
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_restart_set_write_section_func
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:2399
cs_restart_read_ids
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:3050
cs_restart_set_context
void cs_restart_set_context(void *context)
Associate a context to restart section check operations.
Definition: cs_restart.c:2337
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_restart_get_n_location_elts
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:2438
cs_restart_present
int cs_restart_present(void)
Check if we have a restart directory.
Definition: cs_restart.c:1912
cs_restart_check_section
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:2499
CS_TYPE_cs_gnum_t
Definition: cs_restart.h:78
cs_restart_read_section_compat
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:3255
cs_restart_read_section_t
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:142
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
mode
void const cs_int_t * mode
Definition: cs_syr_coupling.h:132
cs_restart_write_section
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:2575
cs_time_step_t
time step descriptor
Definition: cs_time_step.h:51
wtsuit
void cs_real_t cs_real_t * wtsuit
Definition: cs_restart.h:205
cs_restart_write_particles
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:2915
cs_restart_get_name
const char * cs_restart_get_name(const cs_restart_t *restart)
Return name of restart file.
Definition: cs_restart.c:2418
cs_restart_dump_index
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:2460
cs_real_6_t
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:317
ts
void cs_int_t cs_int_t cs_int_t cs_real_t * ts
Definition: cs_at_plugin.h:63
cs_restart_checkpoint_set_mesh_mode
void cs_restart_checkpoint_set_mesh_mode(int mode)
Define checkpoint behavior for mesh.
Definition: cs_restart.c:1733
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_restart_t
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:87
CS_RESTART_MODE_WRITE
Definition: cs_restart.h:69
cs_restart_checkpoint_set_next_wt
void cs_restart_checkpoint_set_next_wt(double wt_next)
Define next forced checkpoint wall-clock time value.
Definition: cs_restart.c:1789
cs_restart_checkpoint_set_defaults
void cs_restart_checkpoint_set_defaults(int nt_interval, double t_interval, double wt_interval)
Define default checkpoint interval.
Definition: cs_restart.c:1703
cs_restart_print_stats
void cs_restart_print_stats(void)
Print statistics associated with restart files.
Definition: cs_restart.c:3711
cs_restart_read_particles_info
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:2615
cs_restart_check_section_t
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's presence.
Definition: cs_restart.h:112
cs_restart_write_ids
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:3153
cs_restart_read_real_3_t_compat
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:3332
cs_time_step.h
cs_restart_set_read_section_func
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:2377
cs_real_66_t
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:322
cs_restart_checkpoint_set_last_ts
void cs_restart_checkpoint_set_last_ts(int nt_last)
Define last forced checkpoint time step.
Definition: cs_restart.c:1747
cs_restart_checkpoint_required
bool cs_restart_checkpoint_required(const cs_time_step_t *ts)
Check if checkpointing is recommended at a given time.
Definition: cs_restart.c:1805
cs_int_t
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:301
cs_restart_check_base_location
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:2115
CS_TYPE_char
Definition: cs_restart.h:76
cs_restart_checkpoint_set_next_tv
void cs_restart_checkpoint_set_next_tv(double t_next)
Define next forced checkpoint time value.
Definition: cs_restart.c:1775
cs_restart_add_location_ref
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:2268
entsor::ntsuit
integer, save ntsuit
saving period of the restart filesy5
Definition: entsor.f90:72
cs_restart_clear_locations_ref
void cs_restart_clear_locations_ref(void)
Clear reference location definitions with a private copy.
Definition: cs_restart.c:2310
cs_restart_create
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:1936
CS_TYPE_cs_real_t
Definition: cs_restart.h:79