libMesh
xdr_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 &) 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 
211  bool version_at_least_1_8_0() const;
212 
213 private:
214 
215 
216  //---------------------------------------------------------------------------
217  // Write Implementation
221  void write_serialized_subdomain_names(Xdr & io) const;
222 
227  const new_header_id_type n_elem_integers) const;
228 
232  void write_serialized_nodes (Xdr & io, const dof_id_type n_nodes,
233  const new_header_id_type n_node_integers) const;
234 
239  void write_serialized_bcs_helper (Xdr & io, const new_header_id_type n_side_bcs, const std::string bc_type) const;
240 
244  void write_serialized_side_bcs (Xdr & io, const new_header_id_type n_side_bcs) const;
245 
250  void write_serialized_edge_bcs (Xdr & io, const new_header_id_type n_edge_bcs) const;
251 
256  void write_serialized_shellface_bcs (Xdr & io, const new_header_id_type n_shellface_bcs) const;
257 
261  void write_serialized_nodesets (Xdr & io, const new_header_id_type n_nodesets) const;
262 
266  void write_serialized_bc_names (Xdr & io, const BoundaryInfo & info, bool is_sideset) const;
267 
268 
269  //---------------------------------------------------------------------------
270  // Read Implementation
271  //
272  // In the function templates below, the "T type_size" argument is only
273  // used for template argument deduction purposes. The value of this
274  // parameter can be arbitrary because it will not be used within the
275  // function.
276 
281  template <typename T>
282  void read_header(Xdr & io, std::vector<T> & meta_data);
283 
288 
292  template <typename T>
294  const dof_id_type n_elem,
295  const std::vector<new_header_id_type> & meta_data,
296  T type_size);
297 
301  void read_serialized_nodes (Xdr & io, const dof_id_type n_nodes,
302  const std::vector<new_header_id_type> & meta_data);
303 
308  template <typename T>
309  void read_serialized_bcs_helper (Xdr & io, T type_size, const std::string bc_type);
310 
315  template <typename T>
316  void read_serialized_side_bcs (Xdr & io, T type_size);
317 
323  template <typename T>
324  void read_serialized_edge_bcs (Xdr & io, T type_size);
325 
331  template <typename T>
332  void read_serialized_shellface_bcs (Xdr & io, T type_size);
333 
338  template <typename T>
339  void read_serialized_nodesets (Xdr & io, T type_size);
340 
344  void read_serialized_bc_names(Xdr & io, BoundaryInfo & info, bool is_sideset);
345 
346  //-------------------------------------------------------------------------
350  void pack_element (std::vector<xdr_id_type> & conn,
351  const Elem * elem,
352  const dof_id_type parent_id,
353  const dof_id_type parent_pid,
354  const new_header_id_type n_elem_integers) const;
355 
356  bool _binary;
357  bool _legacy;
361  unsigned int _field_width;
362  std::string _version;
363  std::string _bc_file_name;
364  std::string _partition_map_file;
365  std::string _subdomain_map_file;
366  std::string _p_level_file;
367 
371  static const std::size_t io_blksize;
372 };
373 
374 
375 // ------------------------------------------------------------
376 // XdrIO inline members
377 
378 inline
380 {
381  // We can't insist on both serial and parallel
382  libmesh_assert (!this->_write_serial || !this->_write_parallel);
383 
384  // If we insisted on serial, do that
385  if (this->_write_serial)
386  return false;
387 
388  // If we insisted on parallel, do that
389  if (this->_write_parallel)
390  return true;
391 
392  // If we're doing things automatically, check the mesh
394  return !mesh.is_serial();
395 }
396 
397 
398 
399 inline
400 void XdrIO::set_write_parallel (bool do_parallel)
401 {
402  this->_write_parallel = do_parallel;
403 
404  this->_write_serial = !do_parallel;
405 }
406 
407 
408 
409 inline
411 {
412  this->_write_serial = false;
413  this->_write_parallel = false;
414 }
415 
416 
417 } // namespace libMesh
418 
419 
420 
421 #endif // LIBMESH_XDR_IO_H
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:1306
const MT & mesh() const
Definition: mesh_output.h:259
XdrIO(MeshBase &, const bool=false)
Constructor.
Definition: xdr_io.C:74
void read_serialized_nodes(Xdr &io, const dof_id_type n_nodes, const std::vector< new_header_id_type > &meta_data)
Read the nodal locations for a parallel, distributed mesh.
Definition: xdr_io.C:1968
bool _binary
Definition: xdr_io.h:356
bool write_parallel() const
Report whether we should write parallel files.
Definition: xdr_io.h:379
MPI_Info info
bool version_at_least_0_9_6() const
Definition: xdr_io.C:2480
bool _write_parallel
Definition: xdr_io.h:359
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:850
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:1285
void read_serialized_subdomain_names(Xdr &io)
Read subdomain name information - NEW in 0.9.2 format.
Definition: xdr_io.C:1664
void read_serialized_bcs_helper(Xdr &io, T type_size, 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:2192
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
Definition: xdr_io.h:109
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
uint64_t largest_id_type
Definition: id_types.h:148
uint32_t old_header_id_type
Definition: xdr_io.h:60
void read_serialized_nodesets(Xdr &io, T type_size)
Read the nodeset conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2307
void write_serialized_subdomain_names(Xdr &io) const
Write subdomain name information - NEW in 0.9.2 format.
Definition: xdr_io.C:291
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
void read_serialized_side_bcs(Xdr &io, T type_size)
Read the side boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2283
void read_serialized_shellface_bcs(Xdr &io, T type_size)
Read the "shell face" boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2299
The libMesh namespace provides an interface to certain functionality in the library.
void write_serialized_nodes(Xdr &io, const dof_id_type n_nodes, const new_header_id_type n_node_integers) const
Write the nodal locations for a parallel, distributed mesh.
Definition: xdr_io.C:692
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:2371
This is the MeshBase class.
Definition: mesh_base.h:74
largest_id_type xdr_id_type
Definition: xdr_io.h:57
void read_serialized_edge_bcs(Xdr &io, T type_size)
Read the edge boundary conditions for a parallel, distributed mesh.
Definition: xdr_io.C:2291
std::string _partition_map_file
Definition: xdr_io.h:364
bool & legacy()
Definition: xdr_io.h:110
virtual bool is_serial() const
Definition: mesh_base.h:205
const dof_id_type n_nodes
Definition: tecplot_io.C:67
std::string & partition_map_file_name()
Definition: xdr_io.h:153
const std::string & boundary_condition_file_name() const
Get/Set the boundary condition file name.
Definition: xdr_io.h:146
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:410
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:56
bool & binary()
Definition: xdr_io.h:104
bool version_at_least_1_3_0() const
Definition: xdr_io.C:2497
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
Definition: xdr_io.C:111
const std::string & subdomain_map_file_name() const
Get/Set the subdomain file name.
Definition: xdr_io.h:158
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:57
libmesh_assert(ctx)
unsigned int _field_width
Definition: xdr_io.h:361
void set_write_parallel(bool do_parallel=true)
Insist that we should/shouldn&#39;t write parallel files.
Definition: xdr_io.h:400
std::string _bc_file_name
Definition: xdr_io.h:363
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:1552
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:1380
bool version_at_least_1_1_0() const
Definition: xdr_io.C:2489
An object whose state is distributed along a set of processors.
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:67
const std::string & partition_map_file_name() const
Get/Set the partitioning file name.
Definition: xdr_io.h:152
void write_serialized_connectivity(Xdr &io, const dof_id_type n_elem, const new_header_id_type n_elem_integers) const
Write the connectivity for a parallel, distributed mesh.
Definition: xdr_io.C:330
bool _write_unique_id
Definition: xdr_io.h:360
std::string & version()
Definition: xdr_io.h:141
const std::string & version() const
Get/Set the version string.
Definition: xdr_io.h:140
const std::string & polynomial_level_file_name() const
Get/Set the polynomial degree file name.
Definition: xdr_io.h:164
static const std::size_t io_blksize
Define the block size to use for chunked IO.
Definition: xdr_io.h:371
std::string & polynomial_level_file_name()
Definition: xdr_io.h:165
std::string _subdomain_map_file
Definition: xdr_io.h:365
virtual ~XdrIO()
Destructor.
bool version_at_least_0_9_2() const
Definition: xdr_io.C:2470
void pack_element(std::vector< xdr_id_type > &conn, const Elem *elem, const dof_id_type parent_id, const dof_id_type parent_pid, const new_header_id_type n_elem_integers) const
Pack an element into a transfer buffer for parallel communication.
Definition: xdr_io.C:2430
void read_serialized_connectivity(Xdr &io, const dof_id_type n_elem, const std::vector< new_header_id_type > &meta_data, T type_size)
Read the connectivity for a parallel, distributed mesh.
Definition: xdr_io.C:1727
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:1299
bool binary() const
Get/Set the flag indicating if we should read/write binary.
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
Helper function used in write_serialized_side_bcs, write_serialized_edge_bcs, and write_serialized_sh...
Definition: xdr_io.C:1163
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:1292
std::string _p_level_file
Definition: xdr_io.h:366
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
Definition: xdr_io.C:1420
bool _write_serial
Definition: xdr_io.h:358
std::string & boundary_condition_file_name()
Definition: xdr_io.h:147
std::string _version
Definition: xdr_io.h:362
uint8_t dof_id_type
Definition: id_types.h:67
bool _legacy
Definition: xdr_io.h:357
bool version_at_least_1_8_0() const
Definition: xdr_io.C:2504