libMesh
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::CheckpointIO Class Reference

The CheckpointIO class can be used to write simplified restart files that can be used to restart simulations that have crashed. More...

#include <checkpoint_io.h>

Inheritance diagram for libMesh::CheckpointIO:
[legend]

Public Types

typedef largest_id_type xdr_id_type
 
typedef uint64_t header_id_type
 

Public Member Functions

 CheckpointIO (MeshBase &, const bool=false)
 Constructor. More...
 
 CheckpointIO (const MeshBase &, const bool=false)
 Constructor. More...
 
virtual ~CheckpointIO ()
 Destructor. More...
 
virtual void read (const std::string &input_name) override
 This method implements reading a mesh from a specified file. More...
 
virtual void write (const std::string &name) override
 This method implements writing a mesh to a specified file. More...
 
bool binary () const
 Get/Set the flag indicating if we should read/write binary. More...
 
bool & binary ()
 
bool parallel () const
 Get/Set the flag indicating if we should read/write binary. More...
 
bool & parallel ()
 
const std::string & version () const
 Get/Set the version string. More...
 
std::string & version ()
 
const std::vector< processor_id_type > & current_processor_ids () const
 Get/Set the processor id or processor ids to use. More...
 
std::vector< processor_id_type > & current_processor_ids ()
 
const processor_id_typecurrent_n_processors () const
 Get/Set the n_processors to use. More...
 
processor_id_typecurrent_n_processors ()
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided. More...
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 This method should be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided. More...
 
unsigned int & ascii_precision ()
 Return/set the precision to use when writing ASCII files. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static void cleanup (const std::string &input_name, processor_id_type n_procs)
 Used to remove a checkpoint directory and its corresponding files. More...
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 Sets the number of partitions in the mesh. More...
 
void skip_comment_lines (std::istream &in, const char comment_start)
 Reads input from in, skipping all the lines that start with the character comment_start. More...
 
const MeshBasemesh () const
 

Protected Attributes

std::vector< bool > elems_of_dimension
 A vector of bools describing what dimension elements have been encountered when reading a mesh. More...
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable. More...
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero. More...
 
const Parallel::Communicator_communicator
 

Private Member Functions

void write_subdomain_names (Xdr &io) const
 Write subdomain name information. More...
 
void write_connectivity (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
 Write the connectivity for part of a mesh. More...
 
void write_remote_elem (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
 Write the remote_elem neighbor and child links for part of a mesh. More...
 
void write_nodes (Xdr &io, const std::set< const Node *> &nodeset) const
 Write the nodal locations for part of a mesh. More...
 
void write_bcs (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements, const std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type >> &bc_triples) const
 Write the side boundary conditions for part of a mesh. More...
 
void write_nodesets (Xdr &io, const std::set< const Node *> &nodeset, const std::vector< std::tuple< dof_id_type, boundary_id_type >> &bc_tuples) const
 Write the nodal boundary conditions for part of a mesh. More...
 
void write_bc_names (Xdr &io, const BoundaryInfo &info, bool is_sideset) const
 Write boundary names information (sideset and nodeset) More...
 
template<typename file_id_type >
file_id_type read_header (const std::string &name)
 Read header data on processor 0, then broadcast. More...
 
template<typename file_id_type >
void read_subfile (Xdr &io, bool expect_all_remote)
 Read a non-header file. More...
 
template<typename file_id_type >
void read_subdomain_names (Xdr &io)
 Read subdomain name information. More...
 
template<typename file_id_type >
void read_connectivity (Xdr &io)
 Read the connectivity for a parallel, distributed mesh. More...
 
template<typename file_id_type >
void read_remote_elem (Xdr &io, bool expect_all_remote)
 Read the remote_elem neighbor and child links for a parallel, distributed mesh. More...
 
template<typename file_id_type >
void read_nodes (Xdr &io)
 Read the nodal locations for a parallel, distributed mesh. More...
 
template<typename file_id_type >
void read_bcs (Xdr &io)
 Read the boundary conditions for a parallel, distributed mesh. More...
 
template<typename file_id_type >
void read_nodesets (Xdr &io)
 Read the nodeset conditions for a parallel, distributed mesh. More...
 
template<typename file_id_type >
void read_bc_names (Xdr &io, BoundaryInfo &info, bool is_sideset)
 Read boundary names information (sideset and nodeset) More...
 
unsigned int n_active_levels_in (MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
 
processor_id_type select_split_config (const std::string &input_name, header_id_type &data_size)
 

Private Attributes

bool _binary
 
bool _parallel
 
std::string _version
 
std::vector< processor_id_type_my_processor_ids
 
processor_id_type _my_n_processors
 

Detailed Description

The CheckpointIO class can be used to write simplified restart files that can be used to restart simulations that have crashed.

Author
Benjamin Kirk
John Peterson
Derek Gaston
Roy Stogner
Date
2017

Definition at line 60 of file checkpoint_io.h.

Member Typedef Documentation

◆ header_id_type

Definition at line 69 of file checkpoint_io.h.

◆ xdr_id_type

Definition at line 66 of file checkpoint_io.h.

Constructor & Destructor Documentation

◆ CheckpointIO() [1/2]

libMesh::CheckpointIO::CheckpointIO ( MeshBase ,
const bool  = false 
)
explicit

Constructor.

Takes a writable reference to a mesh object. This is the constructor required to read a mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.

◆ CheckpointIO() [2/2]

libMesh::CheckpointIO::CheckpointIO ( const MeshBase ,
const bool  = false 
)
explicit

Constructor.

Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.

◆ ~CheckpointIO()

virtual libMesh::CheckpointIO::~CheckpointIO ( )
virtual

Destructor.

Member Function Documentation

◆ ascii_precision()

unsigned int & libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 244 of file mesh_output.h.

245 {
246  return _ascii_precision;
247 }
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:182

◆ binary() [1/2]

bool libMesh::CheckpointIO::binary ( ) const

Get/Set the flag indicating if we should read/write binary.

Definition at line 145 of file checkpoint_io.h.

References _binary.

145 { return _binary; }

◆ binary() [2/2]

bool& libMesh::CheckpointIO::binary ( )

Definition at line 146 of file checkpoint_io.h.

References _binary.

146 { return _binary; }

◆ cleanup()

static void libMesh::CheckpointIO::cleanup ( const std::string &  input_name,
processor_id_type  n_procs 
)
static

Used to remove a checkpoint directory and its corresponding files.

This effectively undoes all the work done be calls to write(...). For example, if a checkpoint configuration was written via:

unsigned int n_splits = 42;
std::unique_ptr<CheckpointIO> cp = split_mesh(my_mesh, n_splits);
// ...
cp->write("foo.cpr");

then you could remove all the corresponding created files/dirs by:

CheckpointIO::cleanup(my_mesh, n_splits);

Or for cases where the split configuration was determined automatically (e.g. via number of running procs with distributed/parallel mesh), then you could:

CheckpointIO::cleanup(your_mesh, your_mesh.comm().size());

Other remaining checkpoint split configurations for the mesh are left unmodified.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ current_n_processors() [1/2]

const processor_id_type& libMesh::CheckpointIO::current_n_processors ( ) const

Get/Set the n_processors to use.

The default n_processors to use is the n_processors() of the mesh.

This is used for m->n parallel checkpoint file writing: You can force CheckpointIO to view the world as if it contains this number of processors by setting it here

Definition at line 183 of file checkpoint_io.h.

References _my_n_processors.

183 { return _my_n_processors; }
processor_id_type _my_n_processors

◆ current_n_processors() [2/2]

processor_id_type& libMesh::CheckpointIO::current_n_processors ( )

Definition at line 184 of file checkpoint_io.h.

References _my_n_processors.

184 { return _my_n_processors; }
processor_id_type _my_n_processors

◆ current_processor_ids() [1/2]

const std::vector<processor_id_type>& libMesh::CheckpointIO::current_processor_ids ( ) const

Get/Set the processor id or processor ids to use.

The default processor_id to use is the processor_id() of the mesh.

This is used for m->n parallel checkpoint file writing: You can force CheckpointIO to write out different partitions of a mesh by setting which partitions to write from each processor here.

Definition at line 170 of file checkpoint_io.h.

References _my_processor_ids.

170 { return _my_processor_ids; }
std::vector< processor_id_type > _my_processor_ids

◆ current_processor_ids() [2/2]

std::vector<processor_id_type>& libMesh::CheckpointIO::current_processor_ids ( )

Definition at line 171 of file checkpoint_io.h.

References _my_processor_ids.

171 { return _my_processor_ids; }
std::vector< processor_id_type > _my_processor_ids

◆ mesh() [1/2]

MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
protectedinherited
Returns
The object as a writable reference.

Definition at line 169 of file mesh_input.h.

Referenced by libMesh::XdrIO::write_parallel().

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }
MeshBase * _obj
A pointer to a non-const object object.
Definition: mesh_input.h:114

◆ mesh() [2/2]

const MeshBase & libMesh::MeshOutput< MeshBase >::mesh ( ) const
protectedinherited
Returns
The object as a read-only reference.

Definition at line 234 of file mesh_output.h.

235 {
236  libmesh_assert(_obj);
237  return *_obj;
238 }
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:177

◆ n_active_levels_in()

unsigned int libMesh::CheckpointIO::n_active_levels_in ( MeshBase::const_element_iterator  begin,
MeshBase::const_element_iterator  end 
) const
private
Returns
The number of levels of refinement in the active mesh on this processor.
Note
This includes all elements on this processor even those not owned by this processor! Implemented by looping over all the active elements and finding the maximum level.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ parallel() [1/2]

bool libMesh::CheckpointIO::parallel ( ) const

Get/Set the flag indicating if we should read/write binary.

Definition at line 151 of file checkpoint_io.h.

References _parallel.

151 { return _parallel; }

◆ parallel() [2/2]

bool& libMesh::CheckpointIO::parallel ( )

Definition at line 152 of file checkpoint_io.h.

References _parallel.

152 { return _parallel; }

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ read()

virtual void libMesh::CheckpointIO::read ( const std::string &  input_name)
overridevirtual

This method implements reading a mesh from a specified file.

If the mesh has been split for running on several processors, input_name should simply be the name of the mesh split directory without the "-split[n]" suffix. The number of splits will be determined automatically by the number of processes being used for the mesh at the time of reading.

Implements libMesh::MeshInput< MeshBase >.

◆ read_bc_names()

template<typename file_id_type >
void libMesh::CheckpointIO::read_bc_names ( Xdr io,
BoundaryInfo info,
bool  is_sideset 
)
private

Read boundary names information (sideset and nodeset)

◆ read_bcs()

template<typename file_id_type >
void libMesh::CheckpointIO::read_bcs ( Xdr io)
private

Read the boundary conditions for a parallel, distributed mesh.

◆ read_connectivity()

template<typename file_id_type >
void libMesh::CheckpointIO::read_connectivity ( Xdr io)
private

Read the connectivity for a parallel, distributed mesh.

◆ read_header()

template<typename file_id_type >
file_id_type libMesh::CheckpointIO::read_header ( const std::string &  name)
private

Read header data on processor 0, then broadcast.

Returns the number of processors for which parallel non-header files have been written, or 0 if files were written in serial.

◆ read_nodes()

template<typename file_id_type >
void libMesh::CheckpointIO::read_nodes ( Xdr io)
private

Read the nodal locations for a parallel, distributed mesh.

◆ read_nodesets()

template<typename file_id_type >
void libMesh::CheckpointIO::read_nodesets ( Xdr io)
private

Read the nodeset conditions for a parallel, distributed mesh.

◆ read_remote_elem()

template<typename file_id_type >
void libMesh::CheckpointIO::read_remote_elem ( Xdr io,
bool  expect_all_remote 
)
private

Read the remote_elem neighbor and child links for a parallel, distributed mesh.

If we expect all these remote_elem links to truly be remote, because we aren't doing an N -> M restart with M < N, then we set expect_all_remote to true and test more assertions.

◆ read_subdomain_names()

template<typename file_id_type >
void libMesh::CheckpointIO::read_subdomain_names ( Xdr io)
private

Read subdomain name information.

◆ read_subfile()

template<typename file_id_type >
void libMesh::CheckpointIO::read_subfile ( Xdr io,
bool  expect_all_remote 
)
private

Read a non-header file.

◆ select_split_config()

processor_id_type libMesh::CheckpointIO::select_split_config ( const std::string &  input_name,
header_id_type data_size 
)
private

◆ set_n_partitions()

void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
protectedinherited

Sets the number of partitions in the mesh.

Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 91 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

91 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1371

◆ skip_comment_lines()

void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Definition at line 179 of file mesh_input.h.

181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }

◆ version() [1/2]

const std::string& libMesh::CheckpointIO::version ( ) const

Get/Set the version string.

Definition at line 157 of file checkpoint_io.h.

References _version.

157 { return _version; }

◆ version() [2/2]

std::string& libMesh::CheckpointIO::version ( )

Definition at line 158 of file checkpoint_io.h.

References _version.

158 { return _version; }

◆ write()

virtual void libMesh::CheckpointIO::write ( const std::string &  name)
overridevirtual

This method implements writing a mesh to a specified file.

If the mesh has been split for running on several processors, this will create a subdirectory named "[name]-split[n]" where name is the given name argument and n is the number of processors the mesh is split for running on. For example:

unsigned int n_splits = 42;
std::unique_ptr<CheckpointIO> cp = split_mesh(my_mesh, n_splits);
// ...
cp->write("foo.cpr");

would create a directory named "foo.cpr-split42".

Implements libMesh::MeshOutput< MeshBase >.

◆ write_bc_names()

void libMesh::CheckpointIO::write_bc_names ( Xdr io,
const BoundaryInfo info,
bool  is_sideset 
) const
private

Write boundary names information (sideset and nodeset)

◆ write_bcs()

void libMesh::CheckpointIO::write_bcs ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements,
const std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type >> &  bc_triples 
) const
private

