~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to src/base/cs_restart.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-01 17:43:32 UTC
  • mto: (6.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20111101174332-tl4vk45no0x3emc3
Tags: upstream-2.1.0
ImportĀ upstreamĀ versionĀ 2.1.0

Show diffs side-by-side

added added

removed removed

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