My Project
programmer's documentation
Functions
cs_restart.c File Reference
#include "cs_defs.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <mpi.h>
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "fvm_io_num.h"
#include "cs_base.h"
#include "cs_block_dist.h"
#include "cs_block_to_part.h"
#include "cs_file.h"
#include "cs_io.h"
#include "cs_mesh.h"
#include "cs_mesh_save.h"
#include "cs_mesh_location.h"
#include "cs_part_to_block.h"
#include "cs_parall.h"
#include "cs_timer.h"
#include "cs_time_step.h"
#include "cs_restart.h"
Include dependency graph for cs_restart.c:

Functions

void CS_PROCF (dflsui, DFLSUI)
 
void CS_PROCF (reqsui, REQSUI)
 
void CS_PROCF (stusui, STUSUI)
 
void CS_PROCF (trbsui, TRBSUI)
 
void CS_PROCF (indsui, INDSUI)
 
void cs_restart_checkpoint_set_defaults (int nt_interval, double t_interval, double wt_interval)
 Define default checkpoint interval. More...
 
void cs_restart_checkpoint_set_mesh_mode (int mode)
 Define checkpoint behavior for mesh. More...
 
void cs_restart_checkpoint_set_last_ts (int nt_last)
 Define last forced checkpoint time step. More...
 
void cs_restart_checkpoint_set_next_ts (int nt_next)
 Define next forced checkpoint time step. More...
 
void cs_restart_checkpoint_set_next_tv (double t_next)
 Define next forced checkpoint time value. More...
 
void cs_restart_checkpoint_set_next_wt (double wt_next)
 Define next forced checkpoint wall-clock time value. More...
 
bool cs_restart_checkpoint_required (const cs_time_step_t *ts)
 Check if checkpointing is recommended at a given time. More...
 
void cs_restart_checkpoint_done (const cs_time_step_t *ts)
 Indicate checkpointing has been done at a given time. More...
 
int cs_restart_present (void)
 Check if we have a restart directory. More...
 
cs_restart_tcs_restart_create (const char *name, const char *path, cs_restart_mode_t mode)
 Initialize a restart file. More...
 
void cs_restart_destroy (cs_restart_t **restart)
 Destroy structure associated with a restart file (and close the file). More...
 
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. More...
 
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. More...
 
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. More...
 
void cs_restart_clear_locations_ref (void)
 Clear reference location definitions with a private copy. More...
 
void cs_restart_set_context (void *context)
 Associate a context to restart section check operations. More...
 
cs_restart_check_section_tcs_restart_set_check_section_func (cs_restart_check_section_t *func)
 Associate a function to restart section check operations. More...
 
cs_restart_read_section_tcs_restart_set_read_section_func (cs_restart_read_section_t *func)
 Associate a function and its input to all restart section read operations. More...
 
cs_restart_write_section_tcs_restart_set_write_section_func (cs_restart_write_section_t *func)
 Associate a function and its input to all restart section write operations. More...
 
const char * cs_restart_get_name (const cs_restart_t *restart)
 Return name of restart file. More...
 
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. More...
 
void cs_restart_dump_index (const cs_restart_t *restart)
 Print the index associated with a restart file in read mode. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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 version. More...
 
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 name and been non-interleaved in a previous version. More...
 
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 name and been non-interleaved in a previous version. More...
 
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 name and been non-interleaved in a previous version. More...
 
void cs_restart_print_stats (void)
 Print statistics associated with restart files. More...
 

Detailed Description

Manage checkpoint / restart files.

Function Documentation

◆ CS_PROCF() [1/5]

void CS_PROCF ( dflsui  ,
DFLSUI   
)

◆ CS_PROCF() [2/5]

void CS_PROCF ( indsui  ,
INDSUI   
)

◆ CS_PROCF() [3/5]

void CS_PROCF ( reqsui  ,
REQSUI   
)

◆ CS_PROCF() [4/5]

void CS_PROCF ( stusui  ,
STUSUI   
)

◆ CS_PROCF() [5/5]

void CS_PROCF ( trbsui  ,
TRBSUI   
)

◆ cs_restart_add_location()

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.

Parameters
[in]restartassociated restart file pointer
[in]location_namename associated with the location
[in]n_glob_entsglobal number of entities
[in]n_entslocal number of entities
[in]ent_global_numglobal entity numbers, or NULL
Returns
the location id assigned, or -1 in case of error

◆ cs_restart_add_location_ref()

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.

Parameters
[in]location_namename associated with the location
[in]n_glob_entsglobal number of entities
[in]n_entslocal number of entities
[in]ent_global_numglobal entity numbers, or NULL
Returns
the location id assigned, or -1 in case of error

