AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
BoundaryCondition.hpp
1#pragma once
2
3#include <type_traits>
4
5#include <dune/functions/common/typeerasure.hh>
6
7#include <amdis/common/ConceptsBase.hpp>
8#include <amdis/common/TypeTraits.hpp>
9
10
11namespace AMDiS {
12namespace Impl {
13
14template <class Mat, class Sol, class Rhs>
15struct BoundaryConditionDefinition
16{
17 // Definition of the interface a BoundaryCondition must fulfill
18 struct Interface
19 {
20 virtual ~Interface() = default;
21 virtual void init() = 0;
22 virtual void apply(Mat&, Sol&, Rhs&) = 0;
23 };
24
25 // Templatized implementation of the interface
26 template <class Impl>
27 struct Model : public Impl
28 {
29 using Impl::Impl;
30 void init() final { this->get().init(); }
31 void apply(Mat& A, Sol& x, Rhs& b) final { this->get().apply(A,x,b); }
32 };
33
34 // The Concept definition of a BoundaryCondition
35 struct Concept
36 {
37 template <class BC>
38 auto require(BC&& bc) -> decltype
39 (
40 bc.init(),
41 bc.apply(std::declval<Mat&>(), std::declval<Sol&>(), std::declval<Rhs&>())
42 );
43 };
44
45 using Base = Dune::Functions::TypeErasureBase<Interface, Model>;
46};
47
48} // end namespace Impl
49
50
52
60template <class Mat, class Sol, class Rhs>
62 : public Impl::BoundaryConditionDefinition<Mat,Sol,Rhs>::Base
63{
64 using Definition = Impl::BoundaryConditionDefinition<Mat,Sol,Rhs>;
65 using Super = typename Definition::Base;
66
67public:
69 template <class Impl, Dune::disableCopyMove<BoundaryCondition,Impl> = 0>
71 : Super{FWD(impl)}
72 {
73 static_assert(Concepts::models<typename Definition::Concept(Impl)>,
74 "Implementation does not model the BoundaryCondition concept.");
75 }
76
78 BoundaryCondition() = default;
79
81
85 void init()
86 {
87 this->asInterface().init();
88 }
89
91
95 void apply(Mat& A, Sol& x, Rhs& b)
96 {
97 this->asInterface().apply(A,x,b);
98 }
99};
100
101
102} // end namespace AMDiS
Interface class for boundary conditions.
Definition: BoundaryCondition.hpp:63
void init()
Initialize the boundary condition.
Definition: BoundaryCondition.hpp:85
BoundaryCondition()=default
Default Constructor.
void apply(Mat &A, Sol &x, Rhs &b)
Apply the boundary condition to matrix and vector.
Definition: BoundaryCondition.hpp:95
BoundaryCondition(Impl &&impl)
Constructor. Pass any type supporting the BoundaryConditionInterface.
Definition: BoundaryCondition.hpp:70