$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_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, 00154 const std::set<std::string>* system_names=NULL) const; 00155 00156 00163 void write_ascii_new_impl (const std::string&, 00164 const std::vector<Number>* = NULL, 00165 const std::vector<std::string>* = NULL); 00166 00178 void add_cell_centered_data (const std::string& cell_centered_data_name, 00179 const std::vector<Real>* cell_centered_data_vals); 00180 00185 void copy_nodal_solution(EquationSystems& es); 00186 00187 private: 00188 00195 void write_ascii_old_impl (const std::string&, 00196 const std::vector<Number>* = NULL, 00197 const std::vector<std::string>* = NULL); 00198 00204 void write_binary (const std::string&, 00205 const std::vector<Number>* = NULL, 00206 const std::vector<std::string>* = NULL); 00207 00212 template <typename T> 00213 void to_binary_stream(std::ostream& out, 00214 const T i); 00215 00219 bool _binary; 00220 00224 bool _discontinuous; 00225 00229 bool _partitioning; 00230 00235 bool _write_subdomain_id_as_material; 00236 00240 bool _subdivide_second_order; 00241 00245 bool _p_levels; 00246 00253 std::map<std::string, const std::vector<Real>* > _cell_centered_data; 00254 00258 void _read_nodes(); 00259 unsigned int _next_elem_id; 00260 void _read_one_cell(); 00261 ElemType _gmv_elem_to_libmesh_elem(const char* elemname); 00262 void _read_materials(); 00263 void _read_var(); 00264 std::map<std::string, std::vector<Number> > _nodal_data; 00265 }; 00266 00267 00268 00269 // ------------------------------------------------------------ 00270 // GMVIO inline members 00271 inline 00272 GMVIO::GMVIO (const MeshBase& mesh) : 00273 MeshOutput<MeshBase> (mesh), 00274 _binary (false), 00275 _discontinuous (false), 00276 _partitioning (true), 00277 _write_subdomain_id_as_material (false), 00278 _subdivide_second_order (true), 00279 _p_levels (true), 00280 _next_elem_id (0) 00281 { 00282 } 00283 00284 inline 00285 GMVIO::GMVIO (MeshBase& mesh) : 00286 MeshInput<MeshBase> (mesh), 00287 MeshOutput<MeshBase>(mesh), 00288 _binary (false), 00289 _discontinuous (false), 00290 _partitioning (true), 00291 _write_subdomain_id_as_material (false), 00292 _subdivide_second_order (true), 00293 _p_levels (true), 00294 _next_elem_id (0) 00295 { 00296 } 00297 00298 00299 00300 inline 00301 bool & GMVIO::binary () 00302 { 00303 return _binary; 00304 } 00305 00306 00307 00308 inline 00309 bool & GMVIO::discontinuous () 00310 { 00311 return _discontinuous; 00312 } 00313 00314 00315 00316 inline 00317 bool & GMVIO::partitioning () 00318 { 00319 return _partitioning; 00320 } 00321 00322 00323 inline 00324 bool & GMVIO::write_subdomain_id_as_material () 00325 { 00326 return _write_subdomain_id_as_material; 00327 } 00328 00329 00330 00331 inline 00332 bool & GMVIO::subdivide_second_order () 00333 { 00334 return _subdivide_second_order; 00335 } 00336 00337 00338 00339 inline 00340 bool & GMVIO::p_levels() 00341 { 00342 return _p_levels; 00343 } 00344 00345 00346 00347 template <typename T> 00348 void GMVIO::to_binary_stream(std::ostream& out_str, 00349 const T i) 00350 { 00351 static char buf[sizeof(T)]; 00352 memcpy(buf, &i, sizeof(T)); 00353 out_str.write(buf, sizeof(T)); 00354 } 00355 00356 } // namespace libMesh 00357 00358 00359 #endif // LIBMESH_GMV_IO_H