xdr_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 MeshBase;
39 class MeshData;
40 class Xdr;
41 class Elem;
42 
43 
49 // ------------------------------------------------------------
50 // XdrIO class definition
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 header sizes (meta data information)
60  typedef uint32_t header_id_type;
61 
69  explicit
70  XdrIO (MeshBase&, const bool=false);
71 
79  explicit
80  XdrIO (const MeshBase&, const bool=false);
81 
85  virtual ~XdrIO ();
86 
90  virtual void read (const std::string&);
91 
95  virtual void write (const std::string&);
96 
100  bool binary() const { return _binary; }
101  bool & binary() { return _binary; }
102 
106  bool legacy() const { return _legacy; }
107  bool & legacy() { return _legacy; }
108 
112  bool write_parallel() const;
113 
117  void set_write_parallel (bool do_parallel = true);
118 
123  void set_auto_parallel ();
124 
137  const std::string & version () const { return _version; }
138  std::string & version () { return _version; }
139 
143  const std::string & boundary_condition_file_name() const { return _bc_file_name; }
144  std::string & boundary_condition_file_name() { return _bc_file_name; }
145 
149  const std::string & partition_map_file_name() const { return _partition_map_file; }
150  std::string & partition_map_file_name() { return _partition_map_file; }
151 
155  const std::string & subdomain_map_file_name() const { return _subdomain_map_file; }
156  std::string & subdomain_map_file_name() { return _subdomain_map_file; }
157 
161  const std::string & polynomial_level_file_name() const { return _p_level_file; }
162  std::string & polynomial_level_file_name() { return _p_level_file; }
163 
164 
165  private:
166 
167 
168  //---------------------------------------------------------------------------
169  // Write Implementation
173  void write_serialized_subdomain_names(Xdr &io) const;
174 
178  void write_serialized_connectivity (Xdr &io, const dof_id_type n_elem) const;
179 
183  void write_serialized_nodes (Xdr &io, const dof_id_type n_nodes) const;
184 
188  void write_serialized_bcs (Xdr &io, const std::size_t n_bcs) const;
189 
193  void write_serialized_nodesets (Xdr &io, const std::size_t n_nodesets) const;
194 
198  void write_serialized_bc_names (Xdr &io, const BoundaryInfo & info, bool is_sideset) const;
199 
200 
201  //---------------------------------------------------------------------------
202  // Read Implementation
207 
211  template <typename T>
212  void read_serialized_connectivity (Xdr &io, const dof_id_type n_elem, std::vector<header_id_type> & sizes, T);
213 
217  void read_serialized_nodes (Xdr &io, const dof_id_type n_nodes);
218 
223  template <typename T>
224  void read_serialized_bcs (Xdr &io, T);
225 
230  template <typename T>
231  void read_serialized_nodesets (Xdr &io, T);
232 
236  void read_serialized_bc_names(Xdr &io, BoundaryInfo & info, bool is_sideset);
237 
238  //-------------------------------------------------------------------------
242  void pack_element (std::vector<xdr_id_type> &conn,
243  const Elem *elem,
244  const dof_id_type parent_id = DofObject::invalid_id,
245  const dof_id_type parent_pid = DofObject::invalid_id) const;
246 
247  bool _binary;
248  bool _legacy;
253  std::string _version;
254  std::string _bc_file_name;
255  std::string _partition_map_file;
256  std::string _subdomain_map_file;
257  std::string _p_level_file;
258 
262  static const std::size_t io_blksize;
263 };
264 
265 
266 // ------------------------------------------------------------
267 // XdrIO inline members
268 
269 inline
271 {
272  // We can't insist on both serial and parallel
273  libmesh_assert (!this->_write_serial || !this->_write_parallel);
274 
275  // If we insisted on serial, do that
276  if (this->_write_serial)
277  return false;
278 
279  // If we insisted on parallel, do that
280  if (this->_write_parallel)
281  return true;
282 
283  // If we're doing things automatically, check the mesh
285  return !mesh.is_serial();
286 }
287 
288 
289 
290 inline
291 void XdrIO::set_write_parallel (bool do_parallel)
292 {
293  this->_write_parallel = do_parallel;
294 
295  this->_write_serial = !do_parallel;
296 }
297 
298 
299 
300 inline
302 {
303  this->_write_serial = false;
304  this->_write_parallel = false;
305 }
306 
307 
308 } // namespace libMesh
309 
310 
311 
312 #endif // LIBMESH_XDR_IO_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo