libMesh
gmsh_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_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) libmesh_override;
77 
82  virtual void write (const std::string & name) libmesh_override;
83 
89 
94  virtual void write_nodal_data (const std::string &,
95  const std::vector<Number> &,
96  const std::vector<std::string> &) libmesh_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> * = libmesh_nullptr,
137  const std::vector<std::string> * = libmesh_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)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
This class implements writing meshes in the Gmsh format.
Definition: gmsh_io.h:50
bool _binary
Flag to write binary data.
Definition: gmsh_io.h:142
ElemType
Defines an enum for geometric element types.
bool & write_lower_dimensional_elements()
Access to the flag which controls whether boundary elements are written to the Mesh file...
Definition: gmsh_io.C:137
void write_post(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: gmsh_io.C:812
const class libmesh_nullptr_t libmesh_nullptr
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
bool & binary()
Flag indicating whether or not to write a binary file.
Definition: gmsh_io.C:130
The libMesh namespace provides an interface to certain functionality in the library.
std::map< unsigned int, ElementDefinition > in
Definition: gmsh_io.h:186
This is the MeshBase class.
Definition: mesh_base.h:68
std::map< ElemType, ElementDefinition > out
Definition: gmsh_io.h:185
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:50
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)
This method implements writing a mesh to a specified file.
Definition: gmsh_io.C:644
bool _write_lower_dimensional_elements
If true, lower-dimensional elements based on the boundary conditions get written to the output file...
Definition: gmsh_io.h:148
Defines mapping from libMesh element types to Gmsh element types or vice-versa.
Definition: gmsh_io.h:153
static ElementMaps build_element_maps()
A static function used to construct the _element_maps struct, statically.
Definition: gmsh_io.C:42
virtual void write(const std::string &name) libmesh_override
This method implements writing a mesh to a specified file in the Gmsh *.msh format.
Definition: gmsh_io.C:615
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: gmsh_io.C:632
OStreamProxy out
static ElementMaps _element_maps
A static ElementMaps object that is built statically and used by all instances of this class...
Definition: gmsh_io.h:193
virtual void read(const std::string &name) libmesh_override
Reads in a mesh in the Gmsh *.msh format from the ASCII file given by name.
Definition: gmsh_io.C:144
GmshIO(MeshBase &mesh)
Constructor.
Definition: gmsh_io.C:120
void add_def(const ElementDefinition &eledef)
Definition: gmsh_io.h:179
struct which holds a map from Gmsh to libMesh element numberings and vice-versa.
Definition: gmsh_io.h:176
void read_mesh(std::istream &in)
Implementation of the read() function.
Definition: gmsh_io.C:152
std::vector< unsigned int > nodes
Definition: gmsh_io.h:169