FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::Geometry::GmshFileReader Class Reference

Gmsh file reader class. More...

#include <gmsh_reader.hpp>

Classes

struct  BinaryElementsHeader
 Header for a chunk of elements in binary .msh files. More...
 
struct  FileView
 Utility class for walking through potentially mixed ascii and binary .msh files. More...
 

Public Member Functions

 GmshFileReader (const std::filesystem::path &path)
 File path constructor. More...
 
 GmshFileReader (const std::istream &stream)
 Input stream constructor. More...
 
ParsedMeshType get_mesh_type () const
 Returns the mesh-type of the parsed mesh. More...
 
const String & get_meshtype_string () const
 Returns the mesh-type string of the parsed mesh. More...
 
int get_shape_dim () const
 Returns the shape-dimension of the parsed mesh. More...
 
ParsedShapeType get_shape_type () const
 Returns the shape-type of the parsed mesh. More...
 
int get_world_dim () const
 Returns the world-dimension of the parsed mesh. More...
 
template<typename MeshType_ >
std::unique_ptr< RootMeshNode< MeshType_ > > parse (MeshAtlas< MeshType_ > &mesh_atlas, PartitionSet *part_set=nullptr)
 Parses the mesh file into a mesh node and a mesh atlas. More...
 
void read_root_markup ()
 Reads the root markup from the input stream and analyses it. More...
 

Private Member Functions

void read_data (const std::istream &stream)
 Read file into string. More...
 
void scan_elements (FileView &view)
 Gather start position(s) of element data and ensure the mesh contains only a single element type. More...
 
void scan_nodes (FileView &view)
 Gather number of nodes and start position of node data. More...
 

Static Private Member Functions

static std::size_t binary_element_chunk_size (const BinaryElementsHeader &header)
 Size (in bytes) of one chunk of elements in a binary .msh file. More...
 
static int element_type_to_shape_dim (int type)
 .msh element type to shape dimension mapping More...
 
static ParsedShapeType element_type_to_shape_type (int type)
 .msh element type to ShapeType mapping More...
 
static int msh_to_feat_order (int type, int node)
 Re-ordering for cell vertices. More...
 
static int nodes_per_element (int type)
 .msh element type to number of nodes per element More...
 

Private Attributes

std::size_t _data_size = 8
 .msh size for reals More...
 
std::vector< BinaryElementsHeader > _element_headers
 Element chunks, for binary files. More...
 
int _element_type = -1
 .msh element type More...
 
const char * _elements_start = nullptr
 Start of elements in the file, for ascii files. More...
 
String _file_contents
 Contents of the .msh file. More...
 
bool _have_root_markup = false
 
bool _is_binary = false
 .msh ascii/binary indicator More...
 
String _mesh_type_string = ""
 Mesh type string. More...
 
const char * _nodes_start = nullptr
 Start of nodes in the file. More...
 
std::size_t _num_elements = 0
 Number of elements in the file. More...
 
std::size_t _num_nodes = 0
 Number of nodes in the file. More...
 
int _shape_dim = 0
 Shape dimension. More...
 
ParsedShapeType _shape_type = ParsedShapeType::unknown
 Shape type. More...
 
double _version = 0.0
 .msh file version More...
 

Detailed Description

Gmsh file reader class.

This class implements a reader which parses Gmesh's .msh files into a RootMeshNode.

The basic usage is as follows:

  1. Create an object of the GmshFileReader
  2. Scan through the file to ensure it contains a mesh that FEAT can represent using read_root_markup()
  3. Call the parse() function with the appropriate mesh type

For more details on meshes, see the related doxygen page FEAT Mesh File Format.

Limitations:

  1. Currently only nodes and elements are parsed. No charts, meshparts, or partitions will be created.
  2. Only the version 2.2 legacy format is supported.
  3. Only meshes with contiguous indices for vertices and elements are supported.

See Chapter 10 of https://gmsh.info/dev/doc/texinfo/gmsh.pdf for detail on the mesh format.

Author
Markus Muegge

Definition at line 48 of file gmsh_reader.hpp.

Constructor & Destructor Documentation

◆ GmshFileReader() [1/2]

FEAT::Geometry::GmshFileReader::GmshFileReader ( const std::istream &  stream)
inlineexplicit

Input stream constructor.

Definition at line 199 of file gmsh_reader.hpp.

References read_data().

◆ GmshFileReader() [2/2]

FEAT::Geometry::GmshFileReader::GmshFileReader ( const std::filesystem::path &  path)
inlineexplicit

File path constructor.

Definition at line 211 of file gmsh_reader.hpp.

References read_data(), FEAT::stringify(), and XASSERTM.

Member Function Documentation

◆ binary_element_chunk_size()

static std::size_t FEAT::Geometry::GmshFileReader::binary_element_chunk_size ( const BinaryElementsHeader &  header)
inlinestaticprivate

◆ element_type_to_shape_dim()

static int FEAT::Geometry::GmshFileReader::element_type_to_shape_dim ( int  type)
inlinestaticprivate

.msh element type to shape dimension mapping

Definition at line 561 of file gmsh_reader.hpp.

References XABORTM.

Referenced by read_root_markup().

◆ element_type_to_shape_type()

static ParsedShapeType FEAT::Geometry::GmshFileReader::element_type_to_shape_type ( int  type)
inlinestaticprivate

.msh element type to ShapeType mapping

Definition at line 548 of file gmsh_reader.hpp.

References FEAT::Geometry::hypercube, FEAT::Geometry::simplex, and XABORTM.

Referenced by read_root_markup().

◆ get_mesh_type()

ParsedMeshType FEAT::Geometry::GmshFileReader::get_mesh_type ( ) const
inline

Returns the mesh-type of the parsed mesh.

Note
The .msh format has no ability to describe structured meshes, so the mesh type is always MeshType::conformal.
Returns
The mesh-type of the parsed mesh

Definition at line 244 of file gmsh_reader.hpp.

References FEAT::Geometry::conformal.

◆ get_meshtype_string()

const String & FEAT::Geometry::GmshFileReader::get_meshtype_string ( ) const
inline

Returns the mesh-type string of the parsed mesh.

Note
This function can only be called after calling the read_root_markup() function as it will always return an empty string otherwise.
Returns
The mesh-type string of the parsed mesh

Definition at line 229 of file gmsh_reader.hpp.

References _mesh_type_string.

◆ get_shape_dim()

int FEAT::Geometry::GmshFileReader::get_shape_dim ( ) const
inline

Returns the shape-dimension of the parsed mesh.

Note
This function can only be called after calling the read_root_markup() function as it will always return 0 otherwise.
Returns
The shape-dimension of the parsed mesh

Definition at line 274 of file gmsh_reader.hpp.

References _shape_dim.

◆ get_shape_type()

ParsedShapeType FEAT::Geometry::GmshFileReader::get_shape_type ( ) const
inline

Returns the shape-type of the parsed mesh.

Note
This function can only be called after calling the read_root_markup() function as it will always return ShapeType::unknown otherwise.
Returns
The shape-type of the parsed mesh

Definition at line 259 of file gmsh_reader.hpp.

References _shape_type.

◆ get_world_dim()

int FEAT::Geometry::GmshFileReader::get_world_dim ( ) const
inline

Returns the world-dimension of the parsed mesh.

Note
Nodes in .msh files always contain x, y, and z coordinates, thus the world dimension is always three.
Returns
The world-dimension from the root markup node.

Definition at line 289 of file gmsh_reader.hpp.

Referenced by parse().

◆ msh_to_feat_order()

static int FEAT::Geometry::GmshFileReader::msh_to_feat_order ( int  type,
int  node 
)
inlinestaticprivate

Re-ordering for cell vertices.

.msh file and FEAT use different conventions for the ordering of local vertices of a cell. This function provides a mapping to correct for these different conventions

Definition at line 593 of file gmsh_reader.hpp.

References XABORTM.

Referenced by parse().

◆ nodes_per_element()

static int FEAT::Geometry::GmshFileReader::nodes_per_element ( int  type)
inlinestaticprivate

.msh element type to number of nodes per element

Definition at line 574 of file gmsh_reader.hpp.

References XABORTM.

Referenced by binary_element_chunk_size(), and parse().

◆ parse()

template<typename MeshType_ >
std::unique_ptr< RootMeshNode< MeshType_ > > FEAT::Geometry::GmshFileReader::parse ( MeshAtlas< MeshType_ > &  mesh_atlas,
PartitionSet *  part_set = nullptr 
)
inline

Parses the mesh file into a mesh node and a mesh atlas.

Parameters
[in,out]mesh_atlasCurrently unused, only accepted for compatibility
[in,out]part_setCurrently unused, only accepted for compatibility
Returns
A unique pointer to the root mesh node containing the mesh. This mesh node is automatically linked to the given mesh atlas.

Definition at line 360 of file gmsh_reader.hpp.

References _data_size, _element_headers, _element_type, _elements_start, _file_contents, _is_binary, _nodes_start, _num_elements, _num_nodes, _shape_dim, _shape_type, FEAT::Geometry::GmshFileReader::FileView::advance(), get_world_dim(), FEAT::Geometry::hypercube, FEAT::Geometry::GmshFileReader::FileView::memcpy(), msh_to_feat_order(), nodes_per_element(), FEAT::Geometry::GmshFileReader::FileView::parse_line(), read_root_markup(), FEAT::Geometry::simplex, XABORTM, and XASSERT.

