BoundaryCondition.hpp 2.62 KB
Newer Older
1
2
#pragma once

Praetorius, Simon's avatar
Praetorius, Simon committed
3
#include <type_traits>
4

Praetorius, Simon's avatar
Praetorius, Simon committed
5
#include <dune/functions/common/typeerasure.hh>
6

Praetorius, Simon's avatar
Praetorius, Simon committed
7
8
9
10
11
12
13
14
15
#include <amdis/common/ConceptsBase.hpp>
#include <amdis/common/TypeTraits.hpp>


namespace AMDiS {
namespace Impl {

template <class Mat, class Sol, class Rhs>
struct BoundaryConditionDefinition
16
{
Praetorius, Simon's avatar
Praetorius, Simon committed
17
18
  // Definition of the interface a BoundaryCondition must fulfill
  struct Interface
19
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
20
    virtual ~Interface() = default;
21
    virtual void init() = 0;
Praetorius, Simon's avatar
Praetorius, Simon committed
22
23
    virtual void apply(Mat&, Sol&, Rhs&) = 0;
  };
24

Praetorius, Simon's avatar
Praetorius, Simon committed
25
26
27
28
29
30
31
  // Templatized implementation of the interface
  template <class Impl>
  struct Model : public Impl
  {
    using Impl::Impl;
    void init() final { this->get().init(); }
    void apply(Mat& A, Sol& x, Rhs& b) final { this->get().apply(A,x,b); }
32
33
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
34
35
  // The Concept definition of a BoundaryCondition
  struct Concept
36
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
42
    template <class BC>
    auto require(BC&& bc) -> decltype
    (
      bc.init(),
      bc.apply(std::declval<Mat&>(), std::declval<Sol&>(), std::declval<Rhs&>())
    );
43
44
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  using Base = Dune::Functions::TypeErasureBase<Interface, Model>;
};

} // end namespace Impl


/// \brief Interface class for boundary conditions
/**
 * Stores a boundary subset related to the boundary condition. See \ref BoundarySubset.
 * \relates DirichletBoundaryCondition
 * \relates PeriodicBoundaryCondition
 * \tparam Mat  Matrix
 * \tparam Sol  Vector of solution
 * \tparam Rhs  Vector of rhs
 **/
template <class Mat, class Sol, class Rhs>
class BoundaryCondition
    : public Impl::BoundaryConditionDefinition<Mat,Sol,Rhs>::Base
{
  using Definition = Impl::BoundaryConditionDefinition<Mat,Sol,Rhs>;
  using Super = typename Definition::Base;

public:
  /// \brief Constructor. Pass any type supporting the \ref BoundaryConditionInterface
  template <class Impl, Dune::disableCopyMove<BoundaryCondition,Impl> = 0>
  BoundaryCondition(Impl&& impl)
    : Super{FWD(impl)}
  {
    static_assert(Concepts::models<typename Definition::Concept(Impl)>,
      "Implementation does not model the BoundaryCondition concept.");
  }

  /// \brief Default Constructor.
  BoundaryCondition() = default;

  /// \brief Initialize the boundary condition.
  /**
   * This performs setup before starting the matrix and vector assembly independantly of the
   * matrix, rhs or solution.
   **/
  void init()
  {
    this->asInterface().init();
  }

  /// \brief Apply the boundary condition to matrix and vector.
  /**
   * This is called after the matrix `A` and rhs `b` are assembled.
   * Implementations may alter values or change the structure of `A`, `x` or `b`.
   **/
  void apply(Mat& A, Sol& x, Rhs& b)
  {
    this->asInterface().apply(A,x,b);
  }
};

101

102
} // end namespace AMDiS