Loading [MathJax]/extensions/tex2jax.js

DUNE MultiDomainGrid (2.9)

factory.hh
1#ifndef DUNE_MULTIDOMAINGRID_FACTORY_HH
2#define DUNE_MULTIDOMAINGRID_FACTORY_HH
3
4#include <dune/grid/common/exceptions.hh>
5
6#include <dune/geometry/type.hh>
7
8#include <optional>
9#include <memory>
10
11namespace Dune {
12
13namespace mdgrid {
14
15// forward declaration
16template<typename HostGrid,typename MDGridTraits>
17class MultiDomainGrid;
18
19} // namespace mdgrid
20
21// forward declaration
22template <class GridType>
23class GridFactoryInterface;
24
25template <class GridType>
26class GridFactory;
27
28template<class HostGrid, class MDGTraits>
29class GridFactory<Dune::mdgrid::MultiDomainGrid<HostGrid, MDGTraits>> : public GridFactoryInterface<Dune::mdgrid::MultiDomainGrid<HostGrid, MDGTraits>> {
30
32 using Base = GridFactoryInterface<Grid>;
33public:
34
35 GridFactory()
36 : _host_grid_factory{}
37 {}
38
39 // use default implementation from base class
40 using Base::insertBoundarySegment;
41
42 void insertVertex(const FieldVector<typename Grid::ctype, Grid::dimensionworld>& pos) override {
43 _host_grid_factory.insertVertex(pos);
44 }
45
46 void insertElement(const GeometryType& type, const std::vector<unsigned int>& vertices) override {
47 _host_grid_factory.insertElement(type, vertices);
48 }
49
50 void insertBoundarySegment(const std::vector<unsigned int>& vertices) override {
51 _host_grid_factory.insertBoundarySegment(vertices);
52 }
53
54 std::unique_ptr<Grid> createGrid() override {
55 if (not _grid_ptr)
56 makeGrid();
57 assert(_grid_ptr);
58 return std::exchange(_grid_ptr, nullptr);
59 }
60
61 void makeGrid(std::optional<typename MDGTraits::SubDomainIndex> max_subdomains = {}) {
62 assert(not _grid_ptr);
63
64 std::unique_ptr<MDGTraits> traits;
65 if constexpr (Grid::maxSubDomainIndexIsStatic())
66 traits = std::make_unique<MDGTraits>();
67 else {
68 if (not max_subdomains.has_value())
69 DUNE_THROW(GridError, "MultiDomainGrid needs a maximum number of subdomains, but none is provided");
70 traits = std::make_unique<MDGTraits>(*max_subdomains);
71 }
72
73 if (max_subdomains.has_value() and traits->maxSubDomainIndex() < *max_subdomains)
74 DUNE_THROW(GridError, "Maximum number of sub-domains is bigger than what grid traits allows");
75
76 _grid_ptr = std::make_unique<Grid>(_host_grid_factory.createGrid(), *traits);
77 }
78
79 Grid& grid() {
80 assert(_grid_ptr);
81 return *_grid_ptr;
82 }
83
84 HostGrid& hostGrid() {
85 assert(_host_grid_ptr);
86 return *_host_grid_ptr;
87 }
88
89 const std::shared_ptr<HostGrid>& hostGridPtr() {
90 return _host_grid_ptr;
91 }
92
93
94 Dune::GridFactory<HostGrid>& hostGridFactory() {
95 return _host_grid_factory;
96 }
97
98private:
99 Dune::GridFactory<HostGrid> _host_grid_factory;
100 std::shared_ptr<HostGrid> _host_grid_ptr;
101 std::unique_ptr<Grid> _grid_ptr;
102};
103
104} // namespace Dune
105
106#endif // DUNE_MULTIDOMAINGRID_FACTORY_HH
A meta grid for dividing an existing DUNE grid into subdomains that can be accessed as a grid in thei...
Definition: multidomaingrid.hh:247
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 6, 22:49, 2025)