LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
gmsh_reader.h
1/***************************************************************************
2 * LehrFEM++ - A simple C++ finite element library for teaching
3 * Developed from 2018 at the Seminar of Applied Mathematics of ETH Zurich,
4 * lead developers Dr. R. Casagrande and Prof. R. Hiptmair
5 ***************************************************************************/
6
15#ifndef __7fedf7cf1a0246a98b2bf431cfa34da2
16#define __7fedf7cf1a0246a98b2bf431cfa34da2
17#include <lf/mesh/mesh.h>
18#include <lf/mesh/utils/utils.h>
19
20#include <map>
21#include <string>
22#include <variant>
23#include <vector>
24
25#include "gmsh_file_v2.h"
26#include "gmsh_file_v4.h"
27
28namespace lf::io {
29
71 public:
74 using GmshFileVariant = std::variant<GMshFileV2, GMshFileV4>;
75
79 [[nodiscard]] std::shared_ptr<mesh::Mesh> mesh() { return mesh_; }
80
84 [[nodiscard]] std::shared_ptr<const mesh::Mesh> mesh() const { return mesh_; }
85
99 [[nodiscard]] size_type PhysicalEntityName2Nr(const std::string& name,
100 dim_t codim = -1) const;
101
114 [[nodiscard]] std::string PhysicalEntityNr2Name(size_type number,
115 dim_t codim = -1) const;
116
124 [[nodiscard]] std::vector<std::pair<size_type, std::string>> PhysicalEntities(
125 dim_t codim) const;
126
133 [[nodiscard]] std::vector<size_type> PhysicalEntityNr(
134 const mesh::Entity& e) const;
135
149 [[nodiscard]] bool IsPhysicalEntity(const mesh::Entity& e,
150 size_type physical_entity_nr) const;
151
159 GmshReader(std::unique_ptr<mesh::MeshFactory> factory,
160 const GmshFileVariant& msh_file);
161
173 GmshReader(std::unique_ptr<mesh::MeshFactory> factory,
174 const std::string& filename);
175
176 private:
178 std::shared_ptr<mesh::Mesh> mesh_;
179
180 std::unique_ptr<mesh::MeshFactory> mesh_factory_;
181
183 std::shared_ptr<mesh::utils::AllCodimMeshDataSet<std::vector<size_type>>>
185
187 std::multimap<std::string, std::pair<size_type, dim_t>> name_2_nr_;
188
190 std::multimap<size_type, std::pair<std::string, dim_t>> nr_2_name_;
191
192 void InitGmshFile(const GMshFileV2& msh_file);
193 void InitGmshFile(const GMshFileV4& msh_file);
194};
195
196std::variant<GMshFileV2, GMshFileV4> ReadGmshFile(const std::string& filename);
197
198} // namespace lf::io
199
200#endif // __7fedf7cf1a0246a98b2bf431cfa34da2
unsigned int dim_t
Definition: ref_el.h:129
Reads a Gmsh *.msh file into a mesh::MeshFactory and provides a link between mesh::Entity objects and...
Definition: gmsh_reader.h:70
void InitGmshFile(const GMshFileV2 &msh_file)
Definition: gmsh_reader.cc:119
std::shared_ptr< mesh::Mesh > mesh_
The underlying grid created by the grid factory.
Definition: gmsh_reader.h:178
std::shared_ptr< const mesh::Mesh > mesh() const
Get the mesh that was read by this reader.
Definition: gmsh_reader.h:84
base::RefEl::dim_t dim_t
Definition: gmsh_reader.h:73
bool IsPhysicalEntity(const mesh::Entity &e, size_type physical_entity_nr) const
Test whether the given entity belongs to a Gmsh physical entity.
Definition: gmsh_reader.cc:17
std::vector< size_type > PhysicalEntityNr(const mesh::Entity &e) const
Return the Physical Entity Numbers associated with this mesh entity, sorted ascending.
Definition: gmsh_reader.cc:114
mesh::Mesh::size_type size_type
Definition: gmsh_reader.h:72
std::shared_ptr< mesh::Mesh > mesh()
Get the mesh that was read by this reader.
Definition: gmsh_reader.h:79
std::shared_ptr< mesh::utils::AllCodimMeshDataSet< std::vector< size_type > > > physical_nrs_
The PhysicalEntityNr of every entity (0 if not set):
Definition: gmsh_reader.h:184
std::string PhysicalEntityNr2Name(size_type number, dim_t codim=-1) const
Gives the name of a physical entity (inverse of PhysicalEntityName2Nr())
Definition: gmsh_reader.cc:68
std::multimap< size_type, std::pair< std::string, dim_t > > nr_2_name_
Map from physicalEntity nr -> name, codim.
Definition: gmsh_reader.h:190
GmshReader(std::unique_ptr< mesh::MeshFactory > factory, const GmshFileVariant &msh_file)
Create a new GmshReader from the given MshFile (advanced usage)
Definition: gmsh_reader.cc:24
std::multimap< std::string, std::pair< size_type, dim_t > > name_2_nr_
Map from physicalEntity name -> nr, codim.
Definition: gmsh_reader.h:187
size_type PhysicalEntityName2Nr(const std::string &name, dim_t codim=-1) const
maps the name of a physical entity to the physical entity number of gmsh.
Definition: gmsh_reader.cc:34
std::vector< std::pair< size_type, std::string > > PhysicalEntities(dim_t codim) const
Retrieve a list of all (Gmsh) physical entities of the given codim.
Definition: gmsh_reader.cc:102
std::variant< GMshFileV2, GMshFileV4 > GmshFileVariant
Definition: gmsh_reader.h:74
std::unique_ptr< mesh::MeshFactory > mesh_factory_
Definition: gmsh_reader.h:180
Interface class representing a topological entity in a cellular complex
Definition: entity.h:39
lf::base::size_type size_type
Mesh input (from file) and output (in various formats) facilities.
Definition: gmsh_file_v2.cc:35
std::variant< GMshFileV2, GMshFileV4 > ReadGmshFile(const std::string &filename)
Definition: gmsh_reader.cc:642
A representation of a .msh file (V2) in a c++ data structure.
Definition: gmsh_file_v2.h:18
A representation of a .msh file (V4) in a c++ data structure.
Definition: gmsh_file_v4.h:20