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-2021 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 
44 BEGIN_C_DECLS
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 /*!< Success */
59 #define CS_RESTART_ERR_FILE_NUM  -1 /*!< No restart file for the given number */
60 #define CS_RESTART_ERR_LOCATION  -2 /*!< Undefined location / incorrect size */
61 #define CS_RESTART_ERR_VAL_TYPE  -3 /*!< Unknown or unexpected value type */
62 #define CS_RESTART_ERR_N_VALS    -4 /*!< Number of values does not match */
63 #define CS_RESTART_ERR_MODE      -5 /*!< Incompatible access mode */
64 #define CS_RESTART_ERR_EXISTS    -6 /*!< Section not available */
65 
66 /*============================================================================
67  * Local type definitions
68  *============================================================================*/
69 
70 /*! Read or write mode */
71 
72 typedef enum {
73 
74   CS_RESTART_MODE_READ,         /*!< Read mode */
75   CS_RESTART_MODE_WRITE         /*!< Write mode */
76 
77 } cs_restart_mode_t;
78 
79 /* Datatype enumeration to transmit a data's type to a function */
80 
81 typedef enum {
82   CS_TYPE_char,
83   CS_TYPE_int,
84   CS_TYPE_cs_gnum_t,
85   CS_TYPE_cs_real_t,
86 } cs_restart_val_type_t;
87 
88 /*
89   Pointer associated with a restart file structure. The structure itself
90   is defined in "cs_restart.c", and is opaque outside that unit.
91 */
92 
93 typedef struct _cs_restart_t cs_restart_t;
94 
95 /*----------------------------------------------------------------------------*/
96 /*!
97  * \brief Function pointer for modifying behavior when checking a section's
98  *        presence.
99  *
100  * Note: if the context pointer is non-NULL, it must point to valid data
101  * when the selection function is called, so that value or structure should
102  * in general not be temporary.
103  *
104  * \param[in]       restart          associated restart file pointer
105  * \param[in, out]  context          pointer to optional (untyped) value or
106  *                                   structure.
107  * \param[in]       sec_name         section name
108  * \param[in]       location_id      id of corresponding location
109  * \param[in]       n_location_vals  number of values per location (interlaced)
110  * \param[in]       val_type         value type
111  *
112  * \return  0 (CS_RESTART_SUCCESS) in case of success,
113  *          or error code (CS_RESTART_ERR_xxx) in case of error
114  */
115 /*----------------------------------------------------------------------------*/
116 
117 typedef int
118 (cs_restart_check_section_t)(cs_restart_t           *restart,
119                              void                   *context,
120                              const char             *sec_name,
121                              int                     location_id,
122                              int                     n_location_vals,
123                              cs_restart_val_type_t   val_type);
124 
125 /*----------------------------------------------------------------------------*/
126 /*!
127  * \brief Function pointer for modifying behavior when reading a section.
128  *
129  * Note: if the context pointer is non-NULL, it must point to valid data
130  * when the selection function is called, so that value or structure should
131  * in general not be temporary.
132  *
133  * \param[in]       restart          associated restart file pointer
134  * \param[in, out]  context          pointer to optional (untyped) value or
135  *                                   structure.
136  * \param[in]       sec_name         section name
137  * \param[in]       location_id      id of corresponding location
138  * \param[in]       n_location_vals  number of values per location (interlaced)
139  * \param[in]       val_type         value type
140  * \param[out]      val              array of values
141  *
142  * \return  0 (CS_RESTART_SUCCESS) in case of success,
143  *          or error code (CS_RESTART_ERR_xxx) in case of error
144  */
145 /*----------------------------------------------------------------------------*/
146 
147 typedef int
148 (cs_restart_read_section_t)(cs_restart_t           *restart,
149                             void                   *context,
150                             const char             *sec_name,
151                             int                     location_id,
152                             int                     n_location_vals,
153                             cs_restart_val_type_t   val_type,
154                             void                   *val);
155 
156 /*----------------------------------------------------------------------------*/
157 /*!
158  * \brief Function pointer for modifying behavior when writing a section.
159  *
160  * Note: if the context pointer is non-NULL, it must point to valid data
161  * when the selection function is called, so that value or structure should
162  * in general not be temporary.
163  *
164  * \param[in]       restart          associated restart file pointer
165  * \param[in, out]  context          pointer to optional (untyped) value or
166  *                                   structure.
167  * \param[in]       sec_name         section name
168  * \param[in]       location_id      id of corresponding location
169  * \param[in]       n_location_vals  number of values per location (interlaced)
170  * \param[in]       val_type         value type
171  * \param[in]       val              array of values
172  */
173 /*----------------------------------------------------------------------------*/
174 
175 typedef void
176 (cs_restart_write_section_t)(cs_restart_t           *restart,
177                              void                   *context,
178                              const char             *sec_name,
179                              int                     location_id,
180                              int                     n_location_vals,
181                              cs_restart_val_type_t   val_type,
182                              const void             *val);
183 
184 /*=============================================================================
185  * Global variables
186  *============================================================================*/
187 
188 /*============================================================================
189  * Public Fortran function prototypes
190  *============================================================================*/
191 
192 /*----------------------------------------------------------------------------
193  * Indicate if a restart directory is present.
194  *
195  * Fortran interface
196  *
197  * subroutine dflsui (ntsuit, ttsuit, wtsuit)
198  * *****************
199  *
200  * integer          ntsuit      : <-- : > 0: checkpoint time step interval
201  *                              :     : 0: default interval
202  *                              :     : -1: checkpoint at end
203  *                              :     : -2: no checkpoint
204  * double precision ttsuit      : <-- : if> 0, checkpoint time interval
205  * double precision wtsuit      : <-- : if> 0, checkpoint wall time interval
206  *----------------------------------------------------------------------------*/
207 
208 void CS_PROCF (dflsui, DFLSUI)
209 (
210  int        *ntsuit,
211  cs_real_t  *ttsuit,
212  cs_real_t  *wtsuit
213 );
214 
215 /*----------------------------------------------------------------------------
216  * Check if checkpointing is recommended at a given time.
217  *
218  * Fortran interface
219  *
220  * subroutine reqsui (iisuit)
221  * *****************
222  *
223  * integer          iisuit      : --> : 0 if no restart required, 1 otherwise
224  *----------------------------------------------------------------------------*/
225 
226 void CS_PROCF (reqsui, REQSUI)
227 (
228  int  *iisuit
229 );
230 
231 /*----------------------------------------------------------------------------
232  * Indicate checkpointing has been done at a given time.
233  *
234  * This updates the status for future checks to determine
235  * if checkpointing is recommended at a given time.
236  *
237  * Fortran interface
238  *
239  * subroutine stusui
240  * *****************
241  *----------------------------------------------------------------------------*/
242 
243 void CS_PROCF (stusui, STUSUI)
244 (
245  void
246 );
247 
248 /*----------------------------------------------------------------------------
249  * Save output mesh for turbomachinery if needed
250  *
251  * Fortran interface
252  *
253  * subroutine trbsui
254  * *****************
255  *----------------------------------------------------------------------------*/
256 
257 void CS_PROCF (trbsui, TRBSUI)
258 (
259  void
260 );
261 
262 /*----------------------------------------------------------------------------
263  * Indicate if a restart directory is present.
264  *
265  * Fortran interface
266  *
267  * subroutine indsui (isuite)
268  * *****************
269  *
270  * integer          isuite      : --> : 1 for restart, 0 otherwise
271  *----------------------------------------------------------------------------*/
272 
273 void CS_PROCF (indsui, INDSUI)
274 (
275  int   *isuite
276 );
277 
278 /*============================================================================
279  * Public function prototypes
280  *============================================================================*/
281 
282 /*----------------------------------------------------------------------------*/
283 /*!
284  * \brief  Define default checkpoint interval.
285  *
286  * \param[in]  nt_interval  if > 0 time step interval for checkpoint
287  *                          if 0, default of 4 checkpoints per run
288  *                          if -1, checkpoint at end
289  *                          if -2, no checkpointing
290  * \param[in]  t_interval   if > 0, time value interval for checkpoint
291  * \param[in]  wt_interval  if > 0, wall-clock interval for checkpoints
292  */
293 /*----------------------------------------------------------------------------*/
294 
295 void
296 cs_restart_checkpoint_set_defaults(int     nt_interval,
297                                    double  t_interval,
298                                    double  wt_interval);
299 
300 /*----------------------------------------------------------------------------*/
301 /*!
302  * \brief  Define checkpoint behavior for mesh.
303  *
304  * If mesh checkpointing is active (default), upon writing the first
305  * checkpoint file of a computation, a mesh_output file is moved to
306  * checkpoint/mesh_input if present. If not present but a mesh_input
307  * file (or link to file) is present, a hard link to that file is
308  * added as checkpoint/mesh_input.
309  *
310  * A mesh_input directory is ignored, as it is normally only created when
311  * multiple input files are appended, which leads to the output and thus
312  * presence of a mesh_output file, unless explicitely deactivated by the
313  * user.
314  *
315  * \param[in]  mode  if 0, do not checkpoint mesh
316  *                   if 1, checkpoint mesh_output or mesh_input file
317  */
318 /*----------------------------------------------------------------------------*/
319 
320 void
321 cs_restart_checkpoint_set_mesh_mode(int  mode);
322 
323 /*----------------------------------------------------------------------------*/
324 /*!
325  * \brief  Define last forced checkpoint time step.
326  *
327  * \param[in]  nt_last  last time step for forced checkpoint
328  */
329 /*----------------------------------------------------------------------------*/
330 
331 void
332 cs_restart_checkpoint_set_last_ts(int  nt_last);
333 
334 /*----------------------------------------------------------------------------*/
335 /*!
336  * \brief  Define next forced checkpoint time step.
337  *
338  * \param[in]  nt_next  next time step for forced checkpoint
339  */
340 /*----------------------------------------------------------------------------*/
341 
342 void
343 cs_restart_checkpoint_set_next_ts(int  nt_next);
344 
345 /*----------------------------------------------------------------------------*/
346 /*!
347  * \brief  Define next forced checkpoint time value.
348  *
349  * \param[in]  t_next  next time value for forced checkpoint
350  */
351 /*----------------------------------------------------------------------------*/
352 
353 void
354 cs_restart_checkpoint_set_next_tv(double  t_next);
355 
356 /*----------------------------------------------------------------------------*/
357 /*!
358  * \brief  Define next forced checkpoint wall-clock time value.
359  *
360  * \param[in]  wt_next  next wall-clock time value for forced checkpoint
361  */
362 /*----------------------------------------------------------------------------*/
363 
364 void
365 cs_restart_checkpoint_set_next_wt(double  wt_next);
366 
367 /*----------------------------------------------------------------------------*/
368 /*!
369  * \brief  Check if checkpointing is recommended at a given time.
370  *
371  * \param[in]  ts  time step status structure
372  *
373  * \return  true if checkpointing is recommended, false otherwise
374  */
375 /*----------------------------------------------------------------------------*/
376 
377 bool
378 cs_restart_checkpoint_required(const cs_time_step_t  *ts);
379 
380 /*----------------------------------------------------------------------------*/
381 /*!
382  * \brief  Indicate checkpointing has been done at a given time.
383  *
384  * This updates the status for future checks to determine
385  * if checkpointing is recommended at a given time.
386  *
387  * \param[in]  ts  time step status structure
388  */
389 /*----------------------------------------------------------------------------*/
390 
391 void
392 cs_restart_checkpoint_done(const cs_time_step_t  *ts);
393 
394 /*----------------------------------------------------------------------------*/
395 /*!
396  * \brief  Check if we have a restart directory.
397  *
398  * \return  1 if a restart directory is present, 0 otherwise
399  */
400 /*----------------------------------------------------------------------------*/
401 
402 int
403 cs_restart_present(void);
404 
405 /*----------------------------------------------------------------------------*/
406 /*!
407  * \brief  Initialize a restart file.
408  *
409  * \param[in]  name  file name
410  * \param[in]  path  optional directory name for output, or NULL for default
411  *                   (directory automatically created if necessary)
412  * \param[in]  mode  read or write
413  *
414  * \return  pointer to initialized restart file structure
415  */
416 /*----------------------------------------------------------------------------*/
417 
418 cs_restart_t *
419 cs_restart_create(const char         *name,
420                   const char         *path,
421                   cs_restart_mode_t   mode);
422 
423 /*----------------------------------------------------------------------------*/
424 /*!
425  * \brief  Destroy structure associated with a restart file (and close the file).
426  *
427  * \param[in, out]  restart  pointer to restart file structure pointer
428  */
429 /*----------------------------------------------------------------------------*/
430 
431 void
432 cs_restart_destroy(cs_restart_t  **restart);
433 
434 /*----------------------------------------------------------------------------*/
435 /*!
436  * \brief  Check the locations associated with a restart file.
437  *
438  * For each type of entity, the corresponding flag is set to true if the
439  * associated number of entities matches the current value (and so that we
440  * consider the mesh locations are the same), false otherwise.
441  *
442  * \param[out]  restart       associated restart file pointer
443  * \param[out]  match_cell    matching cells flag
444  * \param[out]  match_i_face  matching interior faces flag
445  * \param[out]  match_b_face  matching boundary faces flag
446  * \param[out]  match_vertex  matching vertices flag
447  */
448 /*----------------------------------------------------------------------------*/
449 
450 void
451 cs_restart_check_base_location(const cs_restart_t  *restart,
452                                bool                *match_cell,
453                                bool                *match_i_face,
454                                bool                *match_b_face,
455                                bool                *match_vertex);
456 
457 /*----------------------------------------------------------------------------*/
458 /*!
459  * \brief  Add a location definition.
460  *
461  * \param[in]  restart         associated restart file pointer
462  * \param[in]  location_name   name associated with the location
463  * \param[in]  n_glob_ents     global number of entities
464  * \param[in]  n_ents          local number of entities
465  * \param[in]  ent_global_num  global entity numbers, or NULL
466  *
467  * \return  the location id assigned, or -1 in case of error
468  */
469 /*----------------------------------------------------------------------------*/
470 
471 int
472 cs_restart_add_location(cs_restart_t      *restart,
473                         const char        *location_name,
474                         cs_gnum_t          n_glob_ents,
475                         cs_lnum_t          n_ents,
476                         const cs_gnum_t   *ent_global_num);
477 
478 /*----------------------------------------------------------------------------*/
479 /*!
480  * \brief  Add a reference location definition with a private copy.
481  *
482  * \param[in]  location_name   name associated with the location
483  * \param[in]  n_glob_ents     global number of entities
484  * \param[in]  n_ents          local number of entities
485  * \param[in]  ent_global_num  global entity numbers, or NULL
486  *
487  * \return  the location id assigned, or -1 in case of error
488  */
489 /*----------------------------------------------------------------------------*/
490 
491 void
492 cs_restart_add_location_ref(const char       *location_name,
493                             cs_gnum_t         n_glob_ents,
494                             cs_lnum_t         n_ents,
495                             const cs_gnum_t  *ent_global_num);
496 
497 /*----------------------------------------------------------------------------*/
498 /*!
499  * \brief  Clear reference location definitions with a private copy.
500  */
501 /*----------------------------------------------------------------------------*/
502 
503 void
504 cs_restart_clear_locations_ref(void);
505 
506 /*----------------------------------------------------------------------------*/
507 /*!
508  * \brief  Associate a context to restart section check operations.
509  *
510  * This context may be used by the \ref cs_restart_check_section_t,
511  * \ref cs_restart_read_section_t, and \ref cs_restart_write_section_t
512  * type functions.
513  *
514  * Note that the lifecycle of the data pointed to must be handled separately
515  * (and the pointer must remain valid until the matching restart structure
516  * is destroyed.
517  *
518  * \param[in]  context  pointer to associated data, or NULL
519  */
520 /*----------------------------------------------------------------------------*/
521 
522 void
523 cs_restart_set_context(void  *context);
524 
525 /*----------------------------------------------------------------------------*/
526 /*!
527  * \brief  Associate a function to restart section check operations.
528  *
529  * This allows defining alternate operations when checking restart sections.
530  *
531  * \param[in]  func  associated function
532  *
533  * \return   pointer to previous function
534  */
535 /*----------------------------------------------------------------------------*/
536 
537 cs_restart_check_section_t  *
538 cs_restart_set_check_section_func(cs_restart_check_section_t  *func);
539 
540 /*----------------------------------------------------------------------------*/
541 /*!
542  * \brief  Associate a function and its input to all restart section
543  *         read operations.
544  *
545  * This allows defining alternate operations when reading restart sections.
546  *
547  * \param[in]  func  associated function
548  *
549  * \return   pointer to previous function
550  */
551 /*----------------------------------------------------------------------------*/
552 
553 cs_restart_read_section_t  *
554 cs_restart_set_read_section_func(cs_restart_read_section_t  *func);
555 
556 /*----------------------------------------------------------------------------*/
557 /*!
558  * \brief  Associate a function and its input to all restart section
559  *         write operations.
560  *
561  * This allows defining alternate operations when writing restart sections.
562  *
563  * \param[in]  func  associated hook function
564  *
565  * \return   pointer to previous function
566  */
567 /*----------------------------------------------------------------------------*/
568 
569 cs_restart_write_section_t  *
570 cs_restart_set_write_section_func(cs_restart_write_section_t  *func);
571 
572 /*----------------------------------------------------------------------------*/
573 /*!
574  * \brief  Return name of restart file
575  *
576  * \param[in]  restart  associated restart file pointer
577  *
578  * \return  base name of restart file
579  */
580 /*----------------------------------------------------------------------------*/
581 
582 const char *
583 cs_restart_get_name(const cs_restart_t  *restart);
584 
585 /*----------------------------------------------------------------------------*/
586 /*!
587  * \brief  Return local number of elements associated with a
588  *         given restart location.
589  *
590  * \param[in]  restart      associated restart file pointer
591  * \param[in]  location_id  id of corresponding location
592  *
593  * \return  number of elements associated with location.
594  */
595 /*----------------------------------------------------------------------------*/
596 
597 cs_lnum_t
598 cs_restart_get_n_location_elts(const cs_restart_t  *restart,
599                                int                  location_id);
600 
601 /*----------------------------------------------------------------------------*/
602 /*!
603  * \brief  Print the index associated with a restart file in read mode
604  *
605  * \param[in]  restart  associated restart file pointer
606  */
607 /*----------------------------------------------------------------------------*/
608 
609 void
610 cs_restart_dump_index(const cs_restart_t  *restart);
611 
612 /*----------------------------------------------------------------------------*/
613 /*!
614  * \brief  Check the presence of a given section in a restart file.
615  *
616  * \param[in]  restart          associated restart file pointer
617  * \param[in]  sec_name         section name
618  * \param[in]  location_id      id of corresponding location
619  * \param[in]  n_location_vals  number of values per location (interlaced)
620  * \param[in]  val_type         value type
621  *
622  * \return  0 (CS_RESTART_SUCCESS) in case of success,
623  *          or error code (CS_RESTART_ERR_xxx) in case of error
624  */
625 /*----------------------------------------------------------------------------*/
626 
627 int
628 cs_restart_check_section(cs_restart_t           *restart,
629                          const char             *sec_name,
630                          int                     location_id,
631                          int                     n_location_vals,
632                          cs_restart_val_type_t   val_type);
633 
634 /*----------------------------------------------------------------------------*/
635 /*!
636  * \brief  Read a section from a restart file.
637  *
638  * \param[in]   restart          associated restart file pointer
639  * \param[in]   sec_name         section name
640  * \param[in]   location_id      id of corresponding location
641  * \param[in]   n_location_vals  number of values per location (interlaced)
642  * \param[in]   val_type         value type
643  * \param[out]  val              array of values
644  *
645  * \return  0 (CS_RESTART_SUCCESS) in case of success,
646  *          or error code (CS_RESTART_ERR_xxx) in case of error
647  */
648 /*----------------------------------------------------------------------------*/
649 
650 int
651 cs_restart_read_section(cs_restart_t           *restart,
652                         const char             *sec_name,
653                         int                     location_id,
654                         int                     n_location_vals,
655                         cs_restart_val_type_t   val_type,
656                         void                   *val);
657 
658 /*----------------------------------------------------------------------------*/
659 /*!
660  * \brief  Write a section to a restart file.
661  *
662  * \param[in]  restart          associated restart file pointer
663  * \param[in]  sec_name         section name
664  * \param[in]  location_id      id of corresponding location
665  * \param[in]  n_location_vals  number of values per location (interlaced)
666  * \param[in]  val_type         value type
667  * \param[in]  val              array of values
668  */
669 /*----------------------------------------------------------------------------*/
670 
671 void
672 cs_restart_write_section(cs_restart_t           *restart,
673                          const char             *sec_name,
674                          int                     location_id,
675                          int                     n_location_vals,
676                          cs_restart_val_type_t   val_type,
677                          const void             *val);
678 
679 /*----------------------------------------------------------------------------*/
680 /*!
681  * \brief  Read basic particles information from a restart file.
682  *
683  * This includes building a matching location and associated global numbering.
684  *
685  * \param[in]   restart      associated restart file pointer
686  * \param[in]   name         name of particles set
687  * \param[out]  n_particles  number of particles, or NULL
688  *
689  * \return  the location id assigned to the particles, or -1 in case of error
690  */
691 /*----------------------------------------------------------------------------*/
692 
693 int
694 cs_restart_read_particles_info(cs_restart_t  *restart,
695                                const char    *name,
696                                cs_lnum_t     *n_particles);
697 
698 /*----------------------------------------------------------------------------*/
699 /*!
700  * \brief  Read basic particles information from a restart file.
701  *
702  * \param[in]   restart                associated restart file pointer
703  * \param[in]   particles_location_id  location id of particles set
704  * \param[out]  particle_cell_id       local cell id to which particles belong
705  * \param[out]  particle_coords        local particle coordinates (interleaved)
706  *
707  * \return  0 (CS_RESTART_SUCCESS) in case of success,
708  *          or error code (CS_RESTART_ERR_xxx) in case of error
709  */
710 /*----------------------------------------------------------------------------*/
711 
712 int
713 cs_restart_read_particles(cs_restart_t  *restart,
714                           int            particles_location_id,
715                           cs_lnum_t     *particle_cell_id,
716                           cs_real_t     *particle_coords);
717 
718 /*----------------------------------------------------------------------------*/
719 /*!
720  * \brief  Write basic particles information to a restart file.
721  *
722  * This includes defining a matching location and associated global numbering,
723  * then writing particle coordinates and cell ids.
724  *
725  * \param[in]  restart            associated restart file pointer
726  * \param[in]  name               name of particles set
727  * \param[in]  number_by_coords   if true, numbering is based on current
728  *                                coordinates; otherwise, it is simply based
729  *                                on local numbers, plus the sum of particles
730  *                                on lower MPI ranks
731  * \param[in]  n_particles        local number of particles
732  * \param[in]  particle_cell_id   local cell id (0 to n-1) to which particles
733  *                                belong
734  * \param[in]  particle_coords    local particle coordinates (interleaved)
735  *
736  * \return  the location id assigned to the particles
737  */
738 /*----------------------------------------------------------------------------*/
739 
740 int
741 cs_restart_write_particles(cs_restart_t     *restart,
742                            const char       *name,
743                            bool              number_by_coords,
744                            cs_lnum_t         n_particles,
745                            const cs_lnum_t  *particle_cell_id,
746                            const cs_real_t  *particle_coords);
747 
748 /*----------------------------------------------------------------------------*/
749 /*!
750  * \brief  Read a referenced location id section from a restart file.
751  *
752  * The section read from file contains the global ids matching the local
753  * element ids of a given location. Global id's are transformed to local
754  * ids by this function.
755  *
756  * In case global referenced ids read do not match those of local elements,
757  * id_base - 1 is assigned to the corresponding local ids.
758  *
759  * \param[in]   restart          associated restart file pointer
760  * \param[in]   sec_name         section name
761  * \param[in]   location_id      id of location on which id_ref is defined
762  * \param[in]   ref_location_id  id of referenced location
763  * \param[in]   ref_id_base      base of location entity id numbers
764  *                               (usually 0 or 1)
765  * \param[out]  ref_id           array of location entity ids
766  *
767  * \return  0 (CS_RESTART_SUCCESS) in case of success,
768  *          or error code (CS_RESTART_ERR_xxx) in case of error
769  */
770 /*----------------------------------------------------------------------------*/
771 
772 int
773 cs_restart_read_ids(cs_restart_t     *restart,
774                     const char       *sec_name,
775                     int               location_id,
776                     int               ref_location_id,
777                     cs_lnum_t         ref_id_base,
778                     cs_lnum_t        *ref_id);
779 
780 /*----------------------------------------------------------------------------*/
781 /*!
782  * \brief  Write a referenced location id section to a restart file.
783  *
784  * The section written to file contains the global ids matching the
785  * local element ids of a given location.
786  *
787  * \param[in]  restart          associated restart file pointer
788  * \param[in]  sec_name         section name
789  * \param[in]  location_id      id of location on which id_ref is defined
790  * \param[in]  ref_location_id  id of referenced location
791  * \param[in]  ref_id_base      base of location entity id numbers
792  *                              (usually 0 or 1)
793  * \param[in]  ref_id           array of location entity ids
794  */
795 /*----------------------------------------------------------------------------*/
796 
797 void
798 cs_restart_write_ids(cs_restart_t           *restart,
799                      const char             *sec_name,
800                      int                     location_id,
801                      int                     ref_location_id,
802                      cs_lnum_t               ref_id_base,
803                      const cs_lnum_t        *ref_id);
804 
805 /*----------------------------------------------------------------------------*/
806 /*!
807  * \brief  Read a section from a restart file, when that section may have used
808  *         a different name in a previous version.
809  *
810  * \param[in]   restart          associated restart file pointer
811  * \param[in]   sec_name         section name
812  * \param[in]   old_name         old name
813  * \param[in]   location_id      id of corresponding location
814  * \param[in]   n_location_vals  number of values per location (interlaced)
815  * \param[in]   val_type         value type
816  * \param[out]  val              array of values
817  *
818  * \return  0 (CS_RESTART_SUCCESS) in case of success,
819  *          or error code (CS_RESTART_ERR_xxx) in case of error
820  */
821 /*----------------------------------------------------------------------------*/
822 
823 int
824 cs_restart_read_section_compat(cs_restart_t           *restart,
825                                const char             *sec_name,
826                                const char             *old_name,
827                                int                     location_id,
828                                int                     n_location_vals,
829                                cs_restart_val_type_t   val_type,
830                                void                   *val);
831 
832 /*----------------------------------------------------------------------------*/
833 /*!
834  * \brief  Read a cs_real_3_t vector section from a restart file, when that
835  *         section may have used a different name and been non-interleaved
836  *         in a previous version.
837  *
838  * This function assumes a mesh-base location (i.e. location_id > 0)
839  *
840  * \param[in]   restart          associated restart file pointer
841  * \param[in]   sec_name         section name
842  * \param[in]   old_name_x       old name, x component
843  * \param[in]   old_name_y       old name, y component
844  * \param[in]   old_name_z       old name, z component
845  * \param[in]   location_id      id of corresponding location
846  * \param[out]  val              array of values
847  *
848  * \return  0 (CS_RESTART_SUCCESS) in case of success,
849  *          or error code (CS_RESTART_ERR_xxx) in case of error
850  */
851 /*----------------------------------------------------------------------------*/
852 
853 int
854 cs_restart_read_real_3_t_compat(cs_restart_t  *restart,
855                                 const char    *sec_name,
856                                 const char    *old_name_x,
857                                 const char    *old_name_y,
858                                 const char    *old_name_z,
859                                 int            location_id,
860                                 cs_real_3_t   *val);
861 
862 /*----------------------------------------------------------------------------*/
863 /*!
864  * \brief  Read a cs_real_6_t tensor section from a restart file, when that
865  *         section may have used a different name and been non-interleaved
866  *         in a previous version.
867  *
868  * This function assumes a mesh-base location (i.e. location_id > 0)
869  *
870  * \param[in]   restart          associated restart file pointer
871  * \param[in]   sec_name         section name
872  * \param[in]   old_name_xx      old name, xx component
873  * \param[in]   old_name_yy      old name, yy component
874  * \param[in]   old_name_zz      old name, zz component
875  * \param[in]   old_name_xy      old name, xy component
876  * \param[in]   old_name_yz      old name, yz component
877  * \param[in]   old_name_xz      old name, xz component
878  * \param[in]   location_id      id of corresponding location
879  * \param[out]  val              array of values
880  *
881  * \return  0 (CS_RESTART_SUCCESS) in case of success,
882  *          or error code (CS_RESTART_ERR_xxx) in case of error
883  */
884 /*----------------------------------------------------------------------------*/
885 
886 int
887 cs_restart_read_real_6_t_compat(cs_restart_t  *restart,
888                                 const char    *sec_name,
889                                 const char    *old_name_xx,
890                                 const char    *old_name_yy,
891                                 const char    *old_name_zz,
892                                 const char    *old_name_xy,
893                                 const char    *old_name_yz,
894                                 const char    *old_name_xz,
895                                 int            location_id,
896                                 cs_real_6_t   *val);
897 
898 /*----------------------------------------------------------------------------*/
899 /*!
900  * \brief  Read a cs_real_66_t tensor section from a restart file, when that
901  *         section may have used a different name and been non-interleaved
902  *         in a previous version.
903  *
904  * This function assumes a mesh-base location (i.e. location_id > 0)
905  *
906  * \param[in]   restart          associated restart file pointer
907  * \param[in]   sec_name         section name
908  * \param[in]   old_name_xx      old name, xx component
909  * \param[in]   old_name_yy      old name, yy component
910  * \param[in]   old_name_zz      old name, zz component
911  * \param[in]   old_name_xy      old name, xy component
912  * \param[in]   old_name_yz      old name, yz component
913  * \param[in]   old_name_xz      old name, xz component
914  * \param[in]   location_id      id of corresponding location
915  * \param[out]  val              array of values
916  *
917  * \return  0 (CS_RESTART_SUCCESS) in case of success,
918  *          or error code (CS_RESTART_ERR_xxx) in case of error
919  */
920 /*----------------------------------------------------------------------------*/
921 
922 int
923 cs_restart_read_real_66_t_compat(cs_restart_t  *restart,
924                                  const char    *sec_name,
925                                  const char    *old_name_xx,
926                                  const char    *old_name_yy,
927                                  const char    *old_name_zz,
928                                  const char    *old_name_xy,
929                                  const char    *old_name_yz,
930                                  const char    *old_name_xz,
931                                  int            location_id,
932                                  cs_real_66_t  *val);
933 
934 /*----------------------------------------------------------------------------*/
935 /*!
936  * \brief  Print statistics associated with restart files
937  */
938 /*----------------------------------------------------------------------------*/
939 
940 void
941 cs_restart_print_stats(void);
942 
943 /*----------------------------------------------------------------------------*/
944 /*!
945  * \brief Checks if restart is done from a NCFD checkpoint file
946  *
947  * \return 0 if no, 1 if yes
948  */
949 /*----------------------------------------------------------------------------*/
950 
951 int
952 cs_restart_check_if_restart_from_ncfd(cs_restart_t *r);
953 
954 /*----------------------------------------------------------------------------*/
955 /*!
956  * \brief Returns if restart is done from a NCFD checkpoint file
957  *
958  * \return 0 if no, 1 if yes
959  */
960 /*----------------------------------------------------------------------------*/
961 
962 int
963 cs_restart_is_from_ncfd(void);
964 
965 /*----------------------------------------------------------------------------*/
966 /*!
967  * \brief Set the number of checkpoint files to keep.
968  *
969  * This function sets the number of checkpoint files to keep.
970  * If value is set to -1, all checkpoints are kept.
971  * If more than one file is kept, last one is always named "<prefix>.csc",
972  * while others are names "<prefix_%04d.csc".
973  * %04 provides an id using 4 digits (0 padding), and value is the order
974  * of writing, starting with 0. Hence : prefix_0000.csc, prefix_0001.csc, ...
975  *
976  * \param[in]   n_checkpoints  number of checkpoint files to keps.
977  */
978 /*----------------------------------------------------------------------------*/
979 
980 void
981 cs_restart_set_n_max_checkpoints(int  n_checkpoints);
982 
983 /*----------------------------------------------------------------------------*/
984 /*!
985  * \brief Remove all previous checkpoints which are not to be retained.
986  */
987 /*----------------------------------------------------------------------------*/
988 
989 void
990 cs_restart_clean_multiwriters_history(void);
991 
992 /*----------------------------------------------------------------------------*/
993 /*!
994  * \brief Destroy the multiwriter structure at the end of the computation.
995  */
996 /*----------------------------------------------------------------------------*/
997 
998 void
999 cs_restart_multiwriters_destroy_all(void);
1000 
1001 /*----------------------------------------------------------------------------*/
1002 
1003 END_C_DECLS
1004 
1005 #endif /* __CS_RESTART_H__ */
1006