libMesh
gmv_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 <map>
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class MeshBase;
37 
46 class GMVIO : public MeshInput<MeshBase>,
47  public MeshOutput<MeshBase>
48 {
49 public:
50 
55  explicit
56  GMVIO (const MeshBase &);
57 
62  explicit
63  GMVIO (MeshBase &);
64 
68  virtual void write (const std::string &) libmesh_override;
69 
73  virtual void read (const std::string & mesh_file) libmesh_override;
74 
80 
85  virtual void write_nodal_data (const std::string &,
86  const std::vector<Number> &,
87  const std::vector<std::string> &) libmesh_override;
88 
95  bool & binary () { return _binary; }
96 
101  bool & discontinuous() { return _discontinuous; }
102 
107  bool & partitioning() { return _partitioning; }
108 
115 
121 
126  bool & p_levels() { return _p_levels; }
127 
131  void write_discontinuous_gmv (const std::string & name,
132  const EquationSystems & es,
133  const bool write_partitioning,
134  const std::set<std::string> * system_names=libmesh_nullptr) const;
135 
136 
143  void write_ascii_new_impl (const std::string &,
144  const std::vector<Number> * = libmesh_nullptr,
145  const std::vector<std::string> * = libmesh_nullptr);
146 
158  void add_cell_centered_data (const std::string & cell_centered_data_name,
159  const std::vector<Real> * cell_centered_data_vals);
160 
166 
167 private:
168 
175  void write_ascii_old_impl (const std::string &,
176  const std::vector<Number> * = libmesh_nullptr,
177  const std::vector<std::string> * = libmesh_nullptr);
178 
184  void write_binary (const std::string &,
185  const std::vector<Number> * = libmesh_nullptr,
186  const std::vector<std::string> * = libmesh_nullptr);
187 
191  bool _binary;
192 
197 
202 
208 
213 
217  bool _p_levels;
218 
225  std::map<std::string, const std::vector<Real> * > _cell_centered_data;
226 
230  void _read_nodes();
231  unsigned int _next_elem_id;
232  void _read_one_cell();
233  ElemType gmv_elem_to_libmesh_elem(std::string elemname);
234  void _read_materials();
235  void _read_var();
236  std::map<std::string, std::vector<Number>> _nodal_data;
237 
242  static std::map<std::string, ElemType> _reading_element_map;
243 
247  static std::map<std::string, ElemType> build_reading_element_map();
248 };
249 
250 } // namespace libMesh
251 
252 
253 #endif // LIBMESH_GMV_IO_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
void _read_var()
Definition: gmv_io.C:2043
This is the EquationSystems class.
void _read_nodes()
Helper functions for reading nodes/cells from a GMV file.
Definition: gmv_io.C:2098
bool _binary
Flag to write binary data.
Definition: gmv_io.h:191
static std::map< std::string, ElemType > _reading_element_map
Static map from string -> ElementType for use during reading.
Definition: gmv_io.h:242
ElemType
Defines an enum for geometric element types.
unsigned int _next_elem_id
Definition: gmv_io.h:231
bool _discontinuous
Flag to write the mesh as discontinuous patches.
Definition: gmv_io.h:196
const class libmesh_nullptr_t libmesh_nullptr
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
The libMesh namespace provides an interface to certain functionality in the library.
This class implements writing meshes in the GMV format.
Definition: gmv_io.h:46
bool & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
Definition: gmv_io.h:107
std::map< std::string, std::vector< Number > > _nodal_data
Definition: gmv_io.h:236
This is the MeshBase class.
Definition: mesh_base.h:68
bool & binary()
Flag indicating whether or not to write a binary file.
Definition: gmv_io.h:95
void write_ascii_old_impl(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:569
bool & write_subdomain_id_as_material()
Flag to write element subdomain_id&#39;s as GMV "materials" instead of element processor_id&#39;s.
Definition: gmv_io.h:114
ElemType gmv_elem_to_libmesh_elem(std::string elemname)
Definition: gmv_io.C:2203
std::map< std::string, const std::vector< Real > * > _cell_centered_data
Storage for arbitrary cell-centered data.
Definition: gmv_io.h:225
static std::map< std::string, ElemType > build_reading_element_map()
Static function used to build the _reading_element_map.
Definition: gmv_io.C:205
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:50
bool _write_subdomain_id_as_material
Flag to write element subdomain_id&#39;s as GMV "materials" instead of element processor_id&#39;s.
Definition: gmv_io.h:207
void write_discontinuous_gmv(const std::string &name, const EquationSystems &es, const bool write_partitioning, const std::set< std::string > *system_names=libmesh_nullptr) const
Writes a GMV file with discontinuous data.
Definition: gmv_io.C:1556
void write_ascii_new_impl(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:291
bool & p_levels()
Flag indicating whether or not to write p level information for p refined meshes. ...
Definition: gmv_io.h:126
bool _subdivide_second_order
Flag to subdivide second order elements.
Definition: gmv_io.h:212
void copy_nodal_solution(EquationSystems &es)
If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution in...
Definition: gmv_io.C:2220
void _read_materials()
Definition: gmv_io.C:2055
virtual void write(const std::string &) libmesh_override
This method implements writing a mesh to a specified file.
Definition: gmv_io.C:267
bool & subdivide_second_order()
Flag indicating whether or not to subdivide second order elements.
Definition: gmv_io.h:120
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) libmesh_override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:277
GMVIO(const MeshBase &)
Constructor.
Definition: gmv_io.C:238
bool & discontinuous()
Flag indicating whether or not to write the mesh as discontinuous cell patches.
Definition: gmv_io.h:101
void _read_one_cell()
Definition: gmv_io.C:2129
void add_cell_centered_data(const std::string &cell_centered_data_name, const std::vector< Real > *cell_centered_data_vals)
Takes a vector of cell-centered data to be plotted.
Definition: gmv_io.C:1869
bool _p_levels
Flag to write the mesh p refinement levels.
Definition: gmv_io.h:217
virtual void read(const std::string &mesh_file) libmesh_override
This method implements reading a mesh from a specified file.
Definition: gmv_io.C:1886
bool _partitioning
Flag to write the mesh partitioning.
Definition: gmv_io.h:201
void write_binary(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:1232