xdr_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_XDR_IO_H
21 #define LIBMESH_XDR_IO_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh.h"
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 
37 // Forward declarations
38 class Xdr;
39 class Elem;
40 
51 class XdrIO : public MeshInput<MeshBase>,
52  public MeshOutput<MeshBase>,
53  public ParallelObject
54 {
55 public:
56  // The size used for encoding all id types in this file
58 
59  // The size type used to read pre-1.3.0 header sizes (meta data information)
60  typedef uint32_t old_header_id_type;
61 
62  // Likewise, but for 1.3.0 and newer header files
63  typedef uint64_t new_header_id_type;
64 
72  explicit
73  XdrIO (MeshBase &, const bool=false);
74 
82  explicit
83  XdrIO (const MeshBase &, const bool=false);
84 
88  virtual ~XdrIO ();
89 
93  virtual void read (const std::string &) override;
94 
98  virtual void write (const std::string &) override;
99 
103  bool binary() const { return _binary; }
104  bool & binary() { return _binary; }
105 
109  bool legacy() const { return _legacy; }
110  bool & legacy() { return _legacy; }
111 
115  bool write_parallel() const;
116 
120  void set_write_parallel (bool do_parallel = true);
121 
126  void set_auto_parallel ();
127 
140  const std::string & version () const { return _version; }
141  std::string & version () { return _version; }
142 
146  const std::string & boundary_condition_file_name() const { return _bc_file_name; }
147  std::string & boundary_condition_file_name() { return _bc_file_name; }
148 
152  const std::string & partition_map_file_name() const { return _partition_map_file; }
153  std::string & partition_map_file_name() { return _partition_map_file; }
154 
158  const std::string & subdomain_map_file_name() const { return _subdomain_map_file; }
159  std::string & subdomain_map_file_name() { return _subdomain_map_file; }
160 
164  const std::string & polynomial_level_file_name() const { return _p_level_file; }
165  std::string & polynomial_level_file_name() { return _p_level_file; }
166 
175  bool version_at_least_0_9_2() const;
176 
184  bool version_at_least_0_9_6() const;
185 
193  bool version_at_least_1_1_0() const;
194 
202  bool version_at_least_1_3_0() const;
203 
204 private:
205 
206 
207  //---------------------------------------------------------------------------
208  // Write Implementation
212  void write_serialized_subdomain_names(Xdr & io) const;
213 
217  void write_serialized_connectivity (Xdr & io, const dof_id_type n_elem) const;
218 
222  void write_serialized_nodes (Xdr & io, const dof_id_type n_nodes) const;
223 
228  void write_serialized_bcs_helper (Xdr & io, const new_header_id_type n_side_bcs, const std::string bc_type) const;
229 
233  void write_serialized_side_bcs (Xdr & io, const new_header_id_type n_side_bcs) const;
234 
239  void write_serialized_edge_bcs (Xdr & io, const new_header_id_type n_edge_bcs) const;
240 
245  void write_serialized_shellface_bcs (Xdr & io, const new_header_id_type n_shellface_bcs) const;
246 
250  void write_serialized_nodesets (Xdr & io, const new_header_id_type n_nodesets) const;
251 
255  void write_serialized_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
256 
257 
258  //---------------------------------------------------------------------------
259  // Read Implementation
260 
265  template <typename T>
266  void read_header(Xdr & io, std::vector<T> & meta_data);
267 
272 
276  template <typename T>
277  void read_serialized_connectivity (Xdr & io, const dof_id_type n_elem, std::vector<new_header_id_type> & sizes, T);
278 
282  void read_serialized_nodes (Xdr & io, const dof_id_type n_nodes);
283 
288  template <typename T>
289  void read_serialized_bcs_helper (Xdr & io, T, const std::string bc_type);
290 
295  template <typename T>
296  void read_serialized_side_bcs (Xdr & io, T);
297 
303  template <typename T>
304  void read_serialized_edge_bcs (Xdr & io, T);
305 
311  template <typename T>
312  void read_serialized_shellface_bcs (Xdr & io, T);
313 
318  template <typename T>
319  void read_serialized_nodesets (Xdr & io, T);
320 
324  void read_serialized_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
325 
326  //-------------------------------------------------------------------------
330  void pack_element (std::vector<xdr_id_type> & conn,
331  const Elem * elem,
332  const dof_id_type parent_id = DofObject::invalid_id,
333  const dof_id_type parent_pid = DofObject::invalid_id) const;
334 
335  bool _binary;
336  bool _legacy;
340  unsigned int _field_width;
341  std::string _version;
342  std::string _bc_file_name;
343  std::string _partition_map_file;
344  std::string _subdomain_map_file;
345  std::string _p_level_file;
346 
350  static const std::size_t io_blksize;
351 };
352 
353 
354 // ------------------------------------------------------------
355 // XdrIO inline members
356 
357 inline
359 {
360  // We can't insist on both serial and parallel
361  libmesh_assert (!this->_write_serial || !this->_write_parallel);
362 
363  // If we insisted on serial, do that
364  if (this->_write_serial)
365  return false;
366 
367  // If we insisted on parallel, do that
368  if (this->_write_parallel)
369  return true;
370 
371  // If we're doing things automatically, check the mesh
373  return !mesh.is_serial();
374 }
375 
376 
377 
378 inline
379 void XdrIO::set_write_parallel (bool do_parallel)
380 {
381  this->_write_parallel = do_parallel;
382 
383  this->_write_serial = !do_parallel;
384 }
385 
386 
387 
388 inline
390 {
391  this->_write_serial = false;
392  this->_write_parallel = false;
393 }
394 
395 
396 } // namespace libMesh
397 
398 
399 
400 #endif // LIBMESH_XDR_IO_H
void read_serialized_connectivity(Xdr &io, const dof_id_type n_elem, std::vector< new_header_id_type > &sizes, T)
Definition: xdr_io.C:1504
void write_serialized_nodesets(Xdr &io, const new_header_id_type n_nodesets) const
Definition: xdr_io.C:1136
const MT & mesh() const
Definition: mesh_output.h:234
XdrIO(MeshBase &, const bool=false)
Definition: xdr_io.C:129
void read_serialized_shellface_bcs(Xdr &io, T)
Definition: xdr_io.C:1966
bool _binary
Definition: xdr_io.h:335
bool write_parallel() const
Definition: xdr_io.h:358
bool version_at_least_0_9_6() const
Definition: xdr_io.C:2162
void write_serialized_nodes(Xdr &io, const dof_id_type n_nodes) const
Definition: xdr_io.C:710
bool _write_parallel
Definition: xdr_io.h:338
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Definition: mesh_tools.C:702
void write_serialized_side_bcs(Xdr &io, const new_header_id_type n_side_bcs) const
Definition: xdr_io.C:1115
void read_serialized_subdomain_names(Xdr &io)
Definition: xdr_io.C:1442
bool legacy() const
Definition: xdr_io.h:109
void pack_element(std::vector< xdr_id_type > &conn, const Elem *elem, const dof_id_type parent_id=DofObject::invalid_id, const dof_id_type parent_pid=DofObject::invalid_id) const
Definition: xdr_io.C:2120
The base class for all geometric element types.
Definition: elem.h:100
uint64_t largest_id_type
Definition: id_types.h:139
uint32_t old_header_id_type
Definition: xdr_io.h:60
void write_serialized_subdomain_names(Xdr &io) const
Definition: xdr_io.C:313
std::string & subdomain_map_file_name()
Definition: xdr_io.h:159
void read_serialized_bcs_helper(Xdr &io, T, const std::string bc_type)
Definition: xdr_io.C:1841
void read_serialized_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Definition: xdr_io.C:2061
Base class for Mesh.
Definition: mesh_base.h:77
largest_id_type xdr_id_type
Definition: xdr_io.h:57
std::string _partition_map_file
Definition: xdr_io.h:343
bool & legacy()
Definition: xdr_io.h:110
virtual bool is_serial() const
Definition: mesh_base.h:154
const dof_id_type n_nodes
Definition: tecplot_io.C:68
std::string & partition_map_file_name()
Definition: xdr_io.h:153
const std::string & boundary_condition_file_name() const
Definition: xdr_io.h:146
void set_auto_parallel()
Definition: xdr_io.h:389
bool & binary()
Definition: xdr_io.h:104
bool version_at_least_1_3_0() const
Definition: xdr_io.C:2177
virtual void write(const std::string &) override
Definition: xdr_io.C:168
const std::string & subdomain_map_file_name() const
Definition: xdr_io.h:158
Used by the Mesh to keep track of boundary nodes and elements.
Definition: boundary_info.h:57
unsigned int _field_width
Definition: xdr_io.h:340
static const dof_id_type invalid_id
Definition: dof_object.h:347
void set_write_parallel(bool do_parallel=true)
Definition: xdr_io.h:379
void read_serialized_nodesets(Xdr &io, T)
Definition: xdr_io.C:1974
std::string _bc_file_name
Definition: xdr_io.h:342
void read_header(Xdr &io, std::vector< T > &meta_data)
Definition: xdr_io.C:1380
void write_serialized_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Definition: xdr_io.C:1210
bool version_at_least_1_1_0() const
Definition: xdr_io.C:2170
An object whose state is distributed along a set of processors.
uint64_t new_header_id_type
Definition: xdr_io.h:63
C++ interface for the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:66
const std::string & partition_map_file_name() const
Definition: xdr_io.h:152
void read_serialized_nodes(Xdr &io, const dof_id_type n_nodes)
Definition: xdr_io.C:1690
bool _write_unique_id
Definition: xdr_io.h:339
std::string & version()
Definition: xdr_io.h:141
void read_serialized_edge_bcs(Xdr &io, T)
Definition: xdr_io.C:1958
const std::string & version() const
Definition: xdr_io.h:140
const std::string & polynomial_level_file_name() const
Definition: xdr_io.h:164
static const std::size_t io_blksize
Definition: xdr_io.h:350
std::string & polynomial_level_file_name()
Definition: xdr_io.h:165
std::string _subdomain_map_file
Definition: xdr_io.h:344
virtual ~XdrIO()
Definition: xdr_io.C:162
bool version_at_least_0_9_2() const
Definition: xdr_io.C:2153
void write_serialized_shellface_bcs(Xdr &io, const new_header_id_type n_shellface_bcs) const
Definition: xdr_io.C:1129
bool binary() const
Definition: xdr_io.h:103
void write_serialized_bcs_helper(Xdr &io, const new_header_id_type n_side_bcs, const std::string bc_type) const
Definition: xdr_io.C:993
void write_serialized_edge_bcs(Xdr &io, const new_header_id_type n_edge_bcs) const
Definition: xdr_io.C:1122
std::string _p_level_file
Definition: xdr_io.h:345
void read_serialized_side_bcs(Xdr &io, T)
Definition: xdr_io.C:1950
void write_serialized_connectivity(Xdr &io, const dof_id_type n_elem) const
Definition: xdr_io.C:351
virtual void read(const std::string &) override
Definition: xdr_io.C:1250
bool _write_serial
Definition: xdr_io.h:337
std::string & boundary_condition_file_name()
Definition: xdr_io.h:147
std::string _version
Definition: xdr_io.h:341
uint8_t dof_id_type
Definition: id_types.h:64
bool _legacy
Definition: xdr_io.h:336