dune-multidomaingrid 2.10-git
Loading...
Searching...
No Matches
gmshreader.hh
Go to the documentation of this file.
1#ifndef DUNE_MULTIDOMAINGRID_GMSHREADERPARSER_HH
2#define DUNE_MULTIDOMAINGRID_GMSHREADERPARSER_HH
3
4#include <algorithm>
5
7
9
10namespace Dune {
11
12namespace mdgrid {
13
14// forward declaration
15template<typename HostGrid,typename MDGridTraits>
16class MultiDomainGrid;
17
18} // namespace mdgrid
19
20namespace Impl::Gmsh {
21
22// Since dune-grid 2.11 the (formerly public) GmshReaderParser has been renamed
23// and moved to Dune::Impl::Gmsh::Gmsh2Parser. GmshReader::doRead() now
24// instantiates Gmsh2Parser<Grid> directly, so we hook the sub-domain marking
25// into the reading process by specializing Gmsh2Parser for MultiDomainGrid.
26template<class HostGrid, class MDGTraits>
27class Gmsh2Parser<Dune::mdgrid::MultiDomainGrid<HostGrid, MDGTraits>>
28 : public Gmsh2Parser<HostGrid> {
29public:
30
32
33 Gmsh2Parser(Dune::GridFactory<Grid>& factory, bool v, bool i)
34 : Gmsh2Parser<HostGrid>{factory.hostGridFactory(), v, i}
35 , _factory{factory}
36 {}
37
38 void read (const std::string& f)
39 {
40 Gmsh2Parser<HostGrid>::read(f);
41 // list of gmsh domain indices for each entity (gmsh index starts at 1!)
42 const auto& sub_domain_ids = this->elementIndexMap();
43 if (begin(sub_domain_ids) == end(sub_domain_ids))
44 return;
45 int max_subdomains =
46 *std::max_element(begin(sub_domain_ids), end(sub_domain_ids));
47 if (max_subdomains < 1)
48 DUNE_THROW(IOError,
49 "Gmsh phisical entity indices are 1-index based, but a 0 "
50 "index was read");
51 _factory.makeGrid(max_subdomains);
52 auto& grid = _factory.grid();
53
54 grid.startSubDomainMarking();
55 unsigned int i = 0;
56 for (const auto& cell : elements(grid.leafGridView())) {
57 assert(sub_domain_ids[i] != 0);
58 grid.addToSubDomain(sub_domain_ids[i] - 1, cell), i++;
59 }
60
61 grid.preUpdateSubDomains();
62 grid.updateSubDomains();
63 grid.postUpdateSubDomains();
64 }
65
66private:
68};
69
70} // namespace Impl::Gmsh
71
72} // namespace Dune
73
74#endif // DUNE_MULTIDOMAINGRID_GMSHREADERPARSER_HH
iterator end()
iterator begin()
#define DUNE_THROW(E,...)
const Grid & grid() const
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
IteratorRange<... > elements(const GV &gv)
A meta grid for dividing an existing DUNE grid into subdomains that can be accessed as a grid in thei...
Definition multidomaingrid/multidomaingrid.hh:243
T max_element(T... args)