libMesh
Loading...
Searching...
No Matches
checkpoint_io.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_CHECKPOINT_IO_H
21#define LIBMESH_CHECKPOINT_IO_H
22
23
24// Local includes
25#include "libmesh/compare_elems_by_level.h"
26#include "libmesh/mesh_input.h"
27#include "libmesh/mesh_output.h"
28#include "libmesh/mesh_communication.h"
29#include "libmesh/parallel_object.h"
30
31// C++ includes
32#include <string>
33#include <vector>
34
35namespace libMesh
36{
37// Forward declarations
38class Xdr;
39class CheckpointIO;
40
48std::unique_ptr<CheckpointIO> split_mesh(MeshBase & mesh, processor_id_type nsplits);
49
61class CheckpointIO : public MeshInput<MeshBase>,
62 public MeshOutput<MeshBase>,
63 public ParallelObject
64{
65public:
66 // The size used for encoding all id types in this file
68
69 // The size type used to read header sizes (meta data information)
70 typedef uint64_t header_id_type;
71
79 explicit
80 CheckpointIO (MeshBase &, const bool=false);
81
89 explicit
90 CheckpointIO (const MeshBase &, const bool=false);
91
95 virtual ~CheckpointIO ();
96
103 virtual void read (const std::string & input_name) override;
104
118 virtual void write (const std::string & name) override;
119
141 static void cleanup(const std::string & input_name, processor_id_type n_procs);
142
146 bool binary() const { return _binary; }
147 bool & binary() { return _binary; }
148
152 bool parallel() const { return _parallel; }
153 bool & parallel() { return _parallel; }
154
158 const std::string & version () const { return _version; }
159 std::string & version () { return _version; }
160
168 bool version_at_least_1_5() const;
169
176 bool version_at_least_1_6() const;
177
184 bool version_at_least_1_7() const;
185
196 const std::vector<processor_id_type> & current_processor_ids() const { return _my_processor_ids; }
197 std::vector<processor_id_type> & current_processor_ids() { return _my_processor_ids; }
198
211
212private:
213 //---------------------------------------------------------------------------
214 // Write Implementation
215
219 void write_subdomain_names(Xdr & io) const;
220
224 void write_connectivity (Xdr & io,
225 const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
226
230 void write_remote_elem (Xdr & io,
231 const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
232
236 void write_nodes (Xdr & io,
237 const connected_node_set_type & nodeset) const;
238
242 void write_bcs (Xdr & io,
243 const std::set<const Elem *, CompareElemIdsByLevel> & elements,
244 const std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> & bc_triples) const;
245
249 void write_nodesets (Xdr & io,
250 const connected_node_set_type & nodeset,
251 const std::vector<std::tuple<dof_id_type, boundary_id_type>> & bc_tuples) const;
252
256 void write_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
257
262
263
264 //---------------------------------------------------------------------------
265 // Read Implementation
266
272 template <typename file_id_type>
273 file_id_type read_header(const std::string & name);
274
278 template <typename file_id_type>
279 void read_subfile(Xdr & io, bool expect_all_remote);
280
284 template <typename file_id_type>
285 void read_subdomain_names(Xdr & io);
286
290 template <typename file_id_type>
291 void read_connectivity (Xdr & io);
292
300 template <typename file_id_type>
301 void read_remote_elem (Xdr & io, bool expect_all_remote);
302
306 template <typename file_id_type>
307 void read_nodes (Xdr & io);
308
312 template <typename file_id_type>
313 void read_bcs (Xdr & io);
314
318 template <typename file_id_type>
319 void read_nodesets (Xdr & io);
320
324 template <typename file_id_type>
325 void read_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
326
332 template <typename file_id_type>
334 (Xdr & io,
335 std::vector<file_id_type> & pair_ids,
336 std::vector<Real> & translations);
337
341 template <typename file_id_type>
343 (Xdr & io,
344 std::vector<std::string> & node_integer_names,
345 std::vector<std::string> & elem_integer_names);
346
357
358 processor_id_type select_split_config(const std::string & input_name, header_id_type & data_size);
359
362 std::string _version;
363
364 // The processor ids to write
365 std::vector<processor_id_type> _my_processor_ids;
366
367 // The largest processor id to write
369};
370
371
372} // namespace libMesh
373
374#endif // LIBMESH_CHECKPOINT_IO_H
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
void read_nodes(Xdr &io)
Read the nodal locations for a parallel, distributed mesh.
processor_id_type _my_n_processors
std::string & version()
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Write boundary names information (sideset and nodeset)
largest_id_type xdr_id_type
file_id_type read_header(const std::string &name)
Read header data on processor 0, then broadcast.
void write_nodesets(Xdr &io, const connected_node_set_type &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.
void read_subdomain_names(Xdr &io)
Read subdomain name information.
processor_id_type select_split_config(const std::string &input_name, header_id_type &data_size)
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the connectivity for part of a mesh.
bool version_at_least_1_6() const
virtual ~CheckpointIO()
Destructor.
void read_disjoint_neighbor_boundary_pairs(Xdr &io, std::vector< file_id_type > &pair_ids, std::vector< Real > &translations)
Read disjoint neighbor boundary pairs: the two boundary ids of each pair, and the LIBMESH_DIM transla...
void write_subdomain_names(Xdr &io) const
Write subdomain name information.
std::vector< processor_id_type > & current_processor_ids()
void read_connectivity(Xdr &io)
Read the connectivity for a parallel, distributed mesh.
void write_nodes(Xdr &io, const connected_node_set_type &nodeset) const
Write the nodal locations for part of a mesh.
processor_id_type & current_n_processors()
void read_bcs(Xdr &io)
Read the boundary conditions for a parallel, distributed mesh.
void read_remote_elem(Xdr &io, bool expect_all_remote)
Read the remote_elem neighbor and child links for a parallel, distributed mesh.
void read_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Read boundary names information (sideset and nodeset)
std::vector< processor_id_type > _my_processor_ids
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.
void read_integers_names(Xdr &io, std::vector< std::string > &node_integer_names, std::vector< std::string > &elem_integer_names)
Read extra integers names information.
void read_nodesets(Xdr &io)
Read the nodeset conditions for a parallel, distributed mesh.
const std::vector< processor_id_type > & current_processor_ids() const
Get/Set the processor id or processor ids to use.
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
bool binary() const
Get/Set the flag indicating if we should read/write binary.
const processor_id_type & current_n_processors() const
Get/Set the n_processors to use.
static void cleanup(const std::string &input_name, processor_id_type n_procs)
Used to remove a checkpoint directory and its corresponding files.
const std::string & version() const
Get/Set the version string.
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
void read_subfile(Xdr &io, bool expect_all_remote)
Read a non-header file.
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.
bool parallel() const
Get/Set the flag indicating if we should read/write binary.
bool version_at_least_1_7() const
void write_disjoint_neighbor_boundary_pairs(Xdr &io) const
Write disjoint neighbor boundary pairs.
bool version_at_least_1_5() const
unsigned int n_active_levels_in(MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
This is the MeshBase class.
Definition mesh_base.h:81
This class defines an abstract interface for Mesh input.
Definition mesh_input.h:49
This class defines an abstract interface for Mesh output.
Definition mesh_output.h:54
An object whose state is distributed along a set of processors.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition xdr_cxx.h:68
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< CheckpointIO > split_mesh(MeshBase &mesh, processor_id_type nsplits)
split_mesh takes the given initialized/opened mesh and partitions it into nsplits pieces or chunks.
uint64_t largest_id_type
Definition id_types.h:148
std::set< const Node * > connected_node_set_type
uint8_t processor_id_type
Definition id_types.h:104
The definition of the const_element_iterator struct.
Definition mesh_base.h:2575