libMesh
gmv_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 // C++ includes
29 #include <map>
30 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class MeshBase;
36 enum ElemType : int;
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 &) override;
69 
73  virtual void read (const std::string & mesh_file) override;
74 
80 
85  virtual void write_nodal_data (const std::string &,
86  const std::vector<Number> &,
87  const std::vector<std::string> &) 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=nullptr) const;
135 
136 
143  void write_ascii_new_impl (const std::string &,
144  const std::vector<Number> * = nullptr,
145  const std::vector<std::string> * = 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> * = nullptr,
177  const std::vector<std::string> * = nullptr);
178 
184  void write_binary (const std::string &,
185  const std::vector<Number> * = nullptr,
186  const std::vector<std::string> * = 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:42
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
Definition: gmv_io.C:1866
void _read_var()
Definition: gmv_io.C:2016
ElemType
Defines an enum for geometric element types.
This is the EquationSystems class.
void _read_nodes()
Helper functions for reading nodes/cells from a GMV file.
Definition: gmv_io.C:2052
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
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
Definition: gmv_io.C:271
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:1221
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
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:75
bool & binary()
Flag indicating whether or not to write a binary file.
Definition: gmv_io.h:95
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
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:2136
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:209
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:57
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
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:2148
void _read_materials()
Definition: gmv_io.C:2028
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:565
bool & subdivide_second_order()
Flag indicating whether or not to subdivide second order elements.
Definition: gmv_io.h:120
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
GMVIO(const MeshBase &)
Constructor.
Definition: gmv_io.C:242
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:2071
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:1849
bool _p_levels
Flag to write the mesh p refinement levels.
Definition: gmv_io.h:217
bool _partitioning
Flag to write the mesh partitioning.
Definition: gmv_io.h:201
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:1539
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360