unv_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_UNV_IO_H
21 #define LIBMESH_UNV_IO_H
22 
23 
24 // Local includes
25 #include "libmesh/mesh_input.h"
26 #include "libmesh/mesh_output.h"
27 
28 // C++ inludes
29 #include <cstddef>
30 #include <map>
31 #include <string>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 
37 // Forward declarations
38 class MeshBase;
39 class MeshData;
40 
47 // ------------------------------------------------------------
48 // UNVIO class definition
49 class UNVIO : public MeshInput<MeshBase>,
50  public MeshOutput<MeshBase>
51 {
52 
53  public:
54 
59  UNVIO (MeshBase& mesh, MeshData& mesh_data);
60 
65  UNVIO (const MeshBase& mesh, MeshData& mesh_data);
66 
70  virtual ~UNVIO ();
71 
75  virtual void read (const std::string& );
76 
80  virtual void write (const std::string& );
81 
85  bool & verbose ();
86 
87 
88  private:
89 
90 
96  void read_implementation (std::istream& in_stream);
97 
103  void write_implementation (std::ostream& out_stream);
104 
109  void clear();
110 
111 
112  //-------------------------------------------------------------
113  // read support methods
119  void count_nodes (std::istream& in_file);
120 
130  void node_in (std::istream& in_file);
131 
136  void count_elements (std::istream& in_file);
137 
145  void element_in (std::istream& in_file);
146 
152  bool beginning_of_dataset (std::istream& in_file,
153  const std::string& ds_name) const;
154 
161  Real D_to_e (std::string& number) const;
162 
163 
164  //-------------------------------------------------------------
165  // write support methods
172  void node_out (std::ostream& out_file);
173 
180  void element_out (std::ostream& out_file);
181 
182 
183  //-------------------------------------------------------------
184  // local data
185 
189  bool _verbose;
190 
194  std::vector<dof_id_type> _assign_nodes;
195 
200  std::map<std::string,std::streampos> _ds_position;
201 
207 
213 
217  static const std::string _label_dataset_nodes;
218 
222  static const std::string _label_dataset_elements;
223 
229 
235 
236 };
237 
238 
239 
240 // ------------------------------------------------------------
241 // MeshIO inline members
242 inline
244  MeshInput<MeshBase> (mesh),
245  MeshOutput<MeshBase>(mesh),
246  _verbose (false),
247  _mesh_data (mesh_data)
248 {
249 }
250 
251 
252 
253 inline
254 UNVIO::UNVIO (const MeshBase& mesh, MeshData& mesh_data) :
255  MeshOutput<MeshBase> (mesh),
256  _verbose (false),
257  _mesh_data (mesh_data)
258 {
259 }
260 
261 
262 
263 inline
265 {
266  this->clear ();
267 }
268 
269 
270 
271 inline
272 bool & UNVIO::verbose ()
273 {
274  return _verbose;
275 }
276 
277 
278 
279 inline
280 bool UNVIO::beginning_of_dataset (std::istream& in_file,
281  const std::string& ds_name) const
282 {
283  libmesh_assert (in_file.good());
284  libmesh_assert (!ds_name.empty());
285 
286  std::string olds, news;
287 
288  while (true)
289  {
290  in_file >> olds >> news;
291 
292  /*
293  * a "-1" followed by a number means the beginning of a dataset
294  * stop combing at the end of the file
295  */
296  while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() )
297  {
298  olds = news;
299  in_file >> news;
300  }
301 
302  if (in_file.eof())
303  return false;
304 
305  if (news == ds_name)
306  return true;
307  }
308 
309  // should never end up here
310  libmesh_error();
311  return false;
312 }
313 
314 
315 
316 inline
317 Real UNVIO::D_to_e (std::string& number) const
318 {
319  /* find "D" in string, start looking at
320  * 6th element, to improve speed.
321  * We dont expect a "D" earlier
322  */
323 
324 #ifdef __HP_aCC
325  // Use an int instead of an unsigned int,
326  // otherwise HP aCC may crash!
327  const int position = number.find("D",6);
328 #else
329  const std::string::size_type position = number.find("D",6);
330 #endif
331 
332  libmesh_assert (position != std::string::npos);
333  number.replace(position, 1, "e");
334 
335  return std::atof (number.c_str());
336 }
337 
338 
339 } // namespace libMesh
340 
341 
342 #endif // LIBMESH_UNV_IO_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo