libMesh
gmsh_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_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 
51 class GmshIO : public MeshInput<MeshBase>,
52  public MeshOutput<MeshBase>
53 {
54 public:
55 
60  explicit
61  GmshIO (MeshBase & mesh);
62 
67  explicit
68  GmshIO (const MeshBase & mesh);
69 
83  virtual void read (const std::string & name) override;
84 
89  virtual void write (const std::string & name) override;
90 
96 
101  virtual void write_nodal_data (const std::string &,
102  const std::vector<Number> &,
103  const std::vector<std::string> &) override;
104 
115  bool & binary ();
116 
122 
123 private:
129  void read_mesh (std::istream & in);
130 
135  void write_mesh (std::ostream & out);
136 
142  void write_post (const std::string &,
143  const std::vector<Number> * = nullptr,
144  const std::vector<std::string> * = nullptr);
145 
149  bool _binary;
150 
156 
161  {
163  unsigned gmsh_type_in,
164  unsigned dim_in,
165  unsigned nnodes_in) :
166  type(type_in),
167  gmsh_type(gmsh_type_in),
168  dim(dim_in),
169  nnodes(nnodes_in)
170  {}
171 
173  unsigned int gmsh_type;
174  unsigned int dim;
175  unsigned int nnodes;
176  std::vector<unsigned int> nodes;
177  };
178 
183  struct ElementMaps
184  {
185  // Helper function to add a (key, value) pair to both maps
186  void add_def(const ElementDefinition & eledef)
187  {
188  out.insert(std::make_pair(eledef.type, eledef));
189  in.insert(std::make_pair(eledef.gmsh_type, eledef));
190  }
191 
192  std::map<ElemType, ElementDefinition> out;
193  std::map<unsigned int, ElementDefinition> in;
194  };
195 
201 
207 };
208 
209 
210 } // namespace libMesh
211 
212 #endif // LIBMESH_GMSH_IO_H
libMesh::GmshIO::ElementMaps::in
std::map< unsigned int, ElementDefinition > in
Definition: gmsh_io.h:193
libMesh::GmshIO::read
virtual void read(const std::string &name) override
Reads in a mesh in the Gmsh *.msh format from the ASCII file given by name.
Definition: gmsh_io.C:147
libMesh::GmshIO::ElementDefinition::dim
unsigned int dim
Definition: gmsh_io.h:174
libMesh::GmshIO::_binary
bool _binary
Flag to write binary data.
Definition: gmsh_io.h:149
libMesh::GmshIO::ElementMaps
struct which holds a map from Gmsh to libMesh element numberings and vice-versa.
Definition: gmsh_io.h:183
libMesh::GmshIO::ElementDefinition::nnodes
unsigned int nnodes
Definition: gmsh_io.h:175
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::GmshIO
Reading and writing meshes in the Gmsh format.
Definition: gmsh_io.h:51
libMesh::GmshIO::ElementDefinition::nodes
std::vector< unsigned int > nodes
Definition: gmsh_io.h:176
libMesh::GmshIO::_element_maps
static ElementMaps _element_maps
A static ElementMaps object that is built statically and used by all instances of this class.
Definition: gmsh_io.h:200
libMesh::GmshIO::write_lower_dimensional_elements
bool & write_lower_dimensional_elements()
Access to the flag which controls whether boundary elements are written to the Mesh file.
Definition: gmsh_io.C:140
libMesh::GmshIO::_write_lower_dimensional_elements
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:155
libMesh::GmshIO::ElementDefinition::type
ElemType type
Definition: gmsh_io.h:172
libMesh::GmshIO::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: gmsh_io.C:848
libMesh::GmshIO::write_post
void write_post(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: gmsh_io.C:1006
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::GmshIO::GmshIO
GmshIO(MeshBase &mesh)
Constructor.
Definition: gmsh_io.C:123
libMesh::GmshIO::ElementDefinition::gmsh_type
unsigned int gmsh_type
Definition: gmsh_io.h:173
libMesh::GmshIO::binary
bool & binary()
Flag indicating whether or not to write a binary file.
Definition: gmsh_io.C:133
libMesh::GmshIO::ElementDefinition::ElementDefinition
ElementDefinition(ElemType type_in, unsigned gmsh_type_in, unsigned dim_in, unsigned nnodes_in)
Definition: gmsh_io.h:162
libMesh::GmshIO::ElementMaps::add_def
void add_def(const ElementDefinition &eledef)
Definition: gmsh_io.h:186
libMesh::GmshIO::read_mesh
void read_mesh(std::istream &in)
Implementation of the read() function.
Definition: gmsh_io.C:155
libMesh::GmshIO::write_mesh
void write_mesh(std::ostream &out)
This method implements writing a mesh to a specified file.
Definition: gmsh_io.C:860
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::MeshInput< MeshBase >::mesh
MeshBase & mesh()
Definition: mesh_input.h:169
libMesh::GmshIO::write
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file in the Gmsh *.msh format.
Definition: gmsh_io.C:831
libMesh::GmshIO::ElementMaps::out
std::map< ElemType, ElementDefinition > out
Definition: gmsh_io.h:192
libMesh::GmshIO::ElementDefinition
Defines mapping from libMesh element types to Gmsh element types or vice-versa.
Definition: gmsh_io.h:160
libMesh::out
OStreamProxy out
libMesh::GmshIO::build_element_maps
static ElementMaps build_element_maps()
A static function used to construct the _element_maps struct, statically.
Definition: gmsh_io.C:45
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