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 #if DUNE_VERSION_LT(DUNE_FUNCTIONS,2,7)
32 #include <dune/functions/functionspacebases/defaultlocalindexset.hh>
33 #endif
34 
35 namespace AMDiS
36 {
37  template <class PreBasisFactory, class PBF = remove_cvref_t<PreBasisFactory>>
38  using MultiIndex_t = std::conditional_t<(PBF::requiredMultiIndexSize == 1),
39  Dune::Functions::FlatMultiIndex<std::size_t>,
40  Dune::ReservedVector<std::size_t, PBF::requiredMultiIndexSize>>;
41 
42 
52  template <class PB>
54  : public Dune::Functions::DefaultGlobalBasis<PB>
55  , public Notifier<event::adapt>
56  , private Observer<event::adapt>
57  {
58  using Self = GlobalBasis<PB>;
59  using Super = Dune::Functions::DefaultGlobalBasis<PB>;
60 
61  public:
63  using PreBasis = PB;
64 
66  using GridView = typename PreBasis::GridView;
67  using Grid = typename GridView::Grid;
68 
71 
73  using Comm = std::conditional_t<Traits::IsFlatIndex<typename Super::MultiIndex>::value,
76 
77  struct DummyImpl {};
78  using ADH = Dune::AdaptDataHandle<Grid, DummyImpl>;
79 
80  public:
82 
89  template <class... Args,
90  Dune::Functions::enableIfConstructible<PreBasis, Args...> = 0>
91  GlobalBasis(std::string const& name, Grid const& grid, Args&&... args)
92  : Super(FWD(args)...)
93  , Observer<event::adapt>(grid)
94  , comm_(CommunicationCreator<Comm>::create(static_cast<Super const&>(*this), name + "->solver"))
95  {}
96 
98  template <class PBF>
99  GlobalBasis(std::string const& name, GridView const& gridView,
100  PBF const& preBasisFactory)
101  : GlobalBasis(name, gridView.grid(),
102  flatPreBasis(preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))
103  {}
104 
106  template <class Arg, class... Args,
107  REQUIRES(!std::is_same_v<std::string, remove_cvref_t<Arg>>)>
108  GlobalBasis(Arg&& arg, Args&&... args)
109  : GlobalBasis(std::string(""), FWD(arg), FWD(args)...)
110  {}
111 
113  GlobalBasis(GlobalBasis const&) = delete;
114 
116  GlobalBasis(GlobalBasis&&) = default;
117 
118  public:
120 
124  void update(GridView const& gv)
125  {
126  Super::preBasis().update(gv);
127  Super::preBasis().initializeIndices();
128  comm_.update(*this);
129  }
130 
133  {
134  return LocalView(*this);
135  }
136 
138  GlobalBasis const& rootBasis() const
139  {
140  return *this;
141  }
142 
144 
148  Comm const& communicator() const { return comm_; }
149  Comm& communicator() { return comm_; }
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  Comm comm_;
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<decltype(flatPreBasis(
179  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
180 
181  template <class GV, class PBF>
182  GlobalBasis(GV const& gridView, PBF const& preBasisFactory)
183  -> GlobalBasis<decltype(flatPreBasis(
184  preBasisFactory.template makePreBasis<MultiIndex_t<PBF>>(gridView)))>;
185 
186 } // end namespace AMDiS
GlobalBasis const & rootBasis() const
Return *this because we are not embedded in a larger basis.
Definition: GlobalBasis.hpp:138
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:91
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
typename remove_cvref< T >::type remove_cvref_t
Helper alias template for remove_cvref.
Definition: TypeTraits.hpp:24
void update(GridView const &gv)
Update the stored grid view.
Definition: GlobalBasis.hpp:124
Global basis defined on a pre-basis.
Definition: GlobalBasis.hpp:53
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:70
void updateImpl(event::adapt e) override
Updates the underlying basis when event::adapt is triggered by the observed grid. ...
Definition: GlobalBasis.hpp:160
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Implementation of a creator pattern for Communication types.
Definition: Communication.hpp:47
Definition: GlobalBasis.hpp:77
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:99
Dummy implementation for sequential communication.
Definition: Communication.hpp:14
Definition: Observer.hpp:25
PB PreBasis
Pre-basis providing the implementation details.
Definition: GlobalBasis.hpp:63
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:66
std::conditional_t< Traits::IsFlatIndex< typename Super::MultiIndex >::value, typename BackendTraits< Self >::Comm, SequentialCommunication > Comm
Type of the communicator.
Definition: GlobalBasis.hpp:75
Mixin for signaling of certain events.
Definition: Observer.hpp:54
Comm const & communicator() const
Return the communicator.
Definition: GlobalBasis.hpp:148
GlobalBasis(Arg &&arg, Args &&... args)
Construct this global basis with empty name.
Definition: GlobalBasis.hpp:108
LocalView localView() const
Return local view for basis.
Definition: GlobalBasis.hpp:132