dune-grid 2.9.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Dune::GmshReader< GridType > Class Template Reference

Read Gmsh mesh file. More...

#include <dune/grid/io/file/gmshreader.hh>

Public Types

typedef GridType Grid
 
using Opts = Gmsh::ReaderOptions
 

Public Member Functions

 GmshReader ()=default
 Dynamic Gmsh reader interface. More...
 
 GmshReader (const std::string &fileName, Gmsh::ReaderOptions options=defaultOpts)
 Construct a Gmsh reader object (alternatively use one of the static member functions) More...
 
 GmshReader (const std::string &fileName, GridFactory< Grid > &factory, Gmsh::ReaderOptions options=defaultOpts)
 Construct a Gmsh reader object from a file name and a grid factory. More...
 
const std::vector< int > & elementData () const
 Access element data (maps element index to Gmsh physical entity) More...
 
const std::vector< int > & boundaryData () const
 Access boundary data (maps boundary segment index to Gmsh physical entity) More...
 
bool hasElementData () const
 If element data is available. More...
 
bool hasBoundaryData () const
 If boundary data is available. More...
 
std::vector< int > extractElementData ()
 Erase element data from reader and return the data. More...
 
std::vector< int > extractBoundaryData ()
 Erase boundary data from reader and return the data. More...
 
std::unique_ptr< GridcreateGrid ()
 Create the grid. More...
 

Static Public Member Functions

static std::unique_ptr< Gridread (const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
 
static std::unique_ptr< Gridread (const std::string &fileName, std::vector< int > &boundarySegmentToPhysicalEntity, std::vector< int > &elementToPhysicalEntity, bool verbose=true, bool insertBoundarySegments=true)
 Read Gmsh file, possibly with data. More...
 
static void read (Dune::GridFactory< Grid > &factory, const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
 
static void read (Dune::GridFactory< Grid > &factory, const std::string &fileName, DataFlagArg boundarySegmentData, DataArg elementData, bool verbose=true)
 read Gmsh file, possibly with data More...
 
static void read (Dune::GridFactory< Grid > &factory, const std::string &fileName, std::vector< int > &boundarySegmentToPhysicalEntity, std::vector< int > &elementToPhysicalEntity, bool verbose, bool insertBoundarySegments)
 Read Gmsh file, possibly with data. More...
 

Static Public Attributes

static constexpr Opts defaultOpts
 

Detailed Description

template<typename GridType>
class Dune::GmshReader< GridType >

Read Gmsh mesh file.

Read a .msh (version 2) file generated using Gmsh and construct a grid using the grid factory interface.

The file format used by gmsh can hold grids that are more general than the simplex grids that the gmsh grid generator is able to construct. We try to read as many grids as possible, as long as they are valid files. You can test this by checking whether gmsh will load the file and display its content.

All grids in a gmsh file live in three-dimensional Euclidean space. If the world dimension of the grid type that you are reading the file into is less than three, the remaining coordinates are simply ignored.

Note
Recent versions of Gmsh introduced a new .msh file format (version 4) with a different syntax. This is currently not supported by GmshReader. One can export to an older .msh version as follows:
  • select File→Export (or CTRL+E)
  • select file format .msh
  • a dialog asks for options
  • select 'Version 2 ASCII' and mark 'Save all elements'

Member Typedef Documentation

◆ Grid

template<typename GridType >
typedef GridType Dune::GmshReader< GridType >::Grid

◆ Opts

template<typename GridType >
using Dune::GmshReader< GridType >::Opts = Gmsh::ReaderOptions

Constructor & Destructor Documentation

◆ GmshReader() [1/3]

template<typename GridType >
Dune::GmshReader< GridType >::GmshReader ( )
default

Dynamic Gmsh reader interface.

◆ GmshReader() [2/3]

template<typename GridType >
Dune::GmshReader< GridType >::GmshReader ( const std::string &  fileName,
Gmsh::ReaderOptions  options = defaultOpts 
)
inline

Construct a Gmsh reader object (alternatively use one of the static member functions)

Construct a Gmsh reader object from a file name

Parameters
fileNameName of the file to read from.
optionsOptions of the type Dune::Gmsh::ReaderOptions

To pass several options, combine them with the |-operator like this

auto reader = Dune::GmshReader("grid.msh", Opt::verbose | Opt::readElementData)
ReaderOptions
Option for the Gmsh mesh file reader.
Definition: gmshreader.hh:756
Read Gmsh mesh file.
Definition: gmshreader.hh:805

Per default the reader has enabled the following options

Passing any option to the interface will overwrite these defaults.

A Dune grid object can be obtained via the createGrid() member

◆ GmshReader() [3/3]

template<typename GridType >
Dune::GmshReader< GridType >::GmshReader ( const std::string &  fileName,
GridFactory< Grid > &  factory,
Gmsh::ReaderOptions  options = defaultOpts 
)
inline

Construct a Gmsh reader object from a file name and a grid factory.

Parameters
fileNameName of the file to read from.
optionsOptions of the type Dune::Gmsh::ReaderOptions
Note
Use this constructor if you need access to the grid factor, e.g. for obtaining boundary segment insertion indices.

Member Function Documentation

◆ boundaryData()

template<typename GridType >
const std::vector< int > & Dune::GmshReader< GridType >::boundaryData ( ) const
inline

Access boundary data (maps boundary segment index to Gmsh physical entity)

◆ createGrid()

template<typename GridType >
std::unique_ptr< Grid > Dune::GmshReader< GridType >::createGrid ( )
inline

Create the grid.

◆ elementData()

template<typename GridType >
const std::vector< int > & Dune::GmshReader< GridType >::elementData ( ) const
inline

Access element data (maps element index to Gmsh physical entity)

◆ extractBoundaryData()

template<typename GridType >
std::vector< int > Dune::GmshReader< GridType >::extractBoundaryData ( )
inline

Erase boundary data from reader and return the data.

◆ extractElementData()

template<typename GridType >
std::vector< int > Dune::GmshReader< GridType >::extractElementData ( )
inline

Erase element data from reader and return the data.

◆ hasBoundaryData()

template<typename GridType >
bool Dune::GmshReader< GridType >::hasBoundaryData ( ) const
inline

If boundary data is available.

Note
This is false if no such data was requested

◆ hasElementData()

template<typename GridType >
bool Dune::GmshReader< GridType >::hasElementData ( ) const
inline

If element data is available.

Note
This is false if no such data was requested

◆ read() [1/5]

template<typename GridType >
static std::unique_ptr< Grid > Dune::GmshReader< GridType >::read ( const std::string &  fileName,
bool  verbose = true,
bool  insertBoundarySegments = true 
)
inlinestatic
Todo:
doc me
Returns
The return type is a special pointer type that casts into Grid*, std::unique_ptr<Grid>, and std::shared_ptr<Grid>. It is scheduled to be replaced by std::unique_ptr<Grid> eventually.

◆ read() [2/5]

template<typename GridType >
static std::unique_ptr< Grid > Dune::GmshReader< GridType >::read ( const std::string &  fileName,
std::vector< int > &  boundarySegmentToPhysicalEntity,
std::vector< int > &  elementToPhysicalEntity,
bool  verbose = true,
bool  insertBoundarySegments = true 
)
inlinestatic

Read Gmsh file, possibly with data.

Parameters
fileNameName of the file to read from.
boundarySegmentToPhysicalEntityContainer to fill with boundary segment physical entity data (if insertBoundarySegments=true)
elementToPhysicalEntityContainer to fill with element physical entity data
verboseWhether to be chatty
insertBoundarySegmentsWhether boundary segments are inserted into the factory
Note
When insertBoundarySegments=false there is no way to correctly use the values returned in boundarySegmentToPhysicalEntity. Make sure to set insertBoundarySegments=true if you intent to do this. An alternative is to use the other overloads which provide compile-time checking of the provided parameter combinations.
Todo:
This interface is error-prone and should not be exposed to the user. However, the compile-time overloads may not provide sufficient runtime flexibility in all cases. Therefore this interface is kept until a better interface can be agreed on. See https://gitlab.dune-project.org/core/dune-grid/-/issues/107

◆ read() [3/5]

template<typename GridType >
static void Dune::GmshReader< GridType >::read ( Dune::GridFactory< Grid > &  factory,
const std::string &  fileName,
bool  verbose = true,
bool  insertBoundarySegments = true 
)
inlinestatic
Todo:
doc me

◆ read() [4/5]

template<typename GridType >
static void Dune::GmshReader< GridType >::read ( Dune::GridFactory< Grid > &  factory,
const std::string &  fileName,
DataFlagArg  boundarySegmentData,
DataArg  elementData,
bool  verbose = true 
)
inlinestatic

read Gmsh file, possibly with data

Parameters
factoryThe GridFactory to fill.
fileNameName of the file to read from.
boundarySegmentDataContainer to fill with boundary segment physical entity data, or std::ignore, or a bool value. Boundary segments are inserted when a container or true is given, otherwise they are not inserted.
elementDataContainer to fill with element physical entity data, or std::ignore.
verboseWhether to be chatty.

Containers to fill with data must be std::vector<int> lvalues. Element data is indexed by the insertion index of the element, boundarySegment data is indexed by the insertion index of the boundary intersection. These can be obtained from the factory, and are lost once the grid gets modified (refined or load-balanced).

Note
At the moment the data containers are still filled internally, even if they are ignored. So not having to pass them is more of a convenience feature and less of an optimization. This may however change in the future.

◆ read() [5/5]

template<typename GridType >
static void Dune::GmshReader< GridType >::read ( Dune::GridFactory< Grid > &  factory,
const std::string &  fileName,
std::vector< int > &  boundarySegmentToPhysicalEntity,
std::vector< int > &  elementToPhysicalEntity,
bool  verbose,
bool  insertBoundarySegments 
)
inlinestatic

Read Gmsh file, possibly with data.

Parameters
factoryThe GridFactory to fill.
fileNameName of the file to read from.
boundarySegmentToPhysicalEntityContainer to fill with boundary segment physical entity data (if insertBoundarySegments=true)
elementToPhysicalEntityContainer to fill with element physical entity data
verboseWhether to be chatty
insertBoundarySegmentsWhether boundary segments are inserted into the factory
Note
When insertBoundarySegments=false there is no way to correctly use the values returned in boundarySegmentToPhysicalEntity. Make sure to set insertBoundarySegments=true if you intent to do this. An alternative is to use the other overloads which provide compile-time checking of the provided parameter combinations.
Todo:
This interface is error-prone and should not be exposed to the user. However, the compile-time overloads may not provide sufficient runtime flexibility in all cases. Therefore this interface is kept until a better interface can be agreed on. See https://gitlab.dune-project.org/core/dune-grid/-/issues/107

Member Data Documentation

◆ defaultOpts

template<typename GridType >
constexpr Opts Dune::GmshReader< GridType >::defaultOpts
staticconstexpr
Initial value:
=
Opts::verbose | Opts::insertBoundarySegments | Opts::readElementData | Opts::readBoundaryData

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