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/flatmultiindex.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/Traits.hpp>
29 #include <amdis/typetree/MultiIndex.hpp>
30 
31 namespace AMDiS
32 {
33  template <class PreBasisFactory, class PBF = remove_cvref_t<PreBasisFactory>>
34  using MultiIndex_t = std::conditional_t<(PBF::requiredMultiIndexSize == 1),
35  Dune::Functions::FlatMultiIndex<std::size_t>,
36  Dune::ReservedVector<std::size_t, PBF::requiredMultiIndexSize>>;
37 
38 
48  template <class PB>
50  : public Dune::Functions::DefaultGlobalBasis<PB>
51  , public Notifier<event::adapt>
52  , private Observer<event::adapt>
53  {
54  using Self = GlobalBasis<PB>;
55  using Super = Dune::Functions::DefaultGlobalBasis<PB>;
56 
57  public:
59  using PreBasis = PB;
60 
62  using GridView = typename PreBasis::GridView;
63  using Grid = typename GridView::Grid;
64 
67 
69  using Comm = std::conditional_t<Traits::IsFlatIndex<typename Super::MultiIndex>::value,
72 
73  struct DummyImpl {};
74  using ADH = Dune::AdaptDataHandle<Grid, DummyImpl>;
75 
76  public:
78 
85  template <class... Args,
86  Dune::Functions::enableIfConstructible<PreBasis, Args...> = 0>
87  GlobalBasis(std::string const& name, Grid const& grid, Args&&... args)
88  : Super(FWD(args)...)
89  , Observer<event::adapt>(grid)
90  , comm_(CommunicationCreator<Comm>::create(static_cast<Super const&>(*this), name + "->solver"))
91  {}
92 
94  template <class PBF>
95  GlobalBasis(std::string const& name, GridView const& gridView,
96  PBF const& preBasisFactory)
97  : GlobalBasis(name, gridView.grid(),
98  flatPreBasis(preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))
99  {}
100 
102  template <class Arg, class... Args,
103  REQUIRES(!std::is_same_v<std::string, remove_cvref_t<Arg>>)>
104  GlobalBasis(Arg&& arg, Args&&... args)
105  : GlobalBasis(std::string(""), FWD(arg), FWD(args)...)
106  {}
107 
109  GlobalBasis(GlobalBasis const&) = delete;
110 
112  GlobalBasis(GlobalBasis&&) = default;
113 
114  public:
116 
120  void update(GridView const& gv)
121  {
122  Super::preBasis().update(gv);
123  Super::preBasis().initializeIndices();
124  comm_.update(*this);
125  }
126 
129  {
130  return LocalView(*this);
131  }
132 
134  std::shared_ptr<LocalView> localViewPtr() const
135  {
136  return std::make_shared<LocalView>(*this);
137  }
138 
140  GlobalBasis const& rootBasis() const
141  {
142  return *this;
143  }
144 
146 
150  Comm const& communicator() const { return comm_; }
151  Comm& communicator() { return comm_; }
152 
153  ADH globalRefineCallback() const
154  {
155  // TODO(FM): Implement
156  error_exit("Not implemented: GlobalBasis::globalRefineCallback()");
157  return ADH{};
158  }
159 
160  protected:
162  void updateImpl(event::adapt e) override
163  {
164  if (e.value) {
165  update(Super::gridView());
167  }
168  }
169 
171 
172  protected:
173  Comm comm_;
174  };
175 
176 
177  // Deduction guides
178  template <class GV, class PBF>
179  GlobalBasis(std::string const& name, GV const& gridView, PBF const& preBasisFactory)
180  -> GlobalBasis<decltype(flatPreBasis(
181  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
182 
183  template <class GV, class PBF>
184  GlobalBasis(GV const& gridView, PBF const& preBasisFactory)
185  -> GlobalBasis<decltype(flatPreBasis(
186  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
187 
188 } // end namespace AMDiS
GlobalBasis const & rootBasis() const
Return *this because we are not embedded in a larger basis.
Definition: GlobalBasis.hpp:140
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:87
void update(GridView const &gv)
Update the stored grid view.
Definition: GlobalBasis.hpp:120
Global basis defined on a pre-basis.
Definition: GlobalBasis.hpp:49
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:66
void updateImpl(event::adapt e) override
Updates the underlying basis when event::adapt is triggered by the observed grid. ...
Definition: GlobalBasis.hpp:162
Definition: AdaptBase.hpp:6
Implementation of a creator pattern for Communication types.
Definition: Communication.hpp:47
Definition: GlobalBasis.hpp:73
The restriction of a finite element basis to a single element.
Definition: LocalView.hpp:21
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:95
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:134
PB PreBasis
Pre-basis providing the implementation details.
Definition: GlobalBasis.hpp:59
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:62
std::conditional_t< Traits::IsFlatIndex< typename Super::MultiIndex >::value, typename BackendTraits< Self >::Comm, SequentialCommunication > Comm
Type of the communicator.
Definition: GlobalBasis.hpp:71
Mixin for signaling of certain events.
Definition: Observer.hpp:54
Comm const & communicator() const
Return the communicator.
Definition: GlobalBasis.hpp:150
GlobalBasis(Arg &&arg, Args &&... args)
Construct this global basis with empty name.
Definition: GlobalBasis.hpp:104
LocalView localView() const
Return local view for basis.
Definition: GlobalBasis.hpp:128