libMesh
xdr_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_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"
28 #include "libmesh/parallel_object.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 &) libmesh_override;
94 
98  virtual void write (const std::string &) libmesh_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)
Read the connectivity for a parallel, distributed mesh.
Definition: xdr_io.C:1568
XdrIO(MeshBase &, const bool=false)
Constructor.
Definition: xdr_io.C:128
void read_serialized_shellface_bcs(Xdr &io, T)
Read the "shell face" boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2030
bool binary() const
Get/Set the flag indicating if we should read/write binary.
Definition: xdr_io.h:103
bool write_parallel() const
Report whether we should write parallel files.
Definition: xdr_io.h:358
bool _binary
Definition: xdr_io.h:335
virtual bool is_serial() const
Definition: mesh_base.h:140
void write_serialized_nodesets(Xdr &io, const new_header_id_type n_nodesets) const
Write the boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:1194
const std::string & polynomial_level_file_name() const
Get/Set the polynomial degree file name.
Definition: xdr_io.h:164
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)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:656
void read_serialized_subdomain_names(Xdr &io)
Read subdomain name information - NEW in 0.9.2 format.
Definition: xdr_io.C:1506
virtual void read(const std::string &) libmesh_override
This method implements reading a mesh from a specified file.
Definition: xdr_io.C:1314
void write_serialized_edge_bcs(Xdr &io, const new_header_id_type n_edge_bcs) const
Write the edge boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:1180
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
uint64_t largest_id_type
Definition: id_types.h:139
uint32_t old_header_id_type
Definition: xdr_io.h:60
bool version_at_least_0_9_6() const
Definition: xdr_io.C:2226
void write_serialized_side_bcs(Xdr &io, const new_header_id_type n_side_bcs) const
Write the side boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:1173
const MT & mesh() const
Definition: mesh_output.h:216
std::string & subdomain_map_file_name()
Definition: xdr_io.h:159
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
The libMesh namespace provides an interface to certain functionality in the library.
void read_serialized_bcs_helper(Xdr &io, T, const std::string bc_type)
Helper function used in read_serialized_side_bcs, read_serialized_edge_bcs, and read_serialized_shell...
Definition: xdr_io.C:1902
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
Definition: xdr_io.h:51
void read_serialized_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Read boundary names information (sideset and nodeset) - NEW in 0.9.2 format.
Definition: xdr_io.C:2125
This is the MeshBase class.
Definition: mesh_base.h:68
bool version_at_least_1_1_0() const
Definition: xdr_io.C:2234
libmesh_assert(j)
bool version_at_least_0_9_2() const
Definition: xdr_io.C:2217
virtual void write(const std::string &) libmesh_override
This method implements writing a mesh to a specified file.
Definition: xdr_io.C:167
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
const std::string & boundary_condition_file_name() const
Get/Set the boundary condition file name.
Definition: xdr_io.h:146
const dof_id_type n_nodes
Definition: tecplot_io.C:67
std::string & partition_map_file_name()
Definition: xdr_io.h:153
void write_serialized_connectivity(Xdr &io, const dof_id_type n_elem) const
Write the connectivity for a parallel, distributed mesh.
Definition: xdr_io.C:356
bool version_at_least_1_3_0() const
Definition: xdr_io.C:2241
void set_auto_parallel()
Insist that we should write parallel files if and only if the mesh is an already distributed Distribu...
Definition: xdr_io.h:389
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:50
bool & binary()
Definition: xdr_io.h:104
void write_serialized_nodes(Xdr &io, const dof_id_type n_nodes) const
Write the nodal locations for a parallel, distributed mesh.
Definition: xdr_io.C:719
void write_serialized_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Write boundary names information (sideset and nodeset) - NEW in 0.9.2 format.
Definition: xdr_io.C:1271
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
Pack an element into a transfer buffer for parallel communication.
Definition: xdr_io.C:2184
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:56
unsigned int _field_width
Definition: xdr_io.h:340
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:324
void set_write_parallel(bool do_parallel=true)
Insist that we should/shouldn&#39;t write parallel files.
Definition: xdr_io.h:379
void read_serialized_nodesets(Xdr &io, T)
Read the nodeset conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2038
std::string _bc_file_name
Definition: xdr_io.h:342
void read_header(Xdr &io, std::vector< T > &meta_data)
Read header information - templated to handle old (4-byte) or new (8-byte) header id types...
Definition: xdr_io.C:1444
This class forms the base class for all other classes that are expected to be implemented in parallel...
uint64_t new_header_id_type
Definition: xdr_io.h:63
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition: xdr_cxx.h:68
void read_serialized_nodes(Xdr &io, const dof_id_type n_nodes)
Read the nodal locations for a parallel, distributed mesh.
Definition: xdr_io.C:1754
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)
Read the edge boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2022
void write_serialized_shellface_bcs(Xdr &io, const new_header_id_type n_shellface_bcs) const
Write the "shell face" boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:1187
static const std::size_t io_blksize
Define the block size to use for chunked IO.
Definition: xdr_io.h:350
void write_serialized_subdomain_names(Xdr &io) const
Write subdomain name information - NEW in 0.9.2 format.
Definition: xdr_io.C:315
std::string & polynomial_level_file_name()
Definition: xdr_io.h:165
std::string _subdomain_map_file
Definition: xdr_io.h:344
virtual ~XdrIO()
Destructor.
Definition: xdr_io.C:161
const std::string & subdomain_map_file_name() const
Get/Set the subdomain file name.
Definition: xdr_io.h:158
const std::string & partition_map_file_name() const
Get/Set the partitioning file name.
Definition: xdr_io.h:152
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
Definition: xdr_io.h:109
const std::string & version() const
Get/Set the version string.
Definition: xdr_io.h:140
std::string _p_level_file
Definition: xdr_io.h:345
void read_serialized_side_bcs(Xdr &io, T)
Read the side boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2014
void write_serialized_bcs_helper(Xdr &io, const new_header_id_type n_side_bcs, const std::string bc_type) const
Helper function used in write_serialized_side_bcs, write_serialized_edge_bcs, and write_serialized_sh...
Definition: xdr_io.C:1040
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