9.2
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-2026 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 "base/cs_defs.h"
39
40#include "base/cs_time_step.h"
41
42/*============================================================================
43 * Macro definitions
44 *============================================================================*/
45
46/* Predefined checkpoint interval */
47
48#define CS_RESTART_INTERVAL_NONE -2
49#define CS_RESTART_INTERVAL_ONLY_AT_END -1
50#define CS_RESTART_INTERVAL_DEFAULT 0
51
52/* Error codes */
53
54#define CS_RESTART_SUCCESS 0
55#define CS_RESTART_ERR_FILE_NUM -1
56#define CS_RESTART_ERR_LOCATION -2
57#define CS_RESTART_ERR_VAL_TYPE -3
58#define CS_RESTART_ERR_N_VALS -4
59#define CS_RESTART_ERR_MODE -5
60#define CS_RESTART_ERR_EXISTS -6
61#define CS_RESTART_ERR_NO_MAP -7
64/*============================================================================
65 * Local type definitions
66 *============================================================================*/
67
70typedef enum {
71
76
77/* Datatype enumeration to transmit a data's type to a function */
78
79typedef enum {
85
86/*
87 Pointer associated with a restart file structure. The structure itself
88 is defined in "cs_restart.c", and is opaque outside that unit.
89*/
90
91typedef struct _cs_restart_t cs_restart_t;
92
93/*----------------------------------------------------------------------------*/
113/*----------------------------------------------------------------------------*/
114
115typedef int
117 void *context,
118 const char *sec_name,
119 int location_id,
120 int n_location_vals,
121 cs_restart_val_type_t val_type);
122
123/*----------------------------------------------------------------------------*/
143/*----------------------------------------------------------------------------*/
144
145typedef int
147 void *context,
148 const char *sec_name,
149 int location_id,
150 int n_location_vals,
151 cs_restart_val_type_t val_type,
152 void *val);
153
154/*----------------------------------------------------------------------------*/
171/*----------------------------------------------------------------------------*/
172
173typedef void
175 void *context,
176 const char *sec_name,
177 int location_id,
178 int n_location_vals,
179 cs_restart_val_type_t val_type,
180 const void *val);
181
182/*=============================================================================
183 * Global variables
184 *============================================================================*/
185
186/*============================================================================
187 * Public function prototypes
188 *============================================================================*/
189
190/*----------------------------------------------------------------------------*/
204/*----------------------------------------------------------------------------*/
205
206void
208 double *t_interval,
209 double *wt_interval);
210
211/*----------------------------------------------------------------------------*/
222/*----------------------------------------------------------------------------*/
223
224void
226 double t_interval,
227 double wt_interval);
228
229/*----------------------------------------------------------------------------*/
247/*----------------------------------------------------------------------------*/
248
249void
251
252/*----------------------------------------------------------------------------*/
260/*----------------------------------------------------------------------------*/
261
262void
264
265/*----------------------------------------------------------------------------*/
271/*----------------------------------------------------------------------------*/
272
273void
275
276/*----------------------------------------------------------------------------*/
282/*----------------------------------------------------------------------------*/
283
284void
286
287/*----------------------------------------------------------------------------*/
293/*----------------------------------------------------------------------------*/
294
295void
297
298/*----------------------------------------------------------------------------*/
304/*----------------------------------------------------------------------------*/
305
306void
308
309/*----------------------------------------------------------------------------*/
317/*----------------------------------------------------------------------------*/
318
319bool
321
322/*----------------------------------------------------------------------------*/
331/*----------------------------------------------------------------------------*/
332
333void
335
336/*----------------------------------------------------------------------------*/
337/*
338 * \brief Access raw restart data serialized in memory.
339 *
340 * If called previously, reinitialize memory data structure.
341 *
342 * \param[out] nb size of data
343 * \param[out] data pointer to data
344 */
345/*----------------------------------------------------------------------------*/
346
347void
349 void **data);
350
351/*----------------------------------------------------------------------------*/
352/*
353 * \brief Indicate restart will be done based on a serialized data in memory.
354 *
355 * The restart subsystem takes ownership of the given data
356 *
357 * \param[in] nb number of matching bytes for data
358 * \param[in] data data buffer (ownership is relinquished by caller)
359 */
360/*----------------------------------------------------------------------------*/
361
362void
364 void *data);
365
366/*----------------------------------------------------------------------------*/
367/*
368 * \brief Indicate checkpoint will be done to serialized data in memory.
369 *
370 * If called previously, reinitialize memory data structure.
371 *
372 * \param[in] status checkpoint to memory if true, to file otherwise.
373 */
374/*----------------------------------------------------------------------------*/
375
376void
378
379/*----------------------------------------------------------------------------*/
385/*----------------------------------------------------------------------------*/
386
387int
389
390/*----------------------------------------------------------------------------*/
401/*----------------------------------------------------------------------------*/
402
404cs_restart_create(const char *name,
405 const char *path,
406 cs_restart_mode_t mode);
407
408/*----------------------------------------------------------------------------*/
414/*----------------------------------------------------------------------------*/
415
416void
418
419/*----------------------------------------------------------------------------*/
433/*----------------------------------------------------------------------------*/
434
435void
437 bool *match_cell,
438 bool *match_i_face,
439 bool *match_b_face,
440 bool *match_vertex);
441
442/*----------------------------------------------------------------------------*/
454/*----------------------------------------------------------------------------*/
455
456int
458 const char *location_name,
459 cs_gnum_t n_glob_ents,
460 cs_lnum_t n_ents,
461 const cs_gnum_t *ent_global_num);
462
463/*----------------------------------------------------------------------------*/
474/*----------------------------------------------------------------------------*/
475
476void
477cs_restart_add_location_ref(const char *location_name,
478 cs_gnum_t n_glob_ents,
479 cs_lnum_t n_ents,
480 const cs_gnum_t *ent_global_num);
481
482/*----------------------------------------------------------------------------*/
486/*----------------------------------------------------------------------------*/
487
488void
490
491/*----------------------------------------------------------------------------*/
505/*----------------------------------------------------------------------------*/
506
507void
508cs_restart_set_context(void *context);
509
510/*----------------------------------------------------------------------------*/
520/*----------------------------------------------------------------------------*/
521
524
525/*----------------------------------------------------------------------------*/
536/*----------------------------------------------------------------------------*/
537
540
541/*----------------------------------------------------------------------------*/
552/*----------------------------------------------------------------------------*/
553
556
557/*----------------------------------------------------------------------------*/
565/*----------------------------------------------------------------------------*/
566
567const char *
568cs_restart_get_name(const cs_restart_t *restart);
569
570/*----------------------------------------------------------------------------*/
580/*----------------------------------------------------------------------------*/
581
584 int location_id);
585
586/*----------------------------------------------------------------------------*/
592/*----------------------------------------------------------------------------*/
593
594void
595cs_restart_dump_index(const cs_restart_t *restart);
596
597/*----------------------------------------------------------------------------*/
610/*----------------------------------------------------------------------------*/
611
612int
614 const char *sec_name,
615 int location_id,
616 int n_location_vals,
617 cs_restart_val_type_t val_type);
618
619/*----------------------------------------------------------------------------*/
633/*----------------------------------------------------------------------------*/
634
635int
637 const char *sec_name,
638 int location_id,
639 int n_location_vals,
640 cs_restart_val_type_t val_type,
641 void *val);
642
643/*----------------------------------------------------------------------------*/
654/*----------------------------------------------------------------------------*/
655
656void
658 const char *sec_name,
659 int location_id,
660 int n_location_vals,
661 cs_restart_val_type_t val_type,
662 const void *val);
663
664/*----------------------------------------------------------------------------*/
676/*----------------------------------------------------------------------------*/
677
678int
680 const char *name,
681 cs_lnum_t *n_particles);
682
683/*----------------------------------------------------------------------------*/
695/*----------------------------------------------------------------------------*/
696
697int
699 int particles_location_id,
700 cs_lnum_t *particle_cell_id,
701 cs_real_t *particle_coords);
702
703/*----------------------------------------------------------------------------*/
723/*----------------------------------------------------------------------------*/
724
725int
727 const char *name,
728 bool number_by_coords,
729 cs_lnum_t n_particles,
730 const cs_lnum_t *particle_cell_id,
731 const cs_real_t *particle_coords);
732
733/*----------------------------------------------------------------------------*/
755/*----------------------------------------------------------------------------*/
756
757int
759 const char *sec_name,
760 int location_id,
761 int ref_location_id,
762 cs_lnum_t ref_id_base,
763 cs_lnum_t *ref_id);
764
765/*----------------------------------------------------------------------------*/
780/*----------------------------------------------------------------------------*/
781
782void
784 const char *sec_name,
785 int location_id,
786 int ref_location_id,
787 cs_lnum_t ref_id_base,
788 const cs_lnum_t *ref_id);
789
790/*----------------------------------------------------------------------------*/
806/*----------------------------------------------------------------------------*/
807
808int
810 const char *sec_name,
811 const char *old_name,
812 int location_id,
813 int n_location_vals,
814 cs_restart_val_type_t val_type,
815 void *val);
816
817/*----------------------------------------------------------------------------*/
836/*----------------------------------------------------------------------------*/
837
838int
840 const char *sec_name,
841 const char *old_name_x,
842 const char *old_name_y,
843 const char *old_name_z,
844 int location_id,
845 cs_real_3_t *val);
846
847/*----------------------------------------------------------------------------*/
869/*----------------------------------------------------------------------------*/
870
871int
873 const char *sec_name,
874 const char *old_name_xx,
875 const char *old_name_yy,
876 const char *old_name_zz,
877 const char *old_name_xy,
878 const char *old_name_yz,
879 const char *old_name_xz,
880 int location_id,
881 cs_real_6_t *val);
882
883/*----------------------------------------------------------------------------*/
905/*----------------------------------------------------------------------------*/
906
907int
909 const char *sec_name,
910 const char *old_name_xx,
911 const char *old_name_yy,
912 const char *old_name_zz,
913 const char *old_name_xy,
914 const char *old_name_yz,
915 const char *old_name_xz,
916 int location_id,
917 cs_real_66_t *val);
918
919/*----------------------------------------------------------------------------*/
923/*----------------------------------------------------------------------------*/
924
925void
927
928/*----------------------------------------------------------------------------*/
932/*----------------------------------------------------------------------------*/
933
934void
936
937/*----------------------------------------------------------------------------*/
943/*----------------------------------------------------------------------------*/
944
945int
947
948/*----------------------------------------------------------------------------*/
954/*----------------------------------------------------------------------------*/
955
956int
958
959/*----------------------------------------------------------------------------*/
972/*----------------------------------------------------------------------------*/
973
974void
975cs_restart_set_n_max_checkpoints(int n_checkpoints);
976
977/*----------------------------------------------------------------------------*/
981/*----------------------------------------------------------------------------*/
982
983void
985
986/*----------------------------------------------------------------------------*/
990/*----------------------------------------------------------------------------*/
991
992void
994
995/*----------------------------------------------------------------------------*/
996
997#endif /* CS_RESTART_H */
time step descriptor
Definition: cs_time_step.h:60
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:359
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:351
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
int cs_restart_is_from_ncfd(void)
Returns if restart is done from a NCFD checkpoint file.
Definition: cs_restart.cpp:4162
cs_restart_mode_t
Definition: cs_restart.h:70
@ CS_RESTART_MODE_WRITE
Definition: cs_restart.h:73
@ CS_RESTART_MODE_READ
Definition: cs_restart.h:72
void cs_checkpoint_set_to_memory_serialized(bool status)
Indicate checkpoint will be done to serialized data in memory.
Definition: cs_restart.cpp:2118
cs_restart_val_type_t
Definition: cs_restart.h:79
@ CS_TYPE_int
Definition: cs_restart.h:81
@ CS_TYPE_cs_gnum_t
Definition: cs_restart.h:82
@ CS_TYPE_cs_real_t
Definition: cs_restart.h:83
@ CS_TYPE_char
Definition: cs_restart.h:80
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:3804
bool cs_restart_checkpoint_required(const cs_time_step_t *ts)
Check if checkpointing is recommended at a given time.
Definition: cs_restart.cpp:1931
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:2791
void cs_restart_checkpoint_get_intervals(int *nt_interval, double *t_interval, double *wt_interval)
Query checkpoint intervals.
Definition: cs_restart.cpp:1725
const char * cs_restart_get_name(const cs_restart_t *restart)
Return name of restart file.
Definition: cs_restart.cpp:2771
void cs_restart_set_context(void *context)
Associate a context to restart section check operations.
Definition: cs_restart.cpp:2690
int cs_restart_present(void)
Check if we have a restart directory.
Definition: cs_restart.cpp:2170
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:2468
void cs_restart_clear_locations_ref(void)
Clear reference location definitions with a private copy.
Definition: cs_restart.cpp:2663
struct _cs_restart_t cs_restart_t
Definition: cs_restart.h:91
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:4133
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:146
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:2852
void cs_restart_checkpoint_set_last_ts(int nt_last)
Define last forced checkpoint time step.
Definition: cs_restart.cpp:1873
void cs_restart_checkpoint_set_next_wt(double wt_next)
Define next forced checkpoint wall-clock time value.
Definition: cs_restart.cpp:1915
void cs_restart_log_setup(void)
Log checkpoint/restart setup.
Definition: cs_restart.cpp:4069
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:2200
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:2708
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:2730
void cs_restart_set_n_max_checkpoints(int n_checkpoints)
Set the number of checkpoint files to keep.
Definition: cs_restart.cpp:4186
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:2752
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:116
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:3690
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:2068
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:174
void cs_restart_checkpoint_set_next_tv(double t_next)
Define next forced checkpoint time value.
Definition: cs_restart.cpp:1901
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:2928
void cs_restart_update_mesh_checkpoint(void)
Update checkpoint directory with mesh.
Definition: cs_restart.cpp:1797
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:2968
void cs_restart_destroy(cs_restart_t **restart)
Destroy structure associated with a restart file (and close the file).
Definition: cs_restart.cpp:2410
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:3510
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:3946
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:3613
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:2526
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:3155
void cs_restart_multiwriters_destroy_all(void)
Destroy the multiwriter structure at the end of the computation.
Definition: cs_restart.cpp:4267
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:2813
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:2885
void cs_restart_clean_multiwriters_history(void)
Remove all previous checkpoints which are not to be retained.
Definition: cs_restart.cpp:4208
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:2621
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:3272
void cs_restart_checkpoint_set_interval(int nt_interval, double t_interval, double wt_interval)
Define default checkpoint interval.
Definition: cs_restart.cpp:1751
void cs_restart_get_from_memory_serialized(size_t *nb, void **data)
Definition: cs_restart.cpp:2045
void cs_restart_checkpoint_set_mesh_mode(int mode)
Define checkpoint behavior for mesh.
Definition: cs_restart.cpp:1781
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:3407
void cs_restart_checkpoint_done(const cs_time_step_t *ts)
Indicate checkpointing has been done at a given time.
Definition: cs_restart.cpp:2003
void cs_restart_print_stats(void)
Print statistics associated with restart files.
Definition: cs_restart.cpp:4110
void cs_restart_checkpoint_set_next_ts(int nt_next)
Define next forced checkpoint time step.
Definition: cs_restart.cpp:1887