gmv_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_GMV_IO_H 00021 #define LIBMESH_GMV_IO_H 00022 00023 // Local includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/mesh_output.h" 00026 #include "libmesh/mesh_input.h" 00027 #include "libmesh/enum_elem_type.h" 00028 00029 // C++ includes 00030 #include <cstddef> 00031 #include <cstring> // for memcpy 00032 #include <map> 00033 00034 namespace libMesh 00035 { 00036 00037 // Forward declarations 00038 class MeshBase; 00039 00040 00041 00051 // ------------------------------------------------------------ 00052 // GMVIO class definition 00053 class GMVIO : public MeshInput<MeshBase>, 00054 public MeshOutput<MeshBase> 00055 { 00056 public: 00057 00062 explicit 00063 GMVIO (const MeshBase&); 00064 00069 explicit 00070 GMVIO (MeshBase&); 00071 00075 virtual void write (const std::string& ); 00076 00080 virtual void read (const std::string& mesh_file); 00081 00082 // /** 00083 // * This method implements reading a mesh from a specified file. 00084 // */ 00085 // virtual void read (const std::string& mesh_file) 00086 // { this->read_mesh_and_nodal_data(mesh_file, NULL); } 00087 00088 // /** 00089 // * Extension of the MeshInput::read() routine which 00090 // * also takes an optional EquationSystems pointer and 00091 // * tries to read field variables from the GMV file 00092 // * into the EquationSystems object. 00093 // */ 00094 // virtual void read_mesh_and_nodal_data (const std::string& , 00095 // EquationSystems* es=NULL); 00096 00101 virtual void write_nodal_data (const std::string&, 00102 const std::vector<Number>&, 00103 const std::vector<std::string>&); 00104 00115 bool & binary (); 00116 00121 bool & discontinuous(); 00122 00127 bool & partitioning(); 00128 00134 bool & write_subdomain_id_as_material(); 00135 00140 bool & subdivide_second_order(); 00141 00146 bool & p_levels(); 00147 00151 void write_discontinuous_gmv (const std::string& name, 00152 const EquationSystems& es, 00153 const bool write_partitioning) const; 00154 00155 00162 void write_ascii_new_impl (const std::string&, 00163 const std::vector<Number>* = NULL, 00164 const std::vector<std::string>* = NULL); 00165 00177 void add_cell_centered_data (const std::string& cell_centered_data_name, 00178 const std::vector<Real>* cell_centered_data_vals); 00179 00184 void copy_nodal_solution(EquationSystems& es); 00185 00186 private: 00187 00194 void write_ascii_old_impl (const std::string&, 00195 const std::vector<Number>* = NULL, 00196 const std::vector<std::string>* = NULL); 00197 00203 void write_binary (const std::string&, 00204 const std::vector<Number>* = NULL, 00205 const std::vector<std::string>* = NULL); 00206 00211 template <typename T> 00212 void to_binary_stream(std::ostream& out, 00213 const T i); 00214 00218 bool _binary; 00219 00223 bool _discontinuous; 00224 00228 bool _partitioning; 00229 00234 bool _write_subdomain_id_as_material; 00235 00239 bool _subdivide_second_order; 00240 00244 bool _p_levels; 00245 00252 std::map<std::string, const std::vector<Real>* > _cell_centered_data; 00253 00257 void _read_nodes(); 00258 unsigned int _next_elem_id; 00259 void _read_one_cell(); 00260 ElemType _gmv_elem_to_libmesh_elem(const char* elemname); 00261 void _read_materials(); 00262 void _read_var(); 00263 std::map<std::string, std::vector<Number> > _nodal_data; 00264 }; 00265 00266 00267 00268 // ------------------------------------------------------------ 00269 // GMVIO inline members 00270 inline 00271 GMVIO::GMVIO (const MeshBase& mesh) : 00272 MeshOutput<MeshBase> (mesh), 00273 _binary (false), 00274 _discontinuous (false), 00275 _partitioning (true), 00276 _write_subdomain_id_as_material (false), 00277 _subdivide_second_order (true), 00278 _p_levels (true), 00279 _next_elem_id (0) 00280 { 00281 } 00282 00283 inline 00284 GMVIO::GMVIO (MeshBase& mesh) : 00285 MeshInput<MeshBase> (mesh), 00286 MeshOutput<MeshBase>(mesh), 00287 _binary (false), 00288 _discontinuous (false), 00289 _partitioning (true), 00290 _write_subdomain_id_as_material (false), 00291 _subdivide_second_order (true), 00292 _p_levels (true), 00293 _next_elem_id (0) 00294 { 00295 } 00296 00297 00298 00299 inline 00300 bool & GMVIO::binary () 00301 { 00302 return _binary; 00303 } 00304 00305 00306 00307 inline 00308 bool & GMVIO::discontinuous () 00309 { 00310 return _discontinuous; 00311 } 00312 00313 00314 00315 inline 00316 bool & GMVIO::partitioning () 00317 { 00318 return _partitioning; 00319 } 00320 00321 00322 inline 00323 bool & GMVIO::write_subdomain_id_as_material () 00324 { 00325 return _write_subdomain_id_as_material; 00326 } 00327 00328 00329 00330 inline 00331 bool & GMVIO::subdivide_second_order () 00332 { 00333 return _subdivide_second_order; 00334 } 00335 00336 00337 00338 inline 00339 bool & GMVIO::p_levels() 00340 { 00341 return _p_levels; 00342 } 00343 00344 00345 00346 template <typename T> 00347 void GMVIO::to_binary_stream(std::ostream& out_str, 00348 const T i) 00349 { 00350 static char buf[sizeof(T)]; 00351 memcpy(buf, &i, sizeof(T)); 00352 out_str.write(buf, sizeof(T)); 00353 } 00354 00355 } // namespace libMesh 00356 00357 00358 #endif // LIBMESH_GMV_IO_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: