AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Operator.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <dune/common/concept.hh>
6 #include <dune/functions/common/typeerasure.hh>
7 
8 #include <amdis/LocalOperator.hpp>
9 #include <amdis/common/ConceptsBase.hpp>
10 #include <amdis/typetree/TreeContainerTrafo.hpp>
11 
12 namespace AMDiS {
13 namespace Impl {
14 
15 template <class GV, class LC, class C>
16 struct OperatorTraits
17 {
18  using GridView = GV;
19  using LocalContext = LC;
20  using ElementContainer = C;
21 };
22 
23 template <class Traits, class... Nodes>
24 struct OperatorDefinition
25 {
26  using GridView = typename Traits::GridView;
27 
28  // Definition of the interface an Operator must fulfill
29  struct Interface
30  {
31  virtual ~Interface() = default;
32  virtual void update(GridView const&) = 0;
33  virtual LocalOperator<Traits,Nodes...> asLocalOperator() const = 0;
34  };
35 
36  // Templatized implementation of the interface
37  template <class Impl>
38  struct Model : public Impl
39  {
40  using Impl::Impl;
41  void update(GridView const& gv) final { this->get().update(gv); }
42  LocalOperator<Traits,Nodes...> asLocalOperator() const final {
43  return localOperator(this->get()); }
44  };
45 
46  // The Concept definition of an Operator
47  struct Concept
48  {
49  using LOpConcept = typename LocalOperatorDefinition<Traits,Nodes...>::Concept;
50 
51  template <class Op>
52  auto require(Op&& op) -> decltype
53  (
54  op.update(std::declval<GridView>()),
55  Dune::Concept::requireConcept<LOpConcept>(localOperator(op))
56  );
57  };
58 
59  using Base = Dune::Functions::TypeErasureBase<Interface,Model>;
60 };
61 
62 } // end namespace Impl
63 
64 
70 
78 template <class Traits, class... Nodes>
79 class Operator
80  : public Impl::OperatorDefinition<Traits,Nodes...>::Base
81 {
82  using Definition = Impl::OperatorDefinition<Traits,Nodes...>;
83  using Super = typename Definition::Base;
84 
85 public:
86  // The gridview the operator is associated to
87  using GridView = typename Traits::GridView;
88 
89 public:
91  template <class Impl, Dune::disableCopyMove<Operator,Impl> = 0>
92  Operator(Impl&& impl)
93  : Super{FWD(impl)}
94  {
95  static_assert(Concepts::models<typename Definition::Concept(Impl)>,
96  "Implementation does not model the Operator concept.");
97  }
98 
100  Operator() = default;
101 
103  void update(GridView const& gv)
104  {
105  this->asInterface().update(gv);
106  }
107 
109  friend LocalOperator<Traits,Nodes...> localOperator(Operator const& op)
110  {
111  return op.asInterface().asLocalOperator();
112  }
113 };
114 
115 template <class LocalContext, class Op, class GV>
116 auto makeOperator(Op op, GV const& gridView)
117 {
118  op.update(gridView);
119  return op;
120 }
121 
124 template <class Container>
125 auto localOperators(Container const& c)
126 {
127  return Recursive::map([](auto const& op) { return localOperator(op); }, c);
128 }
129 
130 
131 } // end namespace AMDiS
auto localOperators(Container const &c)
Definition: Operator.hpp:125
The base class for an operator to be used in an Assembler.
Definition: Operator.hpp:79
friend LocalOperator< Traits, Nodes... > localOperator(Operator const &op)
Transform an operator into a local-operator.
Definition: Operator.hpp:109
Operator(Impl &&impl)
Constructor. Pass any type supporting the OperatorInterface.
Definition: Operator.hpp:92
Definition: AdaptBase.hpp:6
The base class for a local operator to be used in a Assembler.
Definition: LocalOperator.hpp:73
auto makeOperator(Tag const &tag, Expr &&expr, int gridFctDeg=-1)
Definition: GridFunctionOperator.hpp:235
void update(GridView const &gv)
Update the operator data on a GridView.
Definition: Operator.hpp:103