unv_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_UNV_IO_H 00021 #define LIBMESH_UNV_IO_H 00022 00023 00024 // Local includes 00025 #include "libmesh/mesh_input.h" 00026 #include "libmesh/mesh_output.h" 00027 00028 // C++ inludes 00029 #include <cstddef> 00030 #include <map> 00031 #include <string> 00032 #include <vector> 00033 00034 namespace libMesh 00035 { 00036 00037 // Forward declarations 00038 class MeshBase; 00039 class MeshData; 00040 00047 // ------------------------------------------------------------ 00048 // UNVIO class definition 00049 class UNVIO : public MeshInput<MeshBase>, 00050 public MeshOutput<MeshBase> 00051 { 00052 00053 public: 00054 00059 UNVIO (MeshBase& mesh, MeshData& mesh_data); 00060 00065 UNVIO (const MeshBase& mesh, MeshData& mesh_data); 00066 00070 virtual ~UNVIO (); 00071 00075 virtual void read (const std::string& ); 00076 00080 virtual void write (const std::string& ); 00081 00085 bool & verbose (); 00086 00087 00088 private: 00089 00090 00096 void read_implementation (std::istream& in_stream); 00097 00103 void write_implementation (std::ostream& out_stream); 00104 00109 void clear(); 00110 00111 00112 //------------------------------------------------------------- 00113 // read support methods 00119 void count_nodes (std::istream& in_file); 00120 00130 void node_in (std::istream& in_file); 00131 00136 void count_elements (std::istream& in_file); 00137 00145 void element_in (std::istream& in_file); 00146 00152 bool beginning_of_dataset (std::istream& in_file, 00153 const std::string& ds_name) const; 00154 00161 Real D_to_e (std::string& number) const; 00162 00163 00164 //------------------------------------------------------------- 00165 // write support methods 00172 void node_out (std::ostream& out_file); 00173 00180 void element_out (std::ostream& out_file); 00181 00182 00183 //------------------------------------------------------------- 00184 // local data 00185 00189 bool _verbose; 00190 00194 std::vector<dof_id_type> _assign_nodes; 00195 00200 std::map<std::string,std::streampos> _ds_position; 00201 00206 dof_id_type _n_nodes; 00207 00212 dof_id_type _n_elements; 00213 00217 static const std::string _label_dataset_nodes; 00218 00222 static const std::string _label_dataset_elements; 00223 00228 bool _need_D_to_e; 00229 00234 MeshData& _mesh_data; 00235 00236 }; 00237 00238 00239 00240 // ------------------------------------------------------------ 00241 // MeshIO inline members 00242 inline 00243 UNVIO::UNVIO (MeshBase& mesh, MeshData& mesh_data) : 00244 MeshInput<MeshBase> (mesh), 00245 MeshOutput<MeshBase>(mesh), 00246 _verbose (false), 00247 _mesh_data (mesh_data) 00248 { 00249 } 00250 00251 00252 00253 inline 00254 UNVIO::UNVIO (const MeshBase& mesh, MeshData& mesh_data) : 00255 MeshOutput<MeshBase> (mesh), 00256 _verbose (false), 00257 _mesh_data (mesh_data) 00258 { 00259 } 00260 00261 00262 00263 inline 00264 UNVIO::~UNVIO () 00265 { 00266 this->clear (); 00267 } 00268 00269 00270 00271 inline 00272 bool & UNVIO::verbose () 00273 { 00274 return _verbose; 00275 } 00276 00277 00278 00279 inline 00280 bool UNVIO::beginning_of_dataset (std::istream& in_file, 00281 const std::string& ds_name) const 00282 { 00283 libmesh_assert (in_file.good()); 00284 libmesh_assert (!ds_name.empty()); 00285 00286 std::string olds, news; 00287 00288 while (true) 00289 { 00290 in_file >> olds >> news; 00291 00292 /* 00293 * a "-1" followed by a number means the beginning of a dataset 00294 * stop combing at the end of the file 00295 */ 00296 while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() ) 00297 { 00298 olds = news; 00299 in_file >> news; 00300 } 00301 00302 if (in_file.eof()) 00303 return false; 00304 00305 if (news == ds_name) 00306 return true; 00307 } 00308 00309 // should never end up here 00310 libmesh_error(); 00311 return false; 00312 } 00313 00314 00315 00316 inline 00317 Real UNVIO::D_to_e (std::string& number) const 00318 { 00319 /* find "D" in string, start looking at 00320 * 6th element, to improve speed. 00321 * We dont expect a "D" earlier 00322 */ 00323 00324 #ifdef __HP_aCC 00325 // Use an int instead of an unsigned int, 00326 // otherwise HP aCC may crash! 00327 const int position = number.find("D",6); 00328 #else 00329 const std::string::size_type position = number.find("D",6); 00330 #endif 00331 00332 libmesh_assert (position != std::string::npos); 00333 number.replace(position, 1, "e"); 00334 00335 return std::atof (number.c_str()); 00336 } 00337 00338 00339 } // namespace libMesh 00340 00341 00342 #endif // LIBMESH_UNV_IO_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: