gmsh_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_GMSH_IO_H
21 #define LIBMESH_GMSH_IO_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/mesh_input.h"
26 #include "libmesh/mesh_output.h"
27 
28 // C++ includes
29 #include <cstddef>
30 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 class MeshBase;
36 
37 
38 
50 class GmshIO : public MeshInput<MeshBase>,
51  public MeshOutput<MeshBase>
52 {
53 public:
54 
59  explicit
60  GmshIO (MeshBase & mesh);
61 
66  explicit
67  GmshIO (const MeshBase & mesh);
68 
76  virtual void read (const std::string & name) override;
77 
82  virtual void write (const std::string & name) override;
83 
89 
94  virtual void write_nodal_data (const std::string &,
95  const std::vector<Number> &,
96  const std::vector<std::string> &) override;
97 
108  bool & binary ();
109 
115 
116 private:
122  void read_mesh (std::istream & in);
123 
128  void write_mesh (std::ostream & out);
129 
135  void write_post (const std::string &,
136  const std::vector<Number> * = nullptr,
137  const std::vector<std::string> * = nullptr);
138 
142  bool _binary;
143 
149 
154  {
156  unsigned gmsh_type_in,
157  unsigned dim_in,
158  unsigned nnodes_in) :
159  type(type_in),
160  gmsh_type(gmsh_type_in),
161  dim(dim_in),
162  nnodes(nnodes_in)
163  {}
164 
166  unsigned int gmsh_type;
167  unsigned int dim;
168  unsigned int nnodes;
169  std::vector<unsigned int> nodes;
170  };
171 
176  struct ElementMaps
177  {
178  // Helper function to add a (key, value) pair to both maps
179  void add_def(const ElementDefinition & eledef)
180  {
181  out.insert(std::make_pair(eledef.type, eledef));
182  in.insert(std::make_pair(eledef.gmsh_type, eledef));
183  }
184 
185  std::map<ElemType, ElementDefinition> out;
186  std::map<unsigned int, ElementDefinition> in;
187  };
188 
194 
200 };
201 
202 
203 } // namespace libMesh
204 
205 #endif // LIBMESH_GMSH_IO_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
virtual void write(const std::string &name) override
Definition: gmsh_io.C:612
bool & write_lower_dimensional_elements()
Definition: gmsh_io.C:137
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Definition: gmsh_io.C:629
bool & binary()
Definition: gmsh_io.C:130
std::map< unsigned int, ElementDefinition > in
Definition: gmsh_io.h:186
Base class for Mesh.
Definition: mesh_base.h:77
std::map< ElemType, ElementDefinition > out
Definition: gmsh_io.h:185
ElementDefinition(ElemType type_in, unsigned gmsh_type_in, unsigned dim_in, unsigned nnodes_in)
Definition: gmsh_io.h:155
void write_mesh(std::ostream &out)
Definition: gmsh_io.C:641
bool _write_lower_dimensional_elements
Definition: gmsh_io.h:148
static ElementMaps build_element_maps()
Definition: gmsh_io.C:42
static ElementMaps _element_maps
Definition: gmsh_io.h:193
GmshIO(MeshBase &mesh)
Definition: gmsh_io.C:120
void add_def(const ElementDefinition &eledef)
Definition: gmsh_io.h:179
virtual void read(const std::string &name) override
Definition: gmsh_io.C:144
OStreamProxy out(std::cout)
void write_post(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
Definition: gmsh_io.C:803
void read_mesh(std::istream &in)
Definition: gmsh_io.C:152
std::vector< unsigned int > nodes
Definition: gmsh_io.h:169