libMesh
gmv_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
28 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
29 namespace libMesh
30 {
31 enum ElemType : int;
32 }
33 #else
34 #include "libmesh/enum_elem_type.h"
35 #endif
36 
37 // C++ includes
38 #include <map>
39 
40 namespace libMesh
41 {
42 
43 // Forward declarations
44 class MeshBase;
45 
54 class GMVIO : public MeshInput<MeshBase>,
55  public MeshOutput<MeshBase>
56 {
57 public:
58 
63  explicit
64  GMVIO (const MeshBase &);
65 
70  explicit
71  GMVIO (MeshBase &);
72 
76  virtual void write (const std::string &) override;
77 
81  virtual void read (const std::string & mesh_file) override;
82 
88 
93  virtual void write_nodal_data (const std::string &,
94  const std::vector<Number> &,
95  const std::vector<std::string> &) override;
96 
103  bool & binary () { return _binary; }
104 
109  bool & discontinuous() { return _discontinuous; }
110 
115  bool & partitioning() { return _partitioning; }
116 
123 
129 
134  bool & p_levels() { return _p_levels; }
135 
139  void write_discontinuous_gmv (const std::string & name,
140  const EquationSystems & es,
141  const bool write_partitioning,
142  const std::set<std::string> * system_names=nullptr) const;
143 
144 
151  void write_ascii_new_impl (const std::string &,
152  const std::vector<Number> * = nullptr,
153  const std::vector<std::string> * = nullptr);
154 
166  void add_cell_centered_data (const std::string & cell_centered_data_name,
167  const std::vector<Real> * cell_centered_data_vals);
168 
174 
175 private:
176 
183  void write_ascii_old_impl (const std::string &,
184  const std::vector<Number> * = nullptr,
185  const std::vector<std::string> * = nullptr);
186 
192  void write_binary (const std::string &,
193  const std::vector<Number> * = nullptr,
194  const std::vector<std::string> * = nullptr);
195 
199  bool _binary;
200 
205 
210 
216 
221 
225  bool _p_levels;
226 
233  std::map<std::string, const std::vector<Real> * > _cell_centered_data;
234 
238  void _read_nodes();
239  unsigned int _next_elem_id;
240  void _read_one_cell();
241  ElemType gmv_elem_to_libmesh_elem(std::string elemname);
242  void _read_materials();
243  void _read_var();
244  std::map<std::string, std::vector<Number>> _nodal_data;
245 
250  static std::map<std::string, ElemType> _reading_element_map;
251 
255  static std::map<std::string, ElemType> build_reading_element_map();
256 };
257 
258 } // namespace libMesh
259 
260 
261 #endif // LIBMESH_GMV_IO_H
libMesh::GMVIO::_subdivide_second_order
bool _subdivide_second_order
Flag to subdivide second order elements.
Definition: gmv_io.h:220
libMesh::GMVIO::p_levels
bool & p_levels()
Flag indicating whether or not to write p level information for p refined meshes.
Definition: gmv_io.h:134
libMesh::GMVIO::write_ascii_old_impl
void write_ascii_old_impl(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:570
libMesh::GMVIO::copy_nodal_solution
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:2159
libMesh::GMVIO::_write_subdomain_id_as_material
bool _write_subdomain_id_as_material
Flag to write element subdomain_id's as GMV "materials" instead of element processor_id's.
Definition: gmv_io.h:215
libMesh::GMVIO::_read_materials
void _read_materials()
Definition: gmv_io.C:2042
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::GMVIO::GMVIO
GMVIO(const MeshBase &)
Constructor.
Definition: gmv_io.C:242
libMesh::GMVIO::discontinuous
bool & discontinuous()
Flag indicating whether or not to write the mesh as discontinuous cell patches.
Definition: gmv_io.h:109
libMesh::GMVIO::subdivide_second_order
bool & subdivide_second_order()
Flag indicating whether or not to subdivide second order elements.
Definition: gmv_io.h:128
libMesh::GMVIO::_read_one_cell
void _read_one_cell()
Definition: gmv_io.C:2085
libMesh::GMVIO
This class implements writing meshes in the GMV format.
Definition: gmv_io.h:54
libMesh::GMVIO::write_ascii_new_impl
void write_ascii_new_impl(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:295
libMesh::GMVIO::_partitioning
bool _partitioning
Flag to write the mesh partitioning.
Definition: gmv_io.h:209
libMesh::GMVIO::add_cell_centered_data
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:1862
libMesh::GMVIO::_p_levels
bool _p_levels
Flag to write the mesh p refinement levels.
Definition: gmv_io.h:225
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::GMVIO::write_discontinuous_gmv
void write_discontinuous_gmv(const std::string &name, const EquationSystems &es, const bool write_partitioning, const std::set< std::string > *system_names=nullptr) const
Writes a GMV file with discontinuous data.
Definition: gmv_io.C:1549
libMesh::GMVIO::_reading_element_map
static std::map< std::string, ElemType > _reading_element_map
Static map from string -> ElementType for use during reading.
Definition: gmv_io.h:250
libMesh::GMVIO::read
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
Definition: gmv_io.C:1879
libMesh::GMVIO::write
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
Definition: gmv_io.C:271
libMesh::GMVIO::_binary
bool _binary
Flag to write binary data.
Definition: gmv_io.h:199
libMesh::GMVIO::_read_var
void _read_var()
Definition: gmv_io.C:2030
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::GMVIO::_next_elem_id
unsigned int _next_elem_id
Definition: gmv_io.h:239
libMesh::GMVIO::_read_nodes
void _read_nodes()
Helper functions for reading nodes/cells from a GMV file.
Definition: gmv_io.C:2066
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::GMVIO::write_binary
void write_binary(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:1228
libMesh::GMVIO::partitioning
bool & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
Definition: gmv_io.h:115
libMesh::GMVIO::binary
bool & binary()
Flag indicating whether or not to write a binary file.
Definition: gmv_io.h:103
libMesh::GMVIO::_discontinuous
bool _discontinuous
Flag to write the mesh as discontinuous patches.
Definition: gmv_io.h:204
libMesh::GMVIO::write_subdomain_id_as_material
bool & write_subdomain_id_as_material()
Flag to write element subdomain_id's as GMV "materials" instead of element processor_id's.
Definition: gmv_io.h:122
libMesh::GMVIO::gmv_elem_to_libmesh_elem
ElemType gmv_elem_to_libmesh_elem(std::string elemname)
Definition: gmv_io.C:2149
libMesh::GMVIO::write_nodal_data
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: gmv_io.C:281
libMesh::GMVIO::_nodal_data
std::map< std::string, std::vector< Number > > _nodal_data
Definition: gmv_io.h:244
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::MeshInput
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33
libMesh::GMVIO::_cell_centered_data
std::map< std::string, const std::vector< Real > * > _cell_centered_data
Storage for arbitrary cell-centered data.
Definition: gmv_io.h:233
libMesh::GMVIO::build_reading_element_map
static std::map< std::string, ElemType > build_reading_element_map()
Static function used to build the _reading_element_map.
Definition: gmv_io.C:209