AMDiS  0.3
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/type_traits.hh>
15 #include <dune/functions/functionspacebases/concepts.hh>
16 #include <dune/functions/functionspacebases/defaultglobalbasis.hh>
17 #include <dune/functions/functionspacebases/defaultlocalindexset.hh>
18 #include <dune/functions/functionspacebases/flatmultiindex.hh>
19 #include <dune/grid/common/adaptcallback.hh>
20 #include <dune/typetree/treepath.hh>
21 
22 #include <amdis/AdaptiveGrid.hpp>
23 #include <amdis/Observer.hpp>
24 #include <amdis/Output.hpp>
25 #include <amdis/common/Concepts.hpp>
26 #include <amdis/common/TypeTraits.hpp>
27 #include <amdis/functions/FlatPreBasis.hpp>
28 #include <amdis/functions/LocalView.hpp>
29 #include <amdis/linearalgebra/Traits.hpp>
30 #include <amdis/typetree/MultiIndex.hpp>
31 
32 namespace AMDiS
33 {
34  template <class PreBasisFactory, class PBF = remove_cvref_t<PreBasisFactory>>
35  using MultiIndex_t = std::conditional_t<(PBF::requiredMultiIndexSize == 1),
36  Dune::Functions::FlatMultiIndex<std::size_t>,
37  Dune::ReservedVector<std::size_t, PBF::requiredMultiIndexSize>>;
38 
39 
49  template <class PB>
51  : public Dune::Functions::DefaultGlobalBasis<PB>
52  , public Notifier<event::adapt>
53  , private Observer<event::adapt>
54  {
55  using Self = GlobalBasis<PB>;
56  using Super = Dune::Functions::DefaultGlobalBasis<PB>;
57 
58  public:
60  using PreBasis = PB;
61 
63  using GridView = typename PreBasis::GridView;
64  using Grid = typename GridView::Grid;
65 
68 
70  using Comm = std::conditional_t<Traits::IsFlatIndex<typename Super::MultiIndex>::value,
73 
74  struct DummyImpl {};
75  using ADH = Dune::AdaptDataHandle<Grid, DummyImpl>;
76 
77  public:
79 
86  template <class... Args,
87  Dune::Functions::enableIfConstructible<PreBasis, Args...> = 0>
88  GlobalBasis(std::string const& name, Grid const& grid, Args&&... args)
89  : Super(FWD(args)...)
90  , Observer<event::adapt>(grid)
91  , comm_(CommunicationCreator<Comm>::create(static_cast<Super const&>(*this), name + "->solver"))
92  {}
93 
95  template <class PBF>
96  GlobalBasis(std::string const& name, GridView const& gridView,
97  PBF const& preBasisFactory)
98  : GlobalBasis(name, gridView.grid(),
99  flatPreBasis(preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))
100  {}
101 
103  template <class Arg, class... Args,
104  REQUIRES(!std::is_same_v<std::string, remove_cvref_t<Arg>>)>
105  GlobalBasis(Arg&& arg, Args&&... args)
106  : GlobalBasis(std::string(""), FWD(arg), FWD(args)...)
107  {}
108 
110  GlobalBasis(GlobalBasis const&) = delete;
111 
113  GlobalBasis(GlobalBasis&&) = default;
114 
115  public:
117 
121  void update(GridView const& gv)
122  {
123  Super::preBasis().update(gv);
124  Super::preBasis().initializeIndices();
125  comm_.update(*this);
126  }
127 
130  {
131  return LocalView(*this);
132  }
133 
135  std::shared_ptr<LocalView> localViewPtr() const
136  {
137  return std::make_shared<LocalView>(*this);
138  }
139 
141  GlobalBasis const& rootBasis() const
142  {
143  return *this;
144  }
145 
147 
151  Comm const& communicator() const { return comm_; }
152  Comm& communicator() { return comm_; }
153 
154  ADH globalRefineCallback() const
155  {
156  // TODO(FM): Implement
157  error_exit("Not implemented: GlobalBasis::globalRefineCallback()");
158  return ADH{};
159  }
160 
161  protected:
163  void updateImpl(event::adapt e) override
164  {
165  if (e.value) {
166  update(Super::gridView());
168  }
169  }
170 
172 
173  protected:
174  Comm comm_;
175  };
176 
177 
178  // Deduction guides
179  template <class GV, class PBF>
180  GlobalBasis(std::string const& name, GV const& gridView, PBF const& preBasisFactory)
181  -> GlobalBasis<decltype(flatPreBasis(
182  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
183 
184  template <class GV, class PBF>
185  GlobalBasis(GV const& gridView, PBF const& preBasisFactory)
186  -> GlobalBasis<decltype(flatPreBasis(
187  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
188 
189 } // end namespace AMDiS
GlobalBasis const & rootBasis() const
Return *this because we are not embedded in a larger basis.
Definition: GlobalBasis.hpp:141
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:88
void update(GridView const &gv)
Update the stored grid view.
Definition: GlobalBasis.hpp:121
Global basis defined on a pre-basis.
Definition: GlobalBasis.hpp:50
Definition: FieldMatVec.hpp:12
AMDiS::LocalView< Self > LocalView
Type of the local view on the restriction of the basis to a single element.
Definition: GlobalBasis.hpp:67
void updateImpl(event::adapt e) override
Updates the underlying basis when event::adapt is triggered by the observed grid. ...
Definition: GlobalBasis.hpp:163
Definition: AdaptBase.hpp:6
Implementation of a creator pattern for Communication types.
Definition: Communication.hpp:47
Definition: GlobalBasis.hpp:74
The restriction of a finite element basis to a single element.
Definition: LocalView.hpp:20
Implementation of the ObserverInterface.
Definition: Observer.hpp:100
GlobalBasis(std::string const &name, GridView const &gridView, PBF const &preBasisFactory)
Construct this global basis with a preBasisFactory.
Definition: GlobalBasis.hpp:96
Dummy implementation for sequential communication.
Definition: Communication.hpp:14
Definition: Observer.hpp:25
std::shared_ptr< LocalView > localViewPtr() const
Return local view as shared_ptr to prevent from copy construction.
Definition: GlobalBasis.hpp:135
PB PreBasis
Pre-basis providing the implementation details.
Definition: GlobalBasis.hpp:60
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:63
std::conditional_t< Traits::IsFlatIndex< typename Super::MultiIndex >::value, typename BackendTraits< Self >::Comm, SequentialCommunication > Comm
Type of the communicator.
Definition: GlobalBasis.hpp:72
Mixin for signaling of certain events.
Definition: Observer.hpp:54
Comm const & communicator() const
Return the communicator.
Definition: GlobalBasis.hpp:151
GlobalBasis(Arg &&arg, Args &&... args)
Construct this global basis with empty name.
Definition: GlobalBasis.hpp:105
LocalView localView() const
Return local view for basis.
Definition: GlobalBasis.hpp:129