Write the side boundary conditions for part of a mesh.

◆ write_connectivity()

void libMesh::CheckpointIO::write_connectivity ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements 
) const
private

Write the connectivity for part of a mesh.

◆ write_discontinuous_equation_systems()

virtual void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object.

◆ write_equation_systems()

virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

◆ write_nodal_data() [1/2]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::Nemesis_IO, libMesh::UCDIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::GMVIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 105 of file mesh_output.h.

108  { libmesh_not_implemented(); }

◆ write_nodal_data() [2/2]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

◆ write_nodal_data_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

◆ write_nodes()

void libMesh::CheckpointIO::write_nodes ( Xdr io,
const std::set< const Node *> &  nodeset 
) const
private

Write the nodal locations for part of a mesh.

◆ write_nodesets()

void libMesh::CheckpointIO::write_nodesets ( Xdr io,
const std::set< const Node *> &  nodeset,
const std::vector< std::tuple< dof_id_type, boundary_id_type >> &  bc_tuples 
) const
private

Write the nodal boundary conditions for part of a mesh.

◆ write_remote_elem()

void libMesh::CheckpointIO::write_remote_elem ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements 
) const
private

Write the remote_elem neighbor and child links for part of a mesh.

◆ write_subdomain_names()

void libMesh::CheckpointIO::write_subdomain_names ( Xdr io) const
private

