$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_XDR_IO_H 00021 #define LIBMESH_XDR_IO_H 00022 00023 00024 // Local includes 00025 #include "libmesh/libmesh.h" 00026 #include "libmesh/mesh_input.h" 00027 #include "libmesh/mesh_output.h" 00028 #include "libmesh/parallel_object.h" 00029 00030 // C++ includes 00031 #include <string> 00032 #include <vector> 00033 00034 namespace libMesh 00035 { 00036 00037 // Forward declarations 00038 class MeshBase; 00039 class MeshData; 00040 class Xdr; 00041 class Elem; 00042 00043 00049 // ------------------------------------------------------------ 00050 // XdrIO class definition 00051 class XdrIO : public MeshInput<MeshBase>, 00052 public MeshOutput<MeshBase>, 00053 public ParallelObject 00054 { 00055 public: 00056 // The size used for encoding all id types in this file 00057 typedef largest_id_type xdr_id_type; 00058 00059 // The size type used to read header sizes (meta data information) 00060 typedef uint32_t header_id_type; 00061 00069 explicit 00070 XdrIO (MeshBase&, const bool=false); 00071 00079 explicit 00080 XdrIO (const MeshBase&, const bool=false); 00081 00085 virtual ~XdrIO (); 00086 00090 virtual void read (const std::string&); 00091 00095 virtual void write (const std::string&); 00096 00100 bool binary() const { return _binary; } 00101 bool & binary() { return _binary; } 00102 00106 bool legacy() const { return _legacy; } 00107 bool & legacy() { return _legacy; } 00108 00112 bool write_parallel() const; 00113 00117 void set_write_parallel (bool do_parallel = true); 00118 00123 void set_auto_parallel (); 00124 00137 const std::string & version () const { return _version; } 00138 std::string & version () { return _version; } 00139 00143 const std::string & boundary_condition_file_name() const { return _bc_file_name; } 00144 std::string & boundary_condition_file_name() { return _bc_file_name; } 00145 00149 const std::string & partition_map_file_name() const { return _partition_map_file; } 00150 std::string & partition_map_file_name() { return _partition_map_file; } 00151 00155 const std::string & subdomain_map_file_name() const { return _subdomain_map_file; } 00156 std::string & subdomain_map_file_name() { return _subdomain_map_file; } 00157 00161 const std::string & polynomial_level_file_name() const { return _p_level_file; } 00162 std::string & polynomial_level_file_name() { return _p_level_file; } 00163 00164 00165 private: 00166 00167 00168 //--------------------------------------------------------------------------- 00169 // Write Implementation 00173 void write_serialized_subdomain_names(Xdr &io) const; 00174 00178 void write_serialized_connectivity (Xdr &io, const dof_id_type n_elem) const; 00179 00183 void write_serialized_nodes (Xdr &io, const dof_id_type n_nodes) const; 00184 00188 void write_serialized_bcs (Xdr &io, const header_id_type n_bcs) const; 00189 00193 void write_serialized_nodesets (Xdr &io, const header_id_type n_nodesets) const; 00194 00198 void write_serialized_bc_names (Xdr &io, const BoundaryInfo & info, bool is_sideset) const; 00199 00200 00201 //--------------------------------------------------------------------------- 00202 // Read Implementation 00206 void read_serialized_subdomain_names(Xdr &io); 00207 00211 template <typename T> 00212 void read_serialized_connectivity (Xdr &io, const dof_id_type n_elem, std::vector<header_id_type> & sizes, T); 00213 00217 void read_serialized_nodes (Xdr &io, const dof_id_type n_nodes); 00218 00223 template <typename T> 00224 void read_serialized_bcs (Xdr &io, T); 00225 00230 template <typename T> 00231 void read_serialized_nodesets (Xdr &io, T); 00232 00236 void read_serialized_bc_names(Xdr &io, BoundaryInfo & info, bool is_sideset); 00237 00238 //------------------------------------------------------------------------- 00242 void pack_element (std::vector<xdr_id_type> &conn, 00243 const Elem *elem, 00244 const dof_id_type parent_id = DofObject::invalid_id, 00245 const dof_id_type parent_pid = DofObject::invalid_id) const; 00246 00247 bool _binary; 00248 bool _legacy; 00249 bool _write_serial; 00250 bool _write_parallel; 00251 bool _write_unique_id; 00252 header_id_type _field_width; 00253 std::string _version; 00254 std::string _bc_file_name; 00255 std::string _partition_map_file; 00256 std::string _subdomain_map_file; 00257 std::string _p_level_file; 00258 00262 static const std::size_t io_blksize; 00263 }; 00264 00265 00266 // ------------------------------------------------------------ 00267 // XdrIO inline members 00268 00269 inline 00270 bool XdrIO::write_parallel() const 00271 { 00272 // We can't insist on both serial and parallel 00273 libmesh_assert (!this->_write_serial || !this->_write_parallel); 00274 00275 // If we insisted on serial, do that 00276 if (this->_write_serial) 00277 return false; 00278 00279 // If we insisted on parallel, do that 00280 if (this->_write_parallel) 00281 return true; 00282 00283 // If we're doing things automatically, check the mesh 00284 const MeshBase &mesh = MeshOutput<MeshBase>::mesh(); 00285 return !mesh.is_serial(); 00286 } 00287 00288 00289 00290 inline 00291 void XdrIO::set_write_parallel (bool do_parallel) 00292 { 00293 this->_write_parallel = do_parallel; 00294 00295 this->_write_serial = !do_parallel; 00296 } 00297 00298 00299 00300 inline 00301 void XdrIO::set_auto_parallel () 00302 { 00303 this->_write_serial = false; 00304 this->_write_parallel = false; 00305 } 00306 00307 00308 } // namespace libMesh 00309 00310 00311 00312 #endif // LIBMESH_XDR_IO_H