AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
GlobalBasis.hpp
1#pragma once
2
3#include <algorithm>
4#include <list>
5#include <memory>
6#include <type_traits>
7#include <utility>
8
9#include <dune/common/concept.hh>
10#include <dune/common/reservedvector.hh>
11#include <dune/common/shared_ptr.hh>
12#include <dune/common/typeutilities.hh>
13#include <dune/common/version.hh>
14#include <dune/functions/common/multiindex.hh>
15#include <dune/functions/common/type_traits.hh>
16#include <dune/functions/functionspacebases/concepts.hh>
17#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
18#include <dune/grid/common/adaptcallback.hh>
19#include <dune/typetree/treepath.hh>
20
21#include <amdis/AdaptiveGrid.hpp>
22#include <amdis/Observer.hpp>
23#include <amdis/Output.hpp>
24#include <amdis/common/Concepts.hpp>
25#include <amdis/common/TypeTraits.hpp>
26#include <amdis/functions/FlatPreBasis.hpp>
27#include <amdis/functions/LocalView.hpp>
28#include <amdis/linearalgebra/IndexDistribution.hpp>
29#include <amdis/linearalgebra/Traits.hpp>
30#include <amdis/typetree/MultiIndex.hpp>
31
32namespace AMDiS
33{
43 template <class PB>
45 : public Dune::Functions::DefaultGlobalBasis<PB>
46 , public Notifier<event::adapt>
47 , private Observer<event::adapt>
48 {
49 using Self = GlobalBasis<PB>;
50 using Super = Dune::Functions::DefaultGlobalBasis<PB>;
51
52 public:
54 using PreBasis = PB;
55
57 using GridView = typename PreBasis::GridView;
58 using Grid = typename GridView::Grid;
59
62
65
66 struct DummyImpl {};
67 using ADH = Dune::AdaptDataHandle<Grid, DummyImpl>;
68
69 public:
71
78 template <class... Args,
79 Dune::Functions::enableIfConstructible<PreBasis, Args...> = 0>
80 GlobalBasis(std::string const& name, Grid const& grid, Args&&... args)
81 : Super(FWD(args)...)
82 , Observer<event::adapt>(grid)
83 , indexDist_(static_cast<Super const&>(*this))
84 {}
85
87 template <class PBF>
88 GlobalBasis(std::string const& name, GridView const& gridView,
89 PBF const& preBasisFactory)
90 : GlobalBasis(name, gridView.grid(), flatPreBasis(preBasisFactory(gridView)))
91 {}
92
94 template <class Arg, class... Args,
95 REQUIRES(!std::is_same_v<std::string, remove_cvref_t<Arg>>)>
96 GlobalBasis(Arg&& arg, Args&&... args)
97 : GlobalBasis(std::string(""), FWD(arg), FWD(args)...)
98 {}
99
101 GlobalBasis(GlobalBasis const&) = delete;
102
105
106 public:
108
112 void update(GridView const& gv)
113 {
114 Super::preBasis().update(gv);
115 Super::preBasis().initializeIndices();
116 indexDist_.update(*this);
117 }
118
121 {
122 return LocalView(*this);
123 }
124
126 std::shared_ptr<LocalView> localViewPtr() const
127 {
128 return std::make_shared<LocalView>(*this);
129 }
130
132 auto entitySet() const
133 {
134 return elements(this->gridView(), BackendTraits::PartitionSet{});
135 }
136
138 GlobalBasis const& rootBasis() const
139 {
140 return *this;
141 }
142
144
148 IndexDist const& indexDistribution() const { return indexDist_; }
149 IndexDist& indexDistribution() { return indexDist_; }
150
151 ADH globalRefineCallback() const
152 {
153 // TODO(FM): Implement
154 error_exit("Not implemented: GlobalBasis::globalRefineCallback()");
155 return ADH{};
156 }
157
158 protected:
160 void updateImpl(event::adapt e) override
161 {
162 if (e.value) {
163 update(Super::gridView());
165 }
166 }
167
169
170 protected:
171 IndexDist indexDist_;
172 };
173
174
175 // Deduction guides
176 template <class GV, class PBF>
177 GlobalBasis(std::string const& name, GV const& gridView, PBF const& preBasisFactory)
178 -> GlobalBasis<std::decay_t<decltype(flatPreBasis(preBasisFactory(gridView)))>>;
179
180 template <class GV, class PBF>
181 GlobalBasis(GV const& gridView, PBF const& preBasisFactory)
182 -> GlobalBasis<std::decay_t<decltype(flatPreBasis(preBasisFactory(gridView)))>>;
183
184} // end namespace AMDiS
Dummy implementation for sequential index "distribution".
Definition: IndexDistribution.hpp:7
Global basis defined on a pre-basis.
Definition: GlobalBasis.hpp:48
GlobalBasis(std::string const &name, Grid const &grid, Args &&... args)
Construct this global basis with given name and grid, and constructing a preBasis.
Definition: GlobalBasis.hpp:80
GlobalBasis(std::string const &name, GridView const &gridView, PBF const &preBasisFactory)
Construct this global basis with a preBasisFactory.
Definition: GlobalBasis.hpp:88
IndexDist const & indexDistribution() const
Return the index distribution.
Definition: GlobalBasis.hpp:148
GlobalBasis(GlobalBasis const &)=delete
Copy constructor.
void update(GridView const &gv)
Update the stored grid view.
Definition: GlobalBasis.hpp:112
LocalView localView() const
Return local view for basis.
Definition: GlobalBasis.hpp:120
AMDiS::LocalView< Self > LocalView
Type of the local view on the restriction of the basis to a single element.
Definition: GlobalBasis.hpp:61
PB PreBasis
Pre-basis providing the implementation details.
Definition: GlobalBasis.hpp:54
auto entitySet() const
Return the set of entities this basis can be bound to.
Definition: GlobalBasis.hpp:132
GlobalBasis const & rootBasis() const
Return *this because we are not embedded in a larger basis.
Definition: GlobalBasis.hpp:138
GlobalBasis(Arg &&arg, Args &&... args)
Construct this global basis with empty name.
Definition: GlobalBasis.hpp:96
GlobalBasis(GlobalBasis &&)=default
Move constructor.
void updateImpl(event::adapt e) override
Updates the underlying basis when event::adapt is triggered by the observed grid.
Definition: GlobalBasis.hpp:160
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:57
std::shared_ptr< LocalView > localViewPtr() const
Return local view as shared_ptr to prevent from copy construction.
Definition: GlobalBasis.hpp:126
BackendTraits::IndexDist< Self > IndexDist
Type of the communicator.
Definition: GlobalBasis.hpp:64
The restriction of a finite element basis to a single element.
Definition: LocalView.hpp:16
Mixin for signaling of certain events.
Definition: Observer.hpp:57
Implementation of the ObserverInterface.
Definition: Observer.hpp:104
constexpr bool GlobalBasis
A Dune::Functions::GlobalBasis type.
Definition: Concepts.hpp:189
Definition: GlobalBasis.hpp:66
Definition: Observer.hpp:25