xdr_io.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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 00029 // C++ includes 00030 #include <string> 00031 #include <vector> 00032 00033 namespace libMesh 00034 { 00035 00036 // Forward declarations 00037 class MeshBase; 00038 class MeshData; 00039 class Xdr; 00040 class Elem; 00041 00042 00048 // ------------------------------------------------------------ 00049 // XdrIO class definition 00050 class XdrIO : public MeshInput<MeshBase>, 00051 public MeshOutput<MeshBase> 00052 { 00053 00054 public: 00055 00063 explicit 00064 XdrIO (MeshBase&, const bool=false); 00065 00073 explicit 00074 XdrIO (const MeshBase&, const bool=false); 00075 00079 virtual ~XdrIO (); 00080 00084 virtual void read (const std::string&); 00085 00089 virtual void write (const std::string&); 00090 00094 bool binary() const { return _binary; } 00095 bool & binary() { return _binary; } 00096 00100 bool legacy() const { return _legacy; } 00101 bool & legacy() { return _legacy; } 00102 00106 bool write_parallel() const; 00107 00111 void set_write_parallel (bool do_parallel = true); 00112 00117 void set_auto_parallel (); 00118 00131 const std::string & version () const { return _version; } 00132 std::string & version () { return _version; } 00133 00137 const std::string & boundary_condition_file_name() const { return _bc_file_name; } 00138 std::string & boundary_condition_file_name() { return _bc_file_name; } 00139 00143 const std::string & partition_map_file_name() const { return _partition_map_file; } 00144 std::string & partition_map_file_name() { return _partition_map_file; } 00145 00149 const std::string & subdomain_map_file_name() const { return _subdomain_map_file; } 00150 std::string & subdomain_map_file_name() { return _subdomain_map_file; } 00151 00155 const std::string & polynomial_level_file_name() const { return _p_level_file; } 00156 std::string & polynomial_level_file_name() { return _p_level_file; } 00157 00158 00159 private: 00160 00161 00162 //--------------------------------------------------------------------------- 00163 // Write Implementation 00167 void write_serialized_connectivity (Xdr &io, const dof_id_type n_elem) const; 00168 00172 void write_serialized_nodes (Xdr &io, const dof_id_type n_nodes) const; 00173 00177 void write_serialized_bcs (Xdr &io, const std::size_t n_bcs) const; 00178 00179 00180 00181 //--------------------------------------------------------------------------- 00182 // Read Implementation 00186 void read_serialized_connectivity (Xdr &io, const dof_id_type n_elem); 00187 00191 void read_serialized_nodes (Xdr &io, const dof_id_type n_nodes); 00192 00196 void read_serialized_bcs (Xdr &io); 00197 00198 //------------------------------------------------------------------------- 00202 void pack_element (std::vector<dof_id_type> &conn, 00203 const Elem *elem, 00204 const dof_id_type parent_id = DofObject::invalid_id, 00205 const dof_id_type parent_pid = DofObject::invalid_id) const; 00206 00207 bool _binary; 00208 bool _legacy; 00209 bool _write_serial; 00210 bool _write_parallel; 00211 std::string _version; 00212 std::string _bc_file_name; 00213 std::string _partition_map_file; 00214 std::string _subdomain_map_file; 00215 std::string _p_level_file; 00216 00220 static const std::size_t io_blksize; 00221 }; 00222 00223 00224 // ------------------------------------------------------------ 00225 // XdrIO inline members 00226 00227 inline 00228 bool XdrIO::write_parallel() const 00229 { 00230 // We can't insist on both serial and parallel 00231 libmesh_assert (!this->_write_serial || !this->_write_parallel); 00232 00233 // If we insisted on serial, do that 00234 if (this->_write_serial) 00235 return false; 00236 00237 // If we insisted on parallel, do that 00238 if (this->_write_parallel) 00239 return true; 00240 00241 // If we're doing things automatically, check the mesh 00242 const MeshBase &mesh = MeshOutput<MeshBase>::mesh(); 00243 return !mesh.is_serial(); 00244 } 00245 00246 00247 00248 inline 00249 void XdrIO::set_write_parallel (bool do_parallel) 00250 { 00251 this->_write_parallel = do_parallel; 00252 00253 this->_write_serial = !do_parallel; 00254 } 00255 00256 00257 00258 inline 00259 void XdrIO::set_auto_parallel () 00260 { 00261 this->_write_serial = false; 00262 this->_write_parallel = false; 00263 } 00264 00265 00266 } // namespace libMesh 00267 00268 00269 00270 #endif // LIBMESH_XDR_IO_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: