AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
LocalOperator.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <dune/functions/common/typeerasure.hh>
6 
7 #include <amdis/ContextGeometry.hpp>
8 #include <amdis/common/ConceptsBase.hpp>
9 #include <amdis/common/TypeTraits.hpp>
10 
11 namespace AMDiS {
12 namespace Impl {
13 
14 template <class Traits, class... Nodes>
15 struct LocalOperatorDefinition
16 {
17  using MatVec = typename Traits::ElementContainer;
18  using CG = ContextGeometry<typename Traits::LocalContext>;
19  using Element = typename CG::Element;
20 
21  // Definition of the interface a LocalOperator must fulfill
22  struct Interface
23  {
24  virtual ~Interface() = default;
25  virtual void bind(Element const&) = 0;
26  virtual void unbind() = 0;
27  virtual void assemble(CG const&, Nodes const&..., MatVec&) const = 0;
28  };
29 
30  // Templatized implementation of the interface
31  template <class Impl>
32  struct Model : public Impl
33  {
34  using Impl::Impl;
35  void bind(Element const& e) final { this->get().bind(e); }
36  void unbind() final { this->get().unbind(); }
37  void assemble(CG const& cg, Nodes const&... ns, MatVec& mv) const final {
38  this->get().assemble(cg,ns...,mv); }
39  };
40 
41  // The Concept definition of a LocalOperator
42  struct Concept
43  {
44  template <class LOp>
45  auto require(LOp&& lop) -> decltype
46  (
47  lop.bind(std::declval<Element>()),
48  lop.unbind(),
49  lop.assemble(std::declval<CG>(), std::declval<Nodes>()..., std::declval<MatVec&>())
50  );
51  };
52 
53  using Base = Dune::Functions::TypeErasureBase<Interface, Model>;
54 };
55 
56 } // end namespace Impl
57 
58 
64 
72 template <class Traits, class... Nodes>
74  : public Impl::LocalOperatorDefinition<Traits,Nodes...>::Base
75 {
76  using Definition = Impl::LocalOperatorDefinition<Traits,Nodes...>;
77  using Super = typename Definition::Base;
78 
79 public:
81  using MatVec = typename Traits::ElementContainer;
82 
85 
87  using Element = typename ContextGeo::Element;
88 
89 public:
91  template <class Impl, Dune::disableCopyMove<LocalOperator,Impl> = 0>
93  : Super{FWD(impl)}
94  {
95  static_assert(Concepts::models<typename Definition::Concept(Impl)>,
96  "Implementation does not model the LocalOperator concept.");
97  }
98 
100  LocalOperator() = default;
101 
103 
106  void bind(Element const& element)
107  {
108  this->asInterface().bind(element);
109  }
110 
112  void unbind()
113  {
114  this->asInterface().unbind();
115  }
116 
118 
123  void assemble(ContextGeo const& cg, Nodes const&... ns, MatVec& mv) const
124  {
125  this->asInterface().assemble(cg,ns...,mv);
126  }
127 };
128 
130 
131 } // end namespace AMDiS
typename ContextGeo::Element Element
The grid entity of codim=0.
Definition: LocalOperator.hpp:87
void assemble(ContextGeo const &cg, Nodes const &... ns, MatVec &mv) const
Assemble a local element matrix or vector on the element that is bound.
Definition: LocalOperator.hpp:123
Definition: AdaptBase.hpp:6
void bind(Element const &element)
Binds the local operator to an element.
Definition: LocalOperator.hpp:106
The base class for a local operator to be used in a Assembler.
Definition: LocalOperator.hpp:73
LocalOperator(Impl &&impl)
Constructor. Pass any type supporting the LocalOperatorInterface.
Definition: LocalOperator.hpp:92
void unbind()
Unbinds operator from element.
Definition: LocalOperator.hpp:112
Wrapper class for element and geometry.
Definition: ContextGeometry.hpp:48