AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
PreconWrapper.hpp
1#pragma once
2
3#include <memory>
4#include <type_traits>
5#include <utility>
6
7#include <dune/common/hybridutilities.hh>
8#include <dune/common/shared_ptr.hh>
9#include <dune/common/std/type_traits.hh>
10#include <dune/istl/preconditioner.hh>
11#include <dune/istl/solvercategory.hh>
12
13#include <amdis/common/TypeTraits.hpp>
14
15namespace AMDiS
16{
19 template <class P, class S>
21 : public Dune::Preconditioner<typename P::domain_type, typename P::range_type>
22 {
23 using Preconditioner = P;
24 using Storage = S;
25
26 public:
27 using domain_type = typename P::domain_type;
28 using range_type = typename P::range_type;
29
30 private:
31 template <class P_>
32 using HasApplyFoward = decltype(std::declval<P_>().template apply<true>(std::declval<domain_type&>(), std::declval<range_type const&>()));
33
34 public:
35 template <class... Args>
36 explicit PreconWrapper(Storage& storage, Args&&... args)
37 : storage_(Dune::stackobject_to_shared_ptr(storage))
38 , precon_(*storage_, FWD(args)...)
39 {}
40
41 template <class... Args>
42 explicit PreconWrapper(std::shared_ptr<Storage> storage, Args&&... args)
43 : storage_(std::move(storage))
44 , precon_(*storage_, FWD(args)...)
45 {}
46
48 void pre(domain_type& x, range_type& b) override
49 {
50 precon_.pre(x, b);
51 }
52
54 void apply(domain_type& v, range_type const& d) override
55 {
56 precon_.apply(v, d);
57 }
58
60 template <bool forward>
61 void apply(domain_type& v, range_type const& d)
62 {
63 if constexpr (Dune::Std::is_detected<HasApplyFoward, P>::value)
64 precon_.template apply<forward>(v,d);
65 else
66 precon_.apply(v,d);
67 }
68
70 void post(domain_type& x) override
71 {
72 precon_.post(x);
73 }
74
76 Dune::SolverCategory::Category category() const override
77 {
78 return precon_.category();
79 }
80
81 private:
82 std::shared_ptr<Storage> storage_;
83 Preconditioner precon_;
84 };
85
86} // end namespace AMDiS
Definition: PreconWrapper.hpp:22
Dune::SolverCategory::Category category() const override
Category of the preconditioner.
Definition: PreconWrapper.hpp:76
void apply(domain_type &v, range_type const &d)
Apply one step of the preconditioner in forward (or backward) direction.
Definition: PreconWrapper.hpp:61
void post(domain_type &x) override
Clean up.
Definition: PreconWrapper.hpp:70
void apply(domain_type &v, range_type const &d) override
Apply one step of the preconditioner to the system A(v)=d.
Definition: PreconWrapper.hpp:54
void pre(domain_type &x, range_type &b) override
Prepare the preconditioner.
Definition: PreconWrapper.hpp:48
Wrapper for using ITL preconditioners in AMDiS.
Definition: Preconditioner.hpp:15