checkpoint_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
26 #include "libmesh/mesh_input.h"
27 #include "libmesh/mesh_output.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 
170  const std::vector<processor_id_type> & current_processor_ids() const { return _my_processor_ids; }
171  std::vector<processor_id_type> & current_processor_ids() { return _my_processor_ids; }
172 
185 
186 private:
187  //---------------------------------------------------------------------------
188  // Write Implementation
189 
193  void write_subdomain_names(Xdr & io) const;
194 
198  void write_connectivity (Xdr & io,
199  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
200 
204  void write_remote_elem (Xdr & io,
205  const std::set<const Elem *, CompareElemIdsByLevel> & elements) const;
206 
210  void write_nodes (Xdr & io,
211  const std::set<const Node *> & nodeset) const;
212 
216  void write_bcs (Xdr & io,
217  const std::set<const Elem *, CompareElemIdsByLevel> & elements,
218  const std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> & bc_triples) const;
219 
223  void write_nodesets (Xdr & io,
224  const std::set<const Node *> & nodeset,
225  const std::vector<std::tuple<dof_id_type, boundary_id_type>> & bc_tuples) const;
226 
230  void write_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
231 
232 
233  //---------------------------------------------------------------------------
234  // Read Implementation
235 
241  template <typename file_id_type>
242  file_id_type read_header(const std::string & name);
243 
247  template <typename file_id_type>
248  void read_subfile(Xdr & io, bool expect_all_remote);
249 
253  template <typename file_id_type>
254  void read_subdomain_names(Xdr & io);
255 
259  template <typename file_id_type>
260  void read_connectivity (Xdr & io);
261 
269  template <typename file_id_type>
270  void read_remote_elem (Xdr & io, bool expect_all_remote);
271 
275  template <typename file_id_type>
276  void read_nodes (Xdr & io);
277 
281  template <typename file_id_type>
282  void read_bcs (Xdr & io);
283 
287  template <typename file_id_type>
288  void read_nodesets (Xdr & io);
289 
293  template <typename file_id_type>
294  void read_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
295 
306 
307  processor_id_type select_split_config(const std::string & input_name, header_id_type & data_size);
308 
309  bool _binary;
310  bool _parallel;
311  std::string _version;
312 
313  // The processor ids to write
314  std::vector<processor_id_type> _my_processor_ids;
315 
316  // The largest processor id to write
318 };
319 
320 
321 } // namespace libMesh
322 
323 #endif // LIBMESH_CHECKPOINT_IO_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
virtual void write(const std::string &name) override
const std::string & version() const
const processor_id_type & current_n_processors() const
void write_remote_elem(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
virtual void read(const std::string &input_name) override
uint64_t largest_id_type
Definition: id_types.h:139
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
IterBase * end
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
void read_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
void read_remote_elem(Xdr &io, bool expect_all_remote)
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)
Base class for Mesh.
Definition: mesh_base.h:77
const std::vector< processor_id_type > & current_processor_ids() const
std::vector< processor_id_type > _my_processor_ids
std::vector< processor_id_type > & current_processor_ids()
std::string & version()
void write_subdomain_names(Xdr &io) const
processor_id_type _my_n_processors
CheckpointIO(MeshBase &, const bool=false)
Used by the Mesh to keep track of boundary nodes and elements.
Definition: boundary_info.h:57
static void cleanup(const std::string &input_name, processor_id_type n_procs)
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
An object whose state is distributed along a set of processors.
file_id_type read_header(const std::string &name)
C++ interface for the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:66
void read_subdomain_names(Xdr &io)
largest_id_type xdr_id_type
Definition: checkpoint_io.h:66
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
void read_bcs(Xdr &io)
std::unique_ptr< CheckpointIO > split_mesh(MeshBase &mesh, processor_id_type nsplits)
void read_subfile(Xdr &io, bool expect_all_remote)
void read_nodesets(Xdr &io)
void read_nodes(Xdr &io)
void write_nodes(Xdr &io, const std::set< const Node *> &nodeset) const
processor_id_type & current_n_processors()
void read_connectivity(Xdr &io)