Write subdomain name information.

Member Data Documentation

◆ _binary

bool libMesh::CheckpointIO::_binary
private

Definition at line 309 of file checkpoint_io.h.

Referenced by binary().

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _is_parallel_format

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable.

If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 159 of file mesh_output.h.

◆ _my_n_processors

processor_id_type libMesh::CheckpointIO::_my_n_processors
private

Definition at line 317 of file checkpoint_io.h.

Referenced by current_n_processors().

◆ _my_processor_ids

std::vector<processor_id_type> libMesh::CheckpointIO::_my_processor_ids
private

Definition at line 314 of file checkpoint_io.h.

Referenced by current_processor_ids().

◆ _parallel

bool libMesh::CheckpointIO::_parallel
private

Definition at line 310 of file checkpoint_io.h.

Referenced by parallel().

◆ _serial_only_needed_on_proc_0

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero.

If this is false (default) the mesh will be serialized to all processors

Definition at line 168 of file mesh_output.h.

◆ _version

std::string libMesh::CheckpointIO::_version
private

Definition at line 311 of file checkpoint_io.h.

Referenced by version().

◆ elems_of_dimension

std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension
protectedinherited

A vector of bools describing what dimension elements have been encountered when reading a mesh.

Definition at line 97 of file mesh_input.h.


The documentation for this class was generated from the following file: