gmv_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_GMV_IO_H
21 #define LIBMESH_GMV_IO_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/mesh_output.h"
26 #include "libmesh/mesh_input.h"
27 #include "libmesh/enum_elem_type.h"
28 
29 // C++ includes
30 #include <cstddef>
31 #include <cstring> // for memcpy
32 #include <map>
33 
34 namespace libMesh
35 {
36 
37 // Forward declarations
38 class MeshBase;
39 
40 
41 
51 // ------------------------------------------------------------
52 // GMVIO class definition
53 class GMVIO : public MeshInput<MeshBase>,
54  public MeshOutput<MeshBase>
55 {
56  public:
57 
62  explicit
63  GMVIO (const MeshBase&);
64 
69  explicit
70  GMVIO (MeshBase&);
71 
75  virtual void write (const std::string& );
76 
80  virtual void read (const std::string& mesh_file);
81 
82 // /**
83 // * This method implements reading a mesh from a specified file.
84 // */
85 // virtual void read (const std::string& mesh_file)
86 // { this->read_mesh_and_nodal_data(mesh_file, NULL); }
87 
88 // /**
89 // * Extension of the MeshInput::read() routine which
90 // * also takes an optional EquationSystems pointer and
91 // * tries to read field variables from the GMV file
92 // * into the EquationSystems object.
93 // */
94 // virtual void read_mesh_and_nodal_data (const std::string& ,
95 // EquationSystems* es=NULL);
96 
101  virtual void write_nodal_data (const std::string&,
102  const std::vector<Number>&,
103  const std::vector<std::string>&);
104 
115  bool & binary ();
116 
121  bool & discontinuous();
122 
127  bool & partitioning();
128 
135 
140  bool & subdivide_second_order();
141 
146  bool & p_levels();
147 
151  void write_discontinuous_gmv (const std::string& name,
152  const EquationSystems& es,
153  const bool write_partitioning) const;
154 
155 
162  void write_ascii_new_impl (const std::string&,
163  const std::vector<Number>* = NULL,
164  const std::vector<std::string>* = NULL);
165 
177  void add_cell_centered_data (const std::string& cell_centered_data_name,
178  const std::vector<Real>* cell_centered_data_vals);
179 
185 
186 private:
187 
194  void write_ascii_old_impl (const std::string&,
195  const std::vector<Number>* = NULL,
196  const std::vector<std::string>* = NULL);
197 
203  void write_binary (const std::string&,
204  const std::vector<Number>* = NULL,
205  const std::vector<std::string>* = NULL);
206 
211  template <typename T>
212  void to_binary_stream(std::ostream& out,
213  const T i);
214 
218  bool _binary;
219 
224 
229 
235 
240 
244  bool _p_levels;
245 
252  std::map<std::string, const std::vector<Real>* > _cell_centered_data;
253 
257  void _read_nodes();
258  unsigned int _next_elem_id;
259  void _read_one_cell();
260  ElemType _gmv_elem_to_libmesh_elem(const char* elemname);
261  void _read_materials();
262  void _read_var();
263  std::map<std::string, std::vector<Number> > _nodal_data;
264 };
265 
266 
267 
268 // ------------------------------------------------------------
269 // GMVIO inline members
270 inline
272  MeshOutput<MeshBase> (mesh),
273  _binary (false),
274  _discontinuous (false),
275  _partitioning (true),
276  _write_subdomain_id_as_material (false),
277  _subdivide_second_order (true),
278  _p_levels (true),
279  _next_elem_id (0)
280 {
281 }
282 
283 inline
285  MeshInput<MeshBase> (mesh),
286  MeshOutput<MeshBase>(mesh),
287  _binary (false),
288  _discontinuous (false),
289  _partitioning (true),
290  _write_subdomain_id_as_material (false),
291  _subdivide_second_order (true),
292  _p_levels (true),
293  _next_elem_id (0)
294 {
295 }
296 
297 
298 
299 inline
300 bool & GMVIO::binary ()
301 {
302  return _binary;
303 }
304 
305 
306 
307 inline
309 {
310  return _discontinuous;
311 }
312 
313 
314 
315 inline
317 {
318  return _partitioning;
319 }
320 
321 
322 inline
324 {
326 }
327 
328 
329 
330 inline
332 {
334 }
335 
336 
337 
338 inline
340 {
341  return _p_levels;
342 }
343 
344 
345 
346 template <typename T>
347 void GMVIO::to_binary_stream(std::ostream& out_str,
348  const T i)
349 {
350  static char buf[sizeof(T)];
351  memcpy(buf, &i, sizeof(T));
352  out_str.write(buf, sizeof(T));
353 }
354 
355 } // namespace libMesh
356 
357 
358 #endif // LIBMESH_GMV_IO_H

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

Hosted By:
SourceForge.net Logo