libMesh
checkpoint_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/parallel_object.h"
29 
30 // C++ includes
31 #include <string>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 // Forward declarations
37 class Xdr;
38 class CheckpointIO;
39 
47 std::unique_ptr<CheckpointIO> split_mesh(MeshBase & mesh, processor_id_type nsplits);
48 
60 class CheckpointIO : public MeshInput<MeshBase>,
61  public MeshOutput<MeshBase>,
62  public ParallelObject
63 {
64 public:
65  // The size used for encoding all id types in this file
67 
68  // The size type used to read header sizes (meta data information)
69  typedef uint64_t header_id_type;
70 
78  explicit
79  CheckpointIO (MeshBase &, const bool=false);
80 
88  explicit
89  CheckpointIO (const MeshBase &, const bool=false);
90 
94  virtual ~CheckpointIO ();
95 
102  virtual void read (const std::string & input_name) override;
103 
117  virtual void write (const std::string & name) override;
118 
140  static void cleanup(const std::string & input_name, processor_id_type n_procs);
141 
145  bool binary() const { return _binary; }
146  bool & binary() { return _binary; }
147 
151  bool parallel() const { return _parallel; }
152  bool & parallel() { return _parallel; }
153 
157  const std::string & version () const { return _version; }
158  std::string & version () { return _version; }
159 
167  bool version_at_least_1_5() const;
168 
179  const std::vector<processor_id_type> & current_processor_ids() const { return _my_processor_ids; }
180  std::vector<processor_id_type> & current_processor_ids() { return _my_processor_ids; }
181 
194 
195 private:
196  //---------------------------------------------------------------------------
197  // Write Implementation
198 
202  void write_subdomain_names(Xdr & io) const;
203 
207  void write_connectivity (Xdr & io,
208  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
209 
213  void write_remote_elem (Xdr & io,
214  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
215 
219  void write_nodes (Xdr & io,
220  const std::set<const Node *> & nodeset) const;
221 
225  void write_bcs (Xdr & io,
226  const std::set<const Elem *, CompareElemIdsByLevel> & elements,
227  const std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> & bc_triples) const;
228 
232  void write_nodesets (Xdr & io,
233  const std::set<const Node *> & nodeset,
234  const std::vector<std::tuple<dof_id_type, boundary_id_type>> & bc_tuples) const;
235 
239  void write_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
240 
241 
242  //---------------------------------------------------------------------------
243  // Read Implementation
244 
250  template <typename file_id_type>
251  file_id_type read_header(const std::string & name);
252 
256  template <typename file_id_type>
257  void read_subfile(Xdr & io, bool expect_all_remote);
258 
262  template <typename file_id_type>
263  void read_subdomain_names(Xdr & io);
264 
268  template <typename file_id_type>
269  void read_connectivity (Xdr & io);
270 
278  template <typename file_id_type>
279  void read_remote_elem (Xdr & io, bool expect_all_remote);
280 
284  template <typename file_id_type>
285  void read_nodes (Xdr & io);
286 
290  template <typename file_id_type>
291  void read_bcs (Xdr & io);
292 
296  template <typename file_id_type>
297  void read_nodesets (Xdr & io);
298 
302  template <typename file_id_type>
303  void read_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
304 
308  template <typename file_id_type>
310  (Xdr & io,
311  std::vector<std::string> & node_integer_names,
312  std::vector<std::string> & elem_integer_names);
313 
324 
325  processor_id_type select_split_config(const std::string & input_name, header_id_type & data_size);
326 
327  bool _binary;
328  bool _parallel;
329  std::string _version;
330 
331  // The processor ids to write
332  std::vector<processor_id_type> _my_processor_ids;
333 
334  // The largest processor id to write
336 };
337 
338 
339 } // namespace libMesh
340 
341 #endif // LIBMESH_CHECKPOINT_IO_H
libMesh::CheckpointIO::select_split_config
processor_id_type select_split_config(const std::string &input_name, header_id_type &data_size)
Definition: checkpoint_io.C:186
libMesh::CheckpointIO::read_bcs
void read_bcs(Xdr &io)
Read the boundary conditions for a parallel, distributed mesh.
Definition: checkpoint_io.C:1350
libMesh::BoundaryInfo
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
Definition: boundary_info.h:57
libMesh::CheckpointIO::current_n_processors
processor_id_type & current_n_processors()
Definition: checkpoint_io.h:193
libMesh::CheckpointIO::write_nodesets
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.
Definition: checkpoint_io.C:741
libMesh::CheckpointIO::parallel
bool parallel() const
Get/Set the flag indicating if we should read/write binary.
Definition: checkpoint_io.h:151
libMesh::CheckpointIO::binary
bool & binary()
Definition: checkpoint_io.h:146
libMesh::CheckpointIO::_my_processor_ids
std::vector< processor_id_type > _my_processor_ids
Definition: checkpoint_io.h:332
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Xdr
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:65
libMesh::CheckpointIO::parallel
bool & parallel()
Definition: checkpoint_io.h:152
libMesh::CheckpointIO::version
const std::string & version() const
Get/Set the version string.
Definition: checkpoint_io.h:157
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
libMesh::CheckpointIO::write_bc_names
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Write boundary names information (sideset and nodeset)
Definition: checkpoint_io.C:772
libMesh::CheckpointIO::xdr_id_type
largest_id_type xdr_id_type
Definition: checkpoint_io.h:66
libMesh::CheckpointIO::read_subdomain_names
void read_subdomain_names(Xdr &io)
Read subdomain name information.
Definition: checkpoint_io.C:994
libMesh::CheckpointIO::version
std::string & version()
Definition: checkpoint_io.h:158
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::largest_id_type
uint64_t largest_id_type
Definition: id_types.h:148
libMesh::CheckpointIO::header_id_type
uint64_t header_id_type
Definition: checkpoint_io.h:69
libMesh::CheckpointIO::cleanup
static void cleanup(const std::string &input_name, processor_id_type n_procs)
Used to remove a checkpoint directory and its corresponding files.
Definition: checkpoint_io.C:251
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::CheckpointIO::write_nodes
void write_nodes(Xdr &io, const std::set< const Node * > &nodeset) const
Write the nodal locations for part of a mesh.
Definition: checkpoint_io.C:530
libMesh::CheckpointIO::read_nodes
void read_nodes(Xdr &io)
Read the nodal locations for a parallel, distributed mesh.
Definition: checkpoint_io.C:1024
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::CheckpointIO::binary
bool binary() const
Get/Set the flag indicating if we should read/write binary.
Definition: checkpoint_io.h:145
libMesh::CheckpointIO::version_at_least_1_5
bool version_at_least_1_5() const
Definition: checkpoint_io.C:277
libMesh::split_mesh
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.
Definition: checkpoint_io.C:134
libMesh::CheckpointIO::read_connectivity
void read_connectivity(Xdr &io)
Read the connectivity for a parallel, distributed mesh.
Definition: checkpoint_io.C:1118
libMesh::CheckpointIO::read_bc_names
void read_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Read boundary names information (sideset and nodeset)
Definition: checkpoint_io.C:1398
libMesh::CheckpointIO::n_active_levels_in
unsigned int n_active_levels_in(MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
Definition: checkpoint_io.C:1441
libMesh::CheckpointIO::~CheckpointIO
virtual ~CheckpointIO()
Destructor.
Definition: checkpoint_io.C:182
libMesh::CheckpointIO::read_nodesets
void read_nodesets(Xdr &io)
Read the nodeset conditions for a parallel, distributed mesh.
Definition: checkpoint_io.C:1375
libMesh::MeshBase::const_element_iterator
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1891
libMesh::CheckpointIO::read
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
Definition: checkpoint_io.C:804
libMesh::CheckpointIO::_version
std::string _version
Definition: checkpoint_io.h:329
libMesh::CheckpointIO::read_remote_elem
void read_remote_elem(Xdr &io, bool expect_all_remote)
Read the remote_elem neighbor and child links for a parallel, distributed mesh.
libMesh::CheckpointIO::write_remote_elem
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.
Definition: checkpoint_io.C:655
libMesh::CheckpointIO::current_n_processors
const processor_id_type & current_n_processors() const
Get/Set the n_processors to use.
Definition: checkpoint_io.h:192
libMesh::CheckpointIO::current_processor_ids
const std::vector< processor_id_type > & current_processor_ids() const
Get/Set the processor id or processor ids to use.
Definition: checkpoint_io.h:179
libMesh::CheckpointIO::CheckpointIO
CheckpointIO(MeshBase &, const bool=false)
Constructor.
Definition: checkpoint_io.C:160
libMesh::CheckpointIO::current_processor_ids
std::vector< processor_id_type > & current_processor_ids()
Definition: checkpoint_io.h:180
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::CheckpointIO::write_subdomain_names
void write_subdomain_names(Xdr &io) const
Write subdomain name information.
Definition: checkpoint_io.C:496
libMesh::CheckpointIO::_my_n_processors
processor_id_type _my_n_processors
Definition: checkpoint_io.h:335
libMesh::CheckpointIO::read_header
file_id_type read_header(const std::string &name)
Read header data on processor 0, then broadcast.
Definition: checkpoint_io.C:884
libMesh::CheckpointIO::write
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
Definition: checkpoint_io.C:283
libMesh::CheckpointIO::_parallel
bool _parallel
Definition: checkpoint_io.h:328
libMesh::CheckpointIO::_binary
bool _binary
Definition: checkpoint_io.h:327
libMesh::CheckpointIO::write_bcs
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.
Definition: checkpoint_io.C:704
libMesh::CheckpointIO::write_connectivity
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the connectivity for part of a mesh.
Definition: checkpoint_io.C:580
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::CheckpointIO
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
Definition: checkpoint_io.h:60
libMesh::MeshInput
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
libMesh::CheckpointIO::read_subfile
void read_subfile(Xdr &io, bool expect_all_remote)
Read a non-header file.
Definition: checkpoint_io.C:973
libMesh::CheckpointIO::read_integers_names
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.
Definition: checkpoint_io.C:1428