8.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-2024 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
74typedef enum {
75
80
81/* Datatype enumeration to transmit a data's type to a function */
82
83typedef 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
95typedef struct _cs_restart_t cs_restart_t;
96
97/*----------------------------------------------------------------------------*/
117/*----------------------------------------------------------------------------*/
118
119typedef 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
149typedef 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
177typedef 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 function prototypes
192 *============================================================================*/
193
194/*----------------------------------------------------------------------------*/
208/*----------------------------------------------------------------------------*/
209
210void
212 double *t_interval,
213 double *wt_interval);
214
215/*----------------------------------------------------------------------------*/
226/*----------------------------------------------------------------------------*/
227
228void
230 double t_interval,
231 double wt_interval);
232
233/*----------------------------------------------------------------------------*/
251/*----------------------------------------------------------------------------*/
252
253void
255
256/*----------------------------------------------------------------------------*/
262/*----------------------------------------------------------------------------*/
263
264void
266
267/*----------------------------------------------------------------------------*/
273/*----------------------------------------------------------------------------*/
274
275void
277
278/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285
286void
288
289/*----------------------------------------------------------------------------*/
295/*----------------------------------------------------------------------------*/
296
297void
299
300/*----------------------------------------------------------------------------*/
308/*----------------------------------------------------------------------------*/
309
310bool
312
313/*----------------------------------------------------------------------------*/
322/*----------------------------------------------------------------------------*/
323
324void
326
327/*----------------------------------------------------------------------------*/
328/*
329 * \brief Access raw restart data serialized in memory.
330 *
331 * If called previously, reinitialize memory data structure.
332 *
333 * \param[out] nb size of data
334 * \param[out] data pointer to data
335 */
336/*----------------------------------------------------------------------------*/
337
338void
340 void **data);
341
342/*----------------------------------------------------------------------------*/
343/*
344 * \brief Indicate restart will be done based on a serialized data in memory.
345 *
346 * The restart subsystem takes ownership of the given data
347 *
348 * \param[in] nb number of matching bytes for data
349 * \param[in] data data buffer (ownership is relinquished by caller)
350 */
351/*----------------------------------------------------------------------------*/
352
353void
355 void *data);
356
357/*----------------------------------------------------------------------------*/
358/*
359 * \brief Indicate checkpoint will be done to serialized data in memory.
360 *
361 * If called previously, reinitialize memory data structure.
362 *
363 * \param[in] status checkpoint to memory if true, to file otherwise.
364 */
365/*----------------------------------------------------------------------------*/
366
367void
369
370/*----------------------------------------------------------------------------*/
376/*----------------------------------------------------------------------------*/
377
378int
380
381/*----------------------------------------------------------------------------*/
392/*----------------------------------------------------------------------------*/
393
395cs_restart_create(const char *name,
396 const char *path,
397 cs_restart_mode_t mode);
398
399/*----------------------------------------------------------------------------*/
405/*----------------------------------------------------------------------------*/
406
407void
409
410/*----------------------------------------------------------------------------*/
424/*----------------------------------------------------------------------------*/
425
426void
428 bool *match_cell,
429 bool *match_i_face,
430 bool *match_b_face,
431 bool *match_vertex);
432
433/*----------------------------------------------------------------------------*/
445/*----------------------------------------------------------------------------*/
446
447int
449 const char *location_name,
450 cs_gnum_t n_glob_ents,
451 cs_lnum_t n_ents,
452 const cs_gnum_t *ent_global_num);
453
454/*----------------------------------------------------------------------------*/
465/*----------------------------------------------------------------------------*/
466
467void
468cs_restart_add_location_ref(const char *location_name,
469 cs_gnum_t n_glob_ents,
470 cs_lnum_t n_ents,
471 const cs_gnum_t *ent_global_num);
472
473/*----------------------------------------------------------------------------*/
477/*----------------------------------------------------------------------------*/
478
479void
481
482/*----------------------------------------------------------------------------*/
496/*----------------------------------------------------------------------------*/
497
498void
499cs_restart_set_context(void *context);
500
501/*----------------------------------------------------------------------------*/
511/*----------------------------------------------------------------------------*/
512
515
516/*----------------------------------------------------------------------------*/
527/*----------------------------------------------------------------------------*/
528
531
532/*----------------------------------------------------------------------------*/
543/*----------------------------------------------------------------------------*/
544
547
548/*----------------------------------------------------------------------------*/
556/*----------------------------------------------------------------------------*/
557
558const char *
559cs_restart_get_name(const cs_restart_t *restart);
560
561/*----------------------------------------------------------------------------*/
571/*----------------------------------------------------------------------------*/
572
575 int location_id);
576
577/*----------------------------------------------------------------------------*/
583/*----------------------------------------------------------------------------*/
584
585void
586cs_restart_dump_index(const cs_restart_t *restart);
587
588/*----------------------------------------------------------------------------*/
601/*----------------------------------------------------------------------------*/
602
603int
605 const char *sec_name,
606 int location_id,
607 int n_location_vals,
608 cs_restart_val_type_t val_type);
609
610/*----------------------------------------------------------------------------*/
624/*----------------------------------------------------------------------------*/
625
626int
628 const char *sec_name,
629 int location_id,
630 int n_location_vals,
631 cs_restart_val_type_t val_type,
632 void *val);
633
634/*----------------------------------------------------------------------------*/
645/*----------------------------------------------------------------------------*/
646
647void
649 const char *sec_name,
650 int location_id,
651 int n_location_vals,
652 cs_restart_val_type_t val_type,
653 const void *val);
654
655/*----------------------------------------------------------------------------*/
667/*----------------------------------------------------------------------------*/
668
669int
671 const char *name,
672 cs_lnum_t *n_particles);
673
674/*----------------------------------------------------------------------------*/
686/*----------------------------------------------------------------------------*/
687
688int
690 int particles_location_id,
691 cs_lnum_t *particle_cell_id,
692 cs_real_t *particle_coords);
693
694/*----------------------------------------------------------------------------*/
714/*----------------------------------------------------------------------------*/
715
716int
718 const char *name,
719 bool number_by_coords,
720 cs_lnum_t n_particles,
721 const cs_lnum_t *particle_cell_id,
722 const cs_real_t *particle_coords);
723
724/*----------------------------------------------------------------------------*/
746/*----------------------------------------------------------------------------*/
747
748int
750 const char *sec_name,
751 int location_id,
752 int ref_location_id,
753 cs_lnum_t ref_id_base,
754 cs_lnum_t *ref_id);
755
756/*----------------------------------------------------------------------------*/
771/*----------------------------------------------------------------------------*/
772
773void
775 const char *sec_name,
776 int location_id,
777 int ref_location_id,
778 cs_lnum_t ref_id_base,
779 const cs_lnum_t *ref_id);
780
781/*----------------------------------------------------------------------------*/
797/*----------------------------------------------------------------------------*/
798
799int
801 const char *sec_name,
802 const char *old_name,
803 int location_id,
804 int n_location_vals,
805 cs_restart_val_type_t val_type,
806 void *val);
807
808/*----------------------------------------------------------------------------*/
827/*----------------------------------------------------------------------------*/
828
829int
831 const char *sec_name,
832 const char *old_name_x,
833 const char *old_name_y,
834 const char *old_name_z,
835 int location_id,
836 cs_real_3_t *val);
837
838/*----------------------------------------------------------------------------*/
860/*----------------------------------------------------------------------------*/
861
862int
864 const char *sec_name,
865 const char *old_name_xx,
866 const char *old_name_yy,
867 const char *old_name_zz,
868 const char *old_name_xy,
869 const char *old_name_yz,
870 const char *old_name_xz,
871 int location_id,
872 cs_real_6_t *val);
873
874/*----------------------------------------------------------------------------*/
896/*----------------------------------------------------------------------------*/
897
898int
900 const char *sec_name,
901 const char *old_name_xx,
902 const char *old_name_yy,
903 const char *old_name_zz,
904 const char *old_name_xy,
905 const char *old_name_yz,
906 const char *old_name_xz,
907 int location_id,
908 cs_real_66_t *val);
909
910/*----------------------------------------------------------------------------*/
914/*----------------------------------------------------------------------------*/
915
916void
918
919/*----------------------------------------------------------------------------*/
923/*----------------------------------------------------------------------------*/
924
925void
927
928/*----------------------------------------------------------------------------*/
934/*----------------------------------------------------------------------------*/
935
936int
938
939/*----------------------------------------------------------------------------*/
945/*----------------------------------------------------------------------------*/
946
947int
949
950/*----------------------------------------------------------------------------*/
963/*----------------------------------------------------------------------------*/
964
965void
966cs_restart_set_n_max_checkpoints(int n_checkpoints);
967
968/*----------------------------------------------------------------------------*/
972/*----------------------------------------------------------------------------*/
973
974void
976
977/*----------------------------------------------------------------------------*/
981/*----------------------------------------------------------------------------*/
982
983void
985
986/*----------------------------------------------------------------------------*/
987
989
990#endif /* __CS_RESTART_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:369
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:359
uint64_t cs_gnum_t
global mesh entity number
Definition: cs_defs.h:325
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:361
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
int cs_restart_is_from_ncfd(void)
Returns if restart is done from a NCFD checkpoint file.
Definition: cs_restart.cpp:4164
cs_restart_mode_t
Definition: cs_restart.h:74
@ CS_RESTART_MODE_WRITE
Definition: cs_restart.h:77
@ CS_RESTART_MODE_READ
Definition: cs_restart.h:76
void cs_checkpoint_set_to_memory_serialized(bool status)
Indicate checkpoint will be done to serialized data in memory.
Definition: cs_restart.cpp:2116
cs_restart_val_type_t
Definition: cs_restart.h:83
@ CS_TYPE_int
Definition: cs_restart.h:85
@ CS_TYPE_cs_gnum_t
Definition: cs_restart.h:86
@ CS_TYPE_cs_real_t
Definition: cs_restart.h:87
@ CS_TYPE_char
Definition: cs_restart.h:84
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.cpp:3806
bool cs_restart_checkpoint_required(const cs_time_step_t *ts)
Check if checkpointing is recommended at a given time.
Definition: cs_restart.cpp:1929
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.cpp:2793
void cs_restart_checkpoint_get_intervals(int *nt_interval, double *t_interval, double *wt_interval)
Query checkpoint intervals.
Definition: cs_restart.cpp:1801
const char * cs_restart_get_name(const cs_restart_t *restart)
Return name of restart file.
Definition: cs_restart.cpp:2773
void cs_restart_set_context(void *context)
Associate a context to restart section check operations.
Definition: cs_restart.cpp:2692
int cs_restart_present(void)
Check if we have a restart directory.
Definition: cs_restart.cpp:2168
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.cpp:2470
void cs_restart_clear_locations_ref(void)
Clear reference location definitions with a private copy.
Definition: cs_restart.cpp:2665
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:95
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.cpp:4135
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:150
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.cpp:2854
void cs_restart_checkpoint_set_last_ts(int nt_last)
Define last forced checkpoint time step.
Definition: cs_restart.cpp:1871
void cs_restart_checkpoint_set_next_wt(double wt_next)
Define next forced checkpoint wall-clock time value.
Definition: cs_restart.cpp:1913
void cs_restart_log_setup(void)
Log checkpoint/restart setup.
Definition: cs_restart.cpp:4071
cs_restart_t * cs_restart_create(const char *name, const char *path, cs_restart_mode_t mode)
Initialize a restart file.
Definition: cs_restart.cpp:2198
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.cpp:2710
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.cpp:2732
void cs_restart_set_n_max_checkpoints(int n_checkpoints)
Set the number of checkpoint files to keep.
Definition: cs_restart.cpp:4188
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.cpp:2754
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:120
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.cpp:3692
void cs_restart_set_from_memory_serialized(size_t nb, void *data)
Indicate restart will be done based on a serialized data in memory.
Definition: cs_restart.cpp:2066
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:178
void cs_restart_checkpoint_set_next_tv(double t_next)
Define next forced checkpoint time value.
Definition: cs_restart.cpp:1899
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.cpp:2930
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.cpp:2970
void cs_restart_destroy(cs_restart_t **restart)
Destroy structure associated with a restart file (and close the file).
Definition: cs_restart.cpp:2412
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.cpp:3512
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.cpp:3948
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.cpp:3615
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.cpp:2528
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.cpp:3157
void cs_restart_multiwriters_destroy_all(void)
Destroy the multiwriter structure at the end of the computation.
Definition: cs_restart.cpp:4269
void cs_restart_dump_index(const cs_restart_t *restart)
Print the index associated with a restart file in read mode.
Definition: cs_restart.cpp:2815
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.cpp:2887
void cs_restart_clean_multiwriters_history(void)
Remove all previous checkpoints which are not to be retained.
Definition: cs_restart.cpp:4210
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.cpp:2623
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.cpp:3274
void cs_restart_checkpoint_set_interval(int nt_interval, double t_interval, double wt_interval)
Define default checkpoint interval.
Definition: cs_restart.cpp:1827
void cs_restart_get_from_memory_serialized(size_t *nb, void **data)
Definition: cs_restart.cpp:2043
void cs_restart_checkpoint_set_mesh_mode(int mode)
Define checkpoint behavior for mesh.
Definition: cs_restart.cpp:1857
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.cpp:3409
void cs_restart_checkpoint_done(const cs_time_step_t *ts)
Indicate checkpointing has been done at a given time.
Definition: cs_restart.cpp:2001
void cs_restart_print_stats(void)
Print statistics associated with restart files.
Definition: cs_restart.cpp:4112
void cs_restart_checkpoint_set_next_ts(int nt_next)
Define next forced checkpoint time step.
Definition: cs_restart.cpp:1885
time step descriptor
Definition: cs_time_step.h:64