◆ read_data()

void FEAT::Geometry::GmshFileReader::read_data ( const std::istream &  stream)
inlineprivate

Read file into string.

Definition at line 703 of file gmsh_reader.hpp.

References _file_contents, and XASSERT.

Referenced by GmshFileReader().

◆ read_root_markup()

void FEAT::Geometry::GmshFileReader::read_root_markup ( )
inline

◆ scan_elements()

void FEAT::Geometry::GmshFileReader::scan_elements ( FileView &  view)
inlineprivate

Gather start position(s) of element data and ensure the mesh contains only a single element type.

Definition at line 638 of file gmsh_reader.hpp.

References _element_headers, _element_type, _elements_start, _is_binary, _num_elements, binary_element_chunk_size(), and XASSERT.

Referenced by read_root_markup().

◆ scan_nodes()

void FEAT::Geometry::GmshFileReader::scan_nodes ( FileView &  view)
inlineprivate

Gather number of nodes and start position of node data.

Definition at line 614 of file gmsh_reader.hpp.

References _data_size, _is_binary, _nodes_start, _num_nodes, and XASSERT.

Referenced by read_root_markup().

Member Data Documentation

◆ _data_size

std::size_t FEAT::Geometry::GmshFileReader::_data_size = 8
private

.msh size for reals

Definition at line 174 of file gmsh_reader.hpp.

Referenced by parse(), read_root_markup(), and scan_nodes().

◆ _element_headers

std::vector<BinaryElementsHeader> FEAT::Geometry::GmshFileReader::_element_headers
private

Element chunks, for binary files.

Definition at line 186 of file gmsh_reader.hpp.

Referenced by parse(), and scan_elements().

◆ _element_type

int FEAT::Geometry::GmshFileReader::_element_type = -1
private

.msh element type

Definition at line 180 of file gmsh_reader.hpp.

Referenced by parse(), read_root_markup(), and scan_elements().

◆ _elements_start

const char* FEAT::Geometry::GmshFileReader::_elements_start = nullptr
private

Start of elements in the file, for ascii files.

Definition at line 184 of file gmsh_reader.hpp.

Referenced by parse(), and scan_elements().

◆ _file_contents

String FEAT::Geometry::GmshFileReader::_file_contents
private

Contents of the .msh file.

Definition at line 162 of file gmsh_reader.hpp.

Referenced by parse(), read_data(), and read_root_markup().

◆ _have_root_markup

bool FEAT::Geometry::GmshFileReader::_have_root_markup = false
private

Definition at line 164 of file gmsh_reader.hpp.

◆ _is_binary

bool FEAT::Geometry::GmshFileReader::_is_binary = false
private

.msh ascii/binary indicator

Definition at line 172 of file gmsh_reader.hpp.

Referenced by parse(), read_root_markup(), scan_elements(), and scan_nodes().

◆ _mesh_type_string

String FEAT::Geometry::GmshFileReader::_mesh_type_string = ""
private

Mesh type string.

Definition at line 191 of file gmsh_reader.hpp.

Referenced by get_meshtype_string(), and read_root_markup().

◆ _nodes_start

const char* FEAT::Geometry::GmshFileReader::_nodes_start = nullptr
private

Start of nodes in the file.

Definition at line 182 of file gmsh_reader.hpp.

Referenced by parse(), and scan_nodes().

◆ _num_elements

std::size_t FEAT::Geometry::GmshFileReader::_num_elements = 0
private

Number of elements in the file.

Definition at line 178 of file gmsh_reader.hpp.

Referenced by parse(), and scan_elements().

◆ _num_nodes

std::size_t FEAT::Geometry::GmshFileReader::_num_nodes = 0
private

Number of nodes in the file.

Definition at line 176 of file gmsh_reader.hpp.

Referenced by parse(), and scan_nodes().

◆ _shape_dim

int FEAT::Geometry::GmshFileReader::_shape_dim = 0
private

Shape dimension.

Definition at line 195 of file gmsh_reader.hpp.

Referenced by get_shape_dim(), parse(), and read_root_markup().

◆ _shape_type

ParsedShapeType FEAT::Geometry::GmshFileReader::_shape_type = ParsedShapeType::unknown
private

Shape type.

Definition at line 193 of file gmsh_reader.hpp.

Referenced by get_shape_type(), parse(), and read_root_markup().

◆ _version

double FEAT::Geometry::GmshFileReader::_version = 0.0
private

.msh file version

Definition at line 170 of file gmsh_reader.hpp.

Referenced by read_root_markup().


The documentation for this class was generated from the following file: