Skip to content

Feature/gmsh reader dynamic interface

Timo Koch requested to merge feature/gmsh-reader-dynamic-interface into master

Fixes #107 (closed)

The gmsh reader interface used to be dynamic in the sense that parameters could be changed at runtime. This was changed to a statically typed interface with different overloads which makes this harder to use in a generic context but more safe to use in a smaller application if you only need to support one option and you like compiler errors.

With this addition we get a dynamic approach next to the statically typed interfaces. You can now construct a reader and if you only need the grid it could look like this

using Opts = Gmsh::ReaderOptions;
auto grid = GmshReader<Grid>("grid.msh", Opts::verbose).createGrid();

the default options are to read also all data (element and boundary data) from the file. (This is currently internally done anyway always, but in the future we might want to do some optimization there.) So if you don't mind that the shorter

auto grid = GmshReader<Grid>("grid.msh").createGrid();

is also possible. Options can be composed and data can be obtained from the reader object like this

using Opts = Gmsh::ReaderOptions;
auto reader = GmshReader<Grid>("grid.msh", Opts::readElementData | Opts::readBoundaryData);
// const auto& elementData = reader.elementData(); // reference
auto elementData = reader.popElementData(); // move the data out
std::cout << reader.hasElementData(); // prints 0/false

Of course you can also pass the grid factory from outside with this approach which is needed for more information on the boundary segments.

GridFactory<Grid> gridFactory;
using Opts = Gmsh::ReaderOptions;
auto reader = GmshReader<Grid>("grid.msh", gridFactory, Opts::readElementData | Opts::readBoundaryData);
auto grid = gridFactory.createGrid();
// auto grid = reader.createGrid(); // throws in this case

Replacement for !405 (closed) and !409 (closed)

Edited by Timo Koch

Merge request reports