◆ cs_restart_check_base_location()

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.

For each type of entity, the corresponding flag is set to true if the associated number of entities matches the current value (and so that we consider the mesh locations are the same), false otherwise.

Parameters
[out]restartassociated restart file pointer
[out]match_cellmatching cells flag
[out]match_i_facematching interior faces flag
[out]match_b_facematching boundary faces flag
[out]match_vertexmatching vertices flag

◆ cs_restart_check_section()

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.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of corresponding location
[in]n_location_valsnumber of values per location (interlaced)
[in]val_typevalue type
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_checkpoint_done()

void cs_restart_checkpoint_done ( const cs_time_step_t ts)

Indicate checkpointing has been done at a given time.

This updates the status for future checks to determine if checkpointing is recommended at a given time.

Parameters
[in]tstime step status structure

◆ cs_restart_checkpoint_required()

bool cs_restart_checkpoint_required ( const cs_time_step_t ts)

Check if checkpointing is recommended at a given time.

Parameters
[in]tstime step status structure
Returns
true if checkpointing is recommended, false otherwise

◆ cs_restart_checkpoint_set_defaults()

void cs_restart_checkpoint_set_defaults ( int  nt_interval,
double  t_interval,
double  wt_interval 
)

Define default checkpoint interval.

Parameters
[in]nt_intervalif > 0 time step interval for checkpoint if 0, default of 4 checkpoints per run if -1, checkpoint at end if -2, no checkpointing
[in]t_intervalif > 0, time value interval for checkpoint
[in]wt_intervalif > 0, wall-clock interval for checkpoints

◆ cs_restart_checkpoint_set_last_ts()

void cs_restart_checkpoint_set_last_ts ( int  nt_last)

Define last forced checkpoint time step.

Parameters
[in]nt_lastlast time step for forced checkpoint

◆ cs_restart_checkpoint_set_mesh_mode()

void cs_restart_checkpoint_set_mesh_mode ( int  mode)

Define checkpoint behavior for mesh.

If mesh checkpointing is active (default), upon writing the first checkpoint file of a computation, a mesh_output file is moved to checkpoint/mesh_input if present. If not present but a mesh_input file (or link to file) is present, a hard link to that file is added as checkpoint/mesh_input.

A mesh_input directory is ignored, as it is normally only created when multiple input files are appended, which leads to the output and thus presence of a mesh_output file, unless explicitely deactivated by the user.

Parameters
[in]modeif 0, do not checkpoint mesh if 1, checkpoint mesh_output or mesh_input file

◆ cs_restart_checkpoint_set_next_ts()

void cs_restart_checkpoint_set_next_ts ( int  nt_next)

Define next forced checkpoint time step.

Parameters
[in]nt_nextnext time step for forced checkpoint

◆ cs_restart_checkpoint_set_next_tv()

void cs_restart_checkpoint_set_next_tv ( double  t_next)

Define next forced checkpoint time value.

Parameters
[in]t_nextnext time value for forced checkpoint

◆ cs_restart_checkpoint_set_next_wt()

void cs_restart_checkpoint_set_next_wt ( double  wt_next)

Define next forced checkpoint wall-clock time value.

Parameters
[in]wt_nextnext wall-clock time value for forced checkpoint

◆ cs_restart_clear_locations_ref()

void cs_restart_clear_locations_ref ( void  )

Clear reference location definitions with a private copy.

◆ cs_restart_create()

cs_restart_t* cs_restart_create ( const char *  name,
const char *  path,
cs_restart_mode_t  mode 
)

Initialize a restart file.

Parameters
[in]namefile name
[in]pathoptional directory name for output, or NULL for default (directory automatically created if necessary)
[in]moderead or write
Returns
pointer to initialized restart file structure

◆ cs_restart_destroy()

void cs_restart_destroy ( cs_restart_t **  restart)

Destroy structure associated with a restart file (and close the file).

Parameters
[in,out]restartpointer to restart file structure pointer

◆ cs_restart_dump_index()

void cs_restart_dump_index ( const cs_restart_t restart)

Print the index associated with a restart file in read mode.

Parameters
[in]restartassociated restart file pointer

◆ cs_restart_get_n_location_elts()

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.

Parameters
[in]restartassociated restart file pointer
[in]location_idid of corresponding location
Returns
number of elements associated with location.

◆ cs_restart_get_name()

const char* cs_restart_get_name ( const cs_restart_t restart)

Return name of restart file.

Parameters
[in]restartassociated restart file pointer
Returns
base name of restart file

◆ cs_restart_present()

int cs_restart_present ( void  )

Check if we have a restart directory.

Returns
1 if a restart directory is present, 0 otherwise

◆ cs_restart_print_stats()

void cs_restart_print_stats ( void  )

Print statistics associated with restart files.

◆ cs_restart_read_ids()

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.

The section read from file contains the global ids matching the local element ids of a given location. Global id's are transformed to local ids by this function.

In case global referenced ids read do not match those of local elements, id_base - 1 is assigned to the corresponding local ids.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of location on which id_ref is defined
[in]ref_location_idid of referenced location
[in]ref_id_basebase of location entity id numbers (usually 0 or 1)
[out]ref_idarray of location entity ids
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_particles()

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.

Parameters
[in]restartassociated restart file pointer
[in]particles_location_idlocation id of particles set
[out]particle_cell_idlocal cell id to which particles belong
[out]particle_coordslocal particle coordinates (interleaved)
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_particles_info()

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.

This includes building a matching location and associated global numbering.

Parameters
[in]restartassociated restart file pointer
[in]namename of particles set
[out]n_particlesnumber of particles, or NULL
Returns
the location id assigned to the particles, or -1 in case of error

◆ cs_restart_read_real_3_t_compat()

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 name and been non-interleaved in a previous version.

This function assumes a mesh-base location (i.e. location_id > 0)

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]old_name_xold name, x component
[in]old_name_yold name, y component
[in]old_name_yold name, z component
[in]location_idid of corresponding location
[out]valarray of values
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_real_66_t_compat()

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 name and been non-interleaved in a previous version.

This function assumes a mesh-base location (i.e. location_id > 0)

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]old_name_xxold name, xx component
[in]old_name_yyold name, yy component
[in]old_name_zzold name, zz component
[in]old_name_xyold name, xy component
[in]old_name_yzold name, yz component
[in]old_name_xzold name, xz component
[in]location_idid of corresponding location
[out]valarray of values
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_real_6_t_compat()

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 name and been non-interleaved in a previous version.

This function assumes a mesh-base location (i.e. location_id > 0)

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]old_name_xxold name, xx component
[in]old_name_yyold name, yy component
[in]old_name_zzold name, zz component
[in]old_name_xyold name, xy component
[in]old_name_yzold name, yz component
[in]old_name_xzold name, xz component
[in]location_idid of corresponding location
[out]valarray of values
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_section()

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.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of corresponding location
[in]n_location_valsnumber of values per location (interlaced)
[in]val_typevalue type
[out]valarray of values
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_read_section_compat()

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 version.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of corresponding location
[in]n_location_valsnumber of values per location (interlaced)
[in]val_typevalue type
[out]valarray of values
Returns
0 (CS_RESTART_SUCCESS) in case of success, or error code (CS_RESTART_ERR_xxx) in case of error

◆ cs_restart_set_check_section_func()

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.

This allows defining alternate operations when checking restart sections.

Parameters
[in]funcassociated function
Returns
pointer to previous function

◆ cs_restart_set_context()

void cs_restart_set_context ( void *  context)

Associate a context to restart section check operations.

This context may be used by the cs_restart_check_section_t, cs_restart_read_section_t, and cs_restart_write_section_t type functions.

Note that the lifecycle of the data pointed to must be handled separately (and the pointer must remain valid until the matching restart structure is destroyed.

Parameters
[in]contextpointer to associated data, or NULL

◆ cs_restart_set_read_section_func()

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.

This allows defining alternate operations when reading restart sections.

Parameters
[in]funcassociated function
Returns
pointer to previous function

◆ cs_restart_set_write_section_func()

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.

This allows defining alternate operations when writing restart sections.

Parameters
[in]funcassociated hook function
Returns
pointer to previous function

◆ cs_restart_write_ids()

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.

The section written to file contains the global ids matching the local element ids of a given location.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of location on which id_ref is defined
[in]ref_location_idid of referenced location
[in]ref_id_basebase of location entity id numbers (usually 0 or 1)
[in]ref_idarray of location entity ids

◆ cs_restart_write_particles()

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.

This includes defining a matching location and associated global numbering, then writing particle coordinates and cell ids.

Parameters
[in]restartassociated restart file pointer
[in]namename of particles set
[in]number_by_coordsif true, numbering is based on current coordinates; otherwise, it is simply based on local numbers, plus the sum of particles on lower MPI ranks
[in]n_particleslocal number of particles
[in]particle_cell_idlocal cell id (0 to n-1) to which particles belong
[in]particle_coordslocal particle coordinates (interleaved)
Returns
the location id assigned to the particles

◆ cs_restart_write_section()

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.

Parameters
[in]restartassociated restart file pointer
[in]sec_namesection name
[in]location_idid of corresponding location
[in]n_location_valsnumber of values per location (interlaced)
[in]val_typevalue type
[in]valarray of values