AMDiS 2.10
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
11namespace AMDiS {
12namespace Impl {
13
14template <class GV, class LC, class C>
15struct OperatorTraits
16{
17 using GridView = GV;
18 using LocalContext = LC;
19 using ElementContainer = C;
20};
21
22template <class Traits, class... Nodes>
23struct OperatorDefinition
24{
25 using GridView = typename Traits::GridView;
26
27 // Definition of the interface an Operator must fulfill
28 struct Interface
29 {
30 virtual ~Interface() = default;
31 virtual void update(GridView const&) = 0;
32 virtual LocalOperator<Traits,Nodes...> asLocalOperator() const = 0;
33 };
34
35 // Templatized implementation of the interface
36 template <class Impl>
37 struct Model : public Impl
38 {
39 using Impl::Impl;
40 void update(GridView const& gv) final { this->get().update(gv); }
41 LocalOperator<Traits,Nodes...> asLocalOperator() const final {
42 return localOperator(this->get()); }
43 };
44
45 // The Concept definition of an Operator
46 struct Concept
47 {
48 using LOpConcept = typename LocalOperatorDefinition<Traits,Nodes...>::Concept;
49
50 template <class Op>
51 auto require(Op&& op) -> decltype
52 (
53 op.update(std::declval<GridView>()),
54 Dune::Concept::requireConcept<LOpConcept>(localOperator(op))
55 );
56 };
57
58 using Base = Dune::Functions::TypeErasureBase<Interface,Model>;
59};
60
61} // end namespace Impl
62
63
70
77template <class Traits, class... Nodes>
79 : public Impl::OperatorDefinition<Traits,Nodes...>::Base
80{
81 using Definition = Impl::OperatorDefinition<Traits,Nodes...>;
82 using Super = typename Definition::Base;
83
84public:
85 // The gridview the operator is associated to
86 using GridView = typename Traits::GridView;
87
88public:
90 template <class Impl, Dune::disableCopyMove<Operator,Impl> = 0>
91 Operator(Impl&& impl)
92 : Super{FWD(impl)}
93 {
94 static_assert(Concepts::models<typename Definition::Concept(Impl)>,
95 "Implementation does not model the Operator concept.");
96 }
97
99 Operator() = default;
100
102 void update(GridView const& gv)
103 {
104 this->asInterface().update(gv);
105 }
106
108 friend LocalOperator<Traits,Nodes...> localOperator(Operator const& op)
109 {
110 return op.asInterface().asLocalOperator();
111 }
112};
113
114template <class LocalContext, class Op, class GV>
115auto makeOperator(Op op, GV const& gridView)
116{
117 op.update(gridView);
118 return op;
119}
120
121} // end namespace AMDiS
The base class for a local operator to be used in a Assembler.
Definition: LocalOperator.hpp:75
The base class for an operator to be used in an Assembler.
Definition: Operator.hpp:80
Operator(Impl &&impl)
Constructor. Pass any type supporting the OperatorInterface.
Definition: Operator.hpp:91
void update(GridView const &gv)
Update the operator data on a GridView.
Definition: Operator.hpp:102
friend LocalOperator< Traits, Nodes... > localOperator(Operator const &op)
Transform an operator into a local-operator.
Definition: Operator.hpp:108
Operator()=default
Default Constructor.