BoundaryCondition.hpp 2.62 KB
 Praetorius, Simon committed Jan 12, 2019 1 2 #pragma once  Praetorius, Simon committed Nov 21, 2020 3 #include  Praetorius, Simon committed Jan 12, 2019 4   Praetorius, Simon committed Nov 21, 2020 5 #include  Praetorius, Simon committed Jan 12, 2019 6   Praetorius, Simon committed Nov 21, 2020 7 8 9 10 11 12 13 14 15 #include #include namespace AMDiS { namespace Impl { template struct BoundaryConditionDefinition  Praetorius, Simon committed Jan 12, 2019 16 {  Praetorius, Simon committed Nov 21, 2020 17 18  // Definition of the interface a BoundaryCondition must fulfill struct Interface  Praetorius, Simon committed Jan 12, 2019 19  {  Praetorius, Simon committed Nov 21, 2020 20  virtual ~Interface() = default;  Praetorius, Simon committed Apr 14, 2020 21  virtual void init() = 0;  Praetorius, Simon committed Nov 21, 2020 22 23  virtual void apply(Mat&, Sol&, Rhs&) = 0; };  Praetorius, Simon committed Apr 14, 2020 24   Praetorius, Simon committed Nov 21, 2020 25 26 27 28 29 30 31  // Templatized implementation of the interface template 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); }  Praetorius, Simon committed Jan 12, 2019 32 33  };  Praetorius, Simon committed Nov 21, 2020 34 35  // The Concept definition of a BoundaryCondition struct Concept  Praetorius, Simon committed Apr 14, 2020 36  {  Praetorius, Simon committed Nov 21, 2020 37 38 39 40 41 42  template auto require(BC&& bc) -> decltype ( bc.init(), bc.apply(std::declval(), std::declval(), std::declval()) );  Praetorius, Simon committed Apr 14, 2020 43 44  };  Praetorius, Simon committed Nov 21, 2020 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; }; } // 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 BoundaryCondition : public Impl::BoundaryConditionDefinition::Base { using Definition = Impl::BoundaryConditionDefinition; using Super = typename Definition::Base; public: /// \brief Constructor. Pass any type supporting the \ref BoundaryConditionInterface template = 0> BoundaryCondition(Impl&& impl) : Super{FWD(impl)} { static_assert(Concepts::models, "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); } };  Praetorius, Simon committed Apr 14, 2020 101   Praetorius, Simon committed Jan 12, 2019 102 } // end namespace AMDiS