Code_Saturne
CFD tool
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-2012 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 /*----------------------------------------------------------------------------*/
41 
43 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /* Error codes */
49 
50 #define CS_RESTART_SUCCES 0 /* Success */
51 #define CS_RESTART_ERR_FILE_NUM -1 /* No restart file for the given number */
52 #define CS_RESTART_ERR_LOCATION -2 /* Undefined location / incorrect size */
53 #define CS_RESTART_ERR_VAL_TYPE -3 /* Unknown or unexpected value type */
54 #define CS_RESTART_ERR_N_VALS -4 /* Number of values does not match */
55 #define CS_RESTART_ERR_MODE -5 /* Incompatible access mode */
56 #define CS_RESTART_ERR_EXISTS -6 /* Section not available */
57 
58 /*============================================================================
59  * Local type definitions
60  *============================================================================*/
61 
62 /* Read or write mode */
63 
64 typedef enum {
65 
66  CS_RESTART_MODE_READ, /* Read mode */
67  CS_RESTART_MODE_WRITE /* Write mode */
68 
70 
71 /*
72  Pointer associated with a restart file structure. The structure itself
73  is defined in "cs_restart.c", and is opaque outside that unit.
74 */
75 
76 typedef struct _cs_restart_t cs_restart_t;
77 
78 /*=============================================================================
79  * Global variables
80  *============================================================================*/
81 
82 /*============================================================================
83  * Public Fortran function prototypes
84  *============================================================================*/
85 
86 /*----------------------------------------------------------------------------
87  * Indicate if a restart directory is present.
88  *
89  * Fortran interface
90  *
91  * subroutine indsui (isuite)
92  * *****************
93  *
94  * integer isuite : --> : 1 for restart, 0 otherwise
95  *----------------------------------------------------------------------------*/
96 
97 void CS_PROCF (indsui, INDSUI)
98 (
100 );
101 
102 /*----------------------------------------------------------------------------
103  * Open a restart file
104  *
105  * Fortran interface
106  *
107  * subroutine opnsui (nomsui, lngnom, ireawr, numsui, ierror)
108  * *****************
109  *
110  * character* nomsui : <-- : Restart file name
111  * integer lngnom : <-- : Restart file name length
112  * integer ireawr : <-- : 1: read; 2: write
113  * integer numsui : --> : Number of opened restart file
114  * integer ierror : --> : 0: success; < 0: error code
115  *----------------------------------------------------------------------------*/
116 
117 void CS_PROCF (opnsui, OPNSUI)
118 (
119  const char *nomsui,
120  const cs_int_t *lngnom,
121  const cs_int_t *ireawr,
122  cs_int_t *numsui,
123  cs_int_t *ierror
124  CS_ARGF_SUPP_CHAINE /* (possible 'length' arguments added
125  by many Fortran compilers) */
126 );
127 
128 /*----------------------------------------------------------------------------
129  * Close a restart file
130  *
131  * Fortran interface
132  *
133  * subroutine clssui (numsui)
134  * *****************
135  *
136  * integer numsui : <-> : Number of restart file to close
137  * integer ierror : --> : 0: success; < 0: error code
138  *----------------------------------------------------------------------------*/
139 
140 void CS_PROCF (clssui, CLSSUI)
141 (
142  const cs_int_t *numsui,
143  cs_int_t *ierror
144 );
145 
146 /*----------------------------------------------------------------------------
147  * Check the locations associated with a restart file.
148  *
149  * For each type of entity, return 1 if the associated number of entities
150  * matches the current value (and so that we consider the mesh locations are
151  * the same), 0 otherwise.
152  *
153  * Fortran interface
154  *
155  * subroutine tstsui (numsui, indcel, indfac, indfbr, indsom)
156  * *****************
157  *
158  * integer numsui : <-- : Restart file number
159  * integer indcel : --> : Matching cells flag
160  * integer indfac : --> : Matching interior faces flag
161  * integer indfbr : --> : Matching boundary faces flag
162  * integer indsom : --> : Matching vertices flag
163  *----------------------------------------------------------------------------*/
164 
165 void CS_PROCF (tstsui, TSTSUI)
166 (
167  const cs_int_t *numsui,
168  cs_int_t *indcel,
169  cs_int_t *indfac,
170  cs_int_t *indfbr,
171  cs_int_t *indsom
172 );
173 
174 /*----------------------------------------------------------------------------
175  * Print index associated with a restart file in read mode
176  *
177  * Fortran interface
178  *
179  * SUBROUTINE INFSUI (NUMSUI)
180  * *****************
181  *
182  * INTEGER NUMSUI : <-- : Restart file number
183  *----------------------------------------------------------------------------*/
184 
185 void CS_PROCF (infsui, INFSUI)
186 (
187  const cs_int_t *numsui
188 );
189 
190 /*----------------------------------------------------------------------------
191  * Read a section from a restart file
192  *
193  * Fortran interface
194  *
195  * subroutine lecsui (numsui, nomrub, lngnom, itysup, nbvent, irtype, tabvar)
196  * *****************
197  *
198  * integer numsui : <-- : Restart file number
199  * character* nomrub : <-- : Section name
200  * integer lngnom : <-- : Section name length
201  * integer itysup : <-- : Location type:
202  * : : 0: scalar (no location)
203  * : : 1: cells
204  * : : 2: interior faces
205  * : : 3: boundary faces
206  * : : 4: vertices (if available)
207  * integer nbvent : <-- : N. values per location entity
208  * integer irtype : <-- : 1 for integers, 2 for double precision
209  * (?) tabvar : <-> : Array of values to read
210  * integer ierror : --> : 0: success, < 0: error code
211  *----------------------------------------------------------------------------*/
212 
213 void CS_PROCF (lecsui, LECSUI)
214 (
215  const cs_int_t *numsui,
216  const char *nomrub,
217  const cs_int_t *lngnom,
218  const cs_int_t *itysup,
219  const cs_int_t *nbvent,
220  const cs_int_t *irtype,
221  void *tabvar,
222  cs_int_t *ierror
223  CS_ARGF_SUPP_CHAINE /* (possible 'length' arguments added
224  by many Fortran compilers) */
225 );
226 
227 /*----------------------------------------------------------------------------
228  * Write a section to a restart file
229  *
230  * Fortran interface
231  *
232  * subroutine ecrsui (numsui, nomrub, lngnom, itysup, nbvent, irtype, tabvar)
233  * *****************
234  *
235  * integer numsui : <-- : Restart file number
236  * character* nomrub : <-- : Section name
237  * integer lngnom : <-- : Section name length
238  * integer itysup : <-- : Location type:
239  * : : 0: scalar (no location)
240  * : : 1: cells
241  * : : 2: interior faces
242  * : : 3: boundary faces
243  * : : 4: vertices (if available)
244  * integer nbvent : <-- : N. values per location entity
245  * integer irtype : <-- : 1 for integers, 2 for double precision
246  * (?) tabvar : <-- : Array of values to write
247  * integer ierror : --> : 0: success, < 0: error code
248  *----------------------------------------------------------------------------*/
249 
250 void CS_PROCF (ecrsui, ECRSUI)
251 (
252  const cs_int_t *numsui,
253  const char *nomrub,
254  const cs_int_t *lngnom,
255  const cs_int_t *itysup,
256  const cs_int_t *nbvent,
257  const cs_int_t *irtype,
258  const void *tabvar,
259  cs_int_t *ierror
260  CS_ARGF_SUPP_CHAINE /* (possible 'length' arguments added
261  by many Fortran compilers) */
262 );
263 
264 /*============================================================================
265  * Public function prototypes
266  *============================================================================*/
267 
268 /*----------------------------------------------------------------------------
269  * Check if we have a restart directory.
270  *
271  * returns:
272  * 1 if a restart directory is present, 0 otherwise.
273  *----------------------------------------------------------------------------*/
274 
275 int
276 cs_restart_present(void);
277 
278 /*----------------------------------------------------------------------------
279  * Initialize a restart file
280  *
281  * parameters:
282  * name <-- file name
283  * path <-- optional directory name for output
284  * (directory automatically created if necessary)
285  * mode <-- read or write
286  *
287  * returns:
288  * pointer to initialized restart file structure
289  *----------------------------------------------------------------------------*/
290 
291 cs_restart_t *
292 cs_restart_create(const char *name,
293  const char *path,
295 
296 /*----------------------------------------------------------------------------
297  * Destroy structure associated with a restart file (and close the file).
298  *
299  * parameters:
300  * restart <-- pointer to restart file structure
301  *
302  * returns:
303  * NULL pointer
304  *----------------------------------------------------------------------------*/
305 
306 cs_restart_t *
308 
309 /*----------------------------------------------------------------------------
310  * Check the locations associated with a restart file.
311  *
312  * For each type of entity, the corresponding flag is set to true if the
313  * associated number of entities matches the current value (and so that we
314  * consider the mesh locations are the same), false otherwise.
315  *
316  * parameters:
317  * restart <-- associated restart file pointer
318  * match_cell <-- matching cells flag
319  * match_i_face <-- matching interior faces flag
320  * match_b_face <-- matching boundary faces flag
321  * match_vertex <-- matching vertices flag
322  *----------------------------------------------------------------------------*/
323 
324 void
326  bool *match_cell,
327  bool *match_i_face,
328  bool *match_b_face,
329  bool *match_vertex);
330 
331 /*----------------------------------------------------------------------------
332  * Add a location definition.
333  *
334  * parameters:
335  * restart <-- associated restart file pointer
336  * location_name <-- name associated with the location
337  * n_glob_ents <-- global number of entities
338  * n_ents <-- local number of entities
339  * ent_global_num <-- global entity numbers, or NULL
340  *
341  * returns:
342  * the location id assigned, or -1 in case of error
343  *----------------------------------------------------------------------------*/
344 
345 int
347  const char *location_name,
348  cs_gnum_t n_glob_ents,
349  cs_lnum_t n_ents,
350  const cs_gnum_t *ent_global_num);
351 
352 /*----------------------------------------------------------------------------
353  * Print the index associated with a restart file in read mode
354  *
355  * parameters:
356  * restart <-- associated restart file pointer
357  *----------------------------------------------------------------------------*/
358 
359 void
360 cs_restart_dump_index(const cs_restart_t *restart);
361 
362 /*----------------------------------------------------------------------------
363  * Read a section from a restart file.
364  *
365  * parameters:
366  * restart <-- associated restart file pointer
367  * sec_name <-- section name
368  * location_id <-- id of corresponding location
369  * n_location_vals <-- number of values per location (interlaced)
370  * val_type <-- value type
371  * val --> array of values
372  *
373  * returns: 0 (CS_RESTART_SUCCES) in case of success,
374  * or error code (CS_RESTART_ERR_xxx) in case of error
375  *----------------------------------------------------------------------------*/
376 
377 int
379  const char *sec_name,
380  int location_id,
381  cs_int_t n_location_vals,
382  cs_type_t val_type,
383  void *val);
384 
385 /*----------------------------------------------------------------------------
386  * Write a section to a restart file.
387  *
388  * parameters:
389  * restart <-- associated restart file pointer
390  * sec_name <-- section name
391  * location_id <-- id of corresponding location
392  * n_location_vals <-- number of values per location (interlaced)
393  * val_type <-- value type
394  * val <-- array of values
395  *----------------------------------------------------------------------------*/
396 
397 void
399  const char *sec_name,
400  int location_id,
401  cs_int_t n_location_vals,
402  cs_type_t val_type,
403  const void *val);
404 
405 /*----------------------------------------------------------------------------
406  * Print statistics associated with restart files
407  *----------------------------------------------------------------------------*/
408 
409 void
411 
412 /*----------------------------------------------------------------------------*/
413 
415 
416 #endif /* __CS_RESTART_H__ */
void cs_restart_dump_index(const cs_restart_t *restart)
Definition: cs_restart.c:1558
void cs_restart_print_stats(void)
Definition: cs_restart.c:1914
cs_restart_t * cs_restart_create(const char *name, const char *path, cs_restart_mode_t mode)
Definition: cs_restart.c:1253
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
integer, save isuite
Definition: optcal.f90:248
void indsui(cs_int_t *isuite)
Definition: cs_restart.c:827
cs_restart_mode_t
Definition: cs_restart.h:64
#define CS_ARGF_SUPP_CHAINE
Definition: cs_defs.h:394
int cs_int_t
Definition: cs_defs.h:263
int cs_restart_present(void)
Definition: cs_restart.c:1229
int cs_lnum_t
Definition: cs_defs.h:260
void infsui(const cs_int_t *numsui)
Definition: cs_restart.c:1036
void ecrsui(const cs_int_t *numsui, const char *nomrub, const cs_int_t *lngnom, const cs_int_t *itysup, const cs_int_t *nbvent, const cs_int_t *irtype, const void *tabvar, cs_int_t *ierror CS_ARGF_SUPP_CHAINE)
Definition: cs_restart.c:1163
unsigned cs_gnum_t
Definition: cs_defs.h:255
void cs_restart_write_section(cs_restart_t *restart, const char *sec_name, int location_id, cs_int_t n_location_vals, cs_type_t val_type, const void *val)
Definition: cs_restart.c:1796
char * name
Definition: cs_restart.c:101
Definition: cs_restart.h:67
void clssui(const cs_int_t *numsui, cs_int_t *ierror)
Definition: cs_restart.c:929
#define END_C_DECLS
Definition: cs_defs.h:366
void opnsui(const char *nomsui, const cs_int_t *lngnom, const cs_int_t *ireawr, cs_int_t *numsui, cs_int_t *ierror CS_ARGF_SUPP_CHAINE)
Definition: cs_restart.c:850
int cs_restart_read_section(cs_restart_t *restart, const char *sec_name, int location_id, cs_int_t n_location_vals, cs_type_t val_type, void *val)
Definition: cs_restart.c:1598
cs_restart_t * cs_restart_destroy(cs_restart_t *restart)
Definition: cs_restart.c:1361
#define CS_PROCF(x, y)
Definition: cs_defs.h:379
void lecsui(const cs_int_t *numsui, const char *nomrub, const cs_int_t *lngnom, const cs_int_t *itysup, const cs_int_t *nbvent, const cs_int_t *irtype, void *tabvar, cs_int_t *ierror CS_ARGF_SUPP_CHAINE)
Definition: cs_restart.c:1084
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)
Definition: cs_restart.c:1413
Definition: cs_restart.c:99
Definition: cs_restart.h:66
cs_restart_mode_t mode
Definition: cs_restart.c:108
void tstsui(const cs_int_t *numsui, cs_int_t *indcel, cs_int_t *indfac, cs_int_t *indfbr, cs_int_t *indsom)
Definition: cs_restart.c:979
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)
Definition: cs_restart.c:1471
cs_type_t
Definition: cs_base.h:78