libMesh
Loading...
Searching...
No Matches
xdr_io.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
34namespace libMesh
35{
36
37// Forward declarations
38class Xdr;
39class Elem;
40
51class XdrIO : public MeshInput<MeshBase>,
52 public MeshOutput<MeshBase>,
53 public ParallelObject
54{
55public:
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; }
154
158 const std::string & subdomain_map_file_name() const { 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
213private:
214
215
216 //---------------------------------------------------------------------------
217 // Write Implementation
221 void write_serialized_subdomain_names(Xdr & io) const;
222
226 void write_serialized_connectivity (Xdr & io, const dof_id_type n_elem,
227 const new_header_id_type n_elem_integers) const;
228
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
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
361 unsigned int _field_width;
362 std::string _version;
363 std::string _bc_file_name;
366 std::string _p_level_file;
367
371 static const std::size_t io_blksize;
372};
373
374
375// ------------------------------------------------------------
376// XdrIO inline members
377
378inline
380{
381 // We can't insist on both serial and 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
399inline
400void 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
409inline
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
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the MeshBase class.
Definition mesh_base.h:81
virtual bool is_serial() const
Definition mesh_base.h:357
This class defines an abstract interface for Mesh input.
Definition mesh_input.h:49
This class defines an abstract interface for Mesh output.
Definition mesh_output.h:54
const MT & mesh() const
An object whose state is distributed along a set of processors.
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
Definition xdr_io.h:54
std::string & boundary_condition_file_name()
Definition xdr_io.h:147
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:346
bool _write_serial
Definition xdr_io.h:358
std::string _bc_file_name
Definition xdr_io.h:363
void set_write_parallel(bool do_parallel=true)
Insist that we should/shouldn't write parallel files.
Definition xdr_io.h:400
bool binary() const
Get/Set the flag indicating if we should read/write binary.
Definition xdr_io.h:103
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
Definition xdr_io.h:109
void read_serialized_edge_bcs(Xdr &io, T type_size)
Read the edge boundary conditions for a parallel, distributed mesh.
Definition xdr_io.C:2311
std::string & subdomain_map_file_name()
Definition xdr_io.h:159
bool write_parallel() const
Report whether we should write parallel files.
Definition xdr_io.h:379
bool version_at_least_1_3_0() const
Definition xdr_io.C:2517
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:1179
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:2212
largest_id_type xdr_id_type
Definition xdr_io.h:57
virtual ~XdrIO()
Destructor.
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:1308
bool version_at_least_1_8_0() const
Definition xdr_io.C:2524
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:1322
bool version_at_least_0_9_6() const
Definition xdr_io.C:2500
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:1988
bool version_at_least_0_9_2() const
Definition xdr_io.C:2490
std::string _subdomain_map_file
Definition xdr_io.h:365
void read_serialized_nodesets(Xdr &io, T type_size)
Read the nodeset conditions for a parallel, distributed mesh.
Definition xdr_io.C:2327
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:708
std::string & polynomial_level_file_name()
Definition xdr_io.h:165
const std::string & boundary_condition_file_name() const
Get/Set the boundary condition file name.
Definition xdr_io.h:146
bool & binary()
Definition xdr_io.h:104
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:1568
std::string & version()
Definition xdr_io.h:141
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:1315
std::string _version
Definition xdr_io.h:362
bool _write_unique_id
Definition xdr_io.h:360
uint32_t old_header_id_type
Definition xdr_io.h:60
std::string _partition_map_file
Definition xdr_io.h:364
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:2319
void read_serialized_subdomain_names(Xdr &io)
Read subdomain name information - NEW in 0.9.2 format.
Definition xdr_io.C:1680
const std::string & polynomial_level_file_name() const
Get/Set the polynomial degree file name.
Definition xdr_io.h:164
const std::string & version() const
Get/Set the version string.
Definition xdr_io.h:140
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:2450
bool _write_parallel
Definition xdr_io.h:359
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
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:2391
unsigned int _field_width
Definition xdr_io.h:361
void write_serialized_subdomain_names(Xdr &io) const
Write subdomain name information - NEW in 0.9.2 format.
Definition xdr_io.C:307
static const std::size_t io_blksize
Define the block size to use for chunked IO.
Definition xdr_io.h:371
void read_serialized_side_bcs(Xdr &io, T type_size)
Read the side boundary conditions for a parallel, distributed mesh.
Definition xdr_io.C:2303
bool & legacy()
Definition xdr_io.h:110
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
Definition xdr_io.C:127
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:1301
const std::string & partition_map_file_name() const
Get/Set the partitioning file name.
Definition xdr_io.h:152
const std::string & subdomain_map_file_name() const
Get/Set the subdomain file name.
Definition xdr_io.h:158
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:1396
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:1743
bool version_at_least_1_1_0() const
Definition xdr_io.C:2509
uint64_t new_header_id_type
Definition xdr_io.h:63
std::string _p_level_file
Definition xdr_io.h:366
std::string & partition_map_file_name()
Definition xdr_io.h:153
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
Definition xdr_io.C:1436
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
Definition xdr_cxx.h:68
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)
uint64_t largest_id_type
Definition id_types.h:148
uint8_t dof_id_type
Definition id_types.h:67
const dof_id_type n_nodes
Definition tecplot_io.C:67