libMesh
checkpoint_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
50 class CheckpointIO : public MeshInput<MeshBase>,
51  public MeshOutput<MeshBase>,
52  public ParallelObject
53 {
54 public:
55  // The size used for encoding all id types in this file
57 
58  // The size type used to read header sizes (meta data information)
59  typedef uint64_t header_id_type;
60 
68  explicit
69  CheckpointIO (MeshBase &, const bool=false);
70 
78  explicit
79  CheckpointIO (const MeshBase &, const bool=false);
80 
84  virtual ~CheckpointIO ();
85 
89  virtual void read (const std::string &) libmesh_override;
90 
94  virtual void write (const std::string &) libmesh_override;
95 
99  bool binary() const { return _binary; }
100  bool & binary() { return _binary; }
101 
105  bool parallel() const { return _parallel; }
106  bool & parallel() { return _parallel; }
107 
111  const std::string & version () const { return _version; }
112  std::string & version () { return _version; }
113 
124  const std::vector<processor_id_type> & current_processor_ids() const { return _my_processor_ids; }
125  std::vector<processor_id_type> & current_processor_ids() { return _my_processor_ids; }
126 
139 
140 private:
141  //---------------------------------------------------------------------------
142  // Write Implementation
143 
147  void write_subdomain_names(Xdr & io) const;
148 
152  void write_connectivity (Xdr & io,
153  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
154 
158  void write_remote_elem (Xdr & io,
159  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
160 
164  void write_nodes (Xdr & io,
165  const std::set<const Node *> & nodeset) const;
166 
170  void write_bcs (Xdr & io,
171  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
172 
176  void write_nodesets (Xdr & io,
177  const std::set<const Node *> & nodeset) const;
178 
182  void write_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
183 
184 
185  //---------------------------------------------------------------------------
186  // Read Implementation
187 
193  template <typename file_id_type>
194  file_id_type read_header(const std::string & name);
195 
199  template <typename file_id_type>
200  void read_subfile(Xdr & io, bool expect_all_remote);
201 
205  template <typename file_id_type>
206  void read_subdomain_names(Xdr & io);
207 
211  template <typename file_id_type>
212  void read_connectivity (Xdr & io);
213 
221  template <typename file_id_type>
222  void read_remote_elem (Xdr & io, bool expect_all_remote);
223 
227  template <typename file_id_type>
228  void read_nodes (Xdr & io);
229 
233  template <typename file_id_type>
234  void read_bcs (Xdr & io);
235 
239  template <typename file_id_type>
240  void read_nodesets (Xdr & io);
241 
245  template <typename file_id_type>
246  void read_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
247 
258 
259  bool _binary;
260  bool _parallel;
261  std::string _version;
262 
263  // The processor ids to write
264  std::vector<processor_id_type> _my_processor_ids;
265 
266  // The largest processor id to write
268 };
269 
270 
271 } // namespace libMesh
272 
273 #endif // LIBMESH_CHECKPOINT_IO_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
Definition: checkpoint_io.h:50
void write_nodes(Xdr &io, const std::set< const Node * > &nodeset) const
Write the nodal locations for part of a mesh.
void write_nodesets(Xdr &io, const std::set< const Node * > &nodeset) const
Write the nodal boundary conditions for part of a mesh.
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the connectivity for part of a mesh.
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
const std::vector< processor_id_type > & current_processor_ids() const
Get/Set the processor id or processor ids to use.
uint64_t largest_id_type
Definition: id_types.h:139
uint8_t processor_id_type
Definition: id_types.h:99
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
void read_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Read boundary names information (sideset and nodeset)
The libMesh namespace provides an interface to certain functionality in the library.
void read_remote_elem(Xdr &io, bool expect_all_remote)
Read the remote_elem neighbor and child links for a parallel, distributed mesh.
This is the MeshBase class.
Definition: mesh_base.h:68
bool parallel() const
Get/Set the flag indicating if we should read/write binary.
virtual void read(const std::string &) libmesh_override
This method implements reading a mesh from a specified file.
std::vector< processor_id_type > _my_processor_ids
std::vector< processor_id_type > & current_processor_ids()
std::string & version()
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 write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Write boundary names information (sideset and nodeset)
void write_subdomain_names(Xdr &io) const
Write subdomain name information.
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:50
processor_id_type _my_n_processors
CheckpointIO(MeshBase &, const bool=false)
Constructor.
Definition: checkpoint_io.C:50
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:56
const processor_id_type & current_n_processors() const
Get/Set the n_processors to use.
void write_bcs(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the side boundary conditions for part of a mesh.
This class forms the base class for all other classes that are expected to be implemented in parallel...
file_id_type read_header(const std::string &name)
Read header data on processor 0, then broadcast.
unsigned int n_active_levels_in(MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:68
void read_subdomain_names(Xdr &io)
Read subdomain name information.
largest_id_type xdr_id_type
Definition: checkpoint_io.h:56
void read_bcs(Xdr &io)
Read the boundary conditions for a parallel, distributed mesh.
const std::string & version() const
Get/Set the version string.
void read_subfile(Xdr &io, bool expect_all_remote)
Read a non-header file.
void read_nodesets(Xdr &io)
Read the nodeset conditions for a parallel, distributed mesh.
void read_nodes(Xdr &io)
Read the nodal locations for a parallel, distributed mesh.
processor_id_type & current_n_processors()
void read_connectivity(Xdr &io)
Read the connectivity for a parallel, distributed mesh.
virtual ~CheckpointIO()
Destructor.
Definition: checkpoint_io.C:76
virtual void write(const std::string &) libmesh_override
This method implements writing a mesh to a specified file.
Definition: checkpoint_io.C:83
bool binary() const
Get/Set the flag indicating if we should read/write binary.
Definition: checkpoint_io.h:99