CuBlockPreconditioner.hpp
Go to the documentation of this file.
1/*
2 Copyright 2022-2023 SINTEF AS
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef OPM_CUISTL_CUBLOCKPRECONDITIONER_HPP
20#define OPM_CUISTL_CUBLOCKPRECONDITIONER_HPP
21
22#include <dune/common/shared_ptr.hh>
23#include <memory>
27
28namespace Opm::cuistl
29{
33template <class X, class Y, class C, class P = Dune::PreconditionerWithUpdate<X, Y>>
35{
36public:
37 using domain_type = X;
38 using range_type = Y;
39 using field_type = typename X::field_type;
41
42
50 CuBlockPreconditioner(const std::shared_ptr<P>& p, const std::shared_ptr<const communication_type>& c)
51 : m_preconditioner(p)
52 , m_communication(c)
53 {
54 }
55
56 CuBlockPreconditioner(const std::shared_ptr<P>& p, const communication_type& c)
57 : m_preconditioner(p)
58 , m_communication(Dune::stackobject_to_shared_ptr(c))
59 {
60 }
61
65 virtual void pre(X& x, Y& b) override
66 {
67 // TODO: [perf] Do we always need to copy, or only when we need the pre step?
68 m_communication->copyOwnerToAll(x, x); // make Dirichlet values consistent
69 if constexpr (detail::shouldCallPreconditionerPre<P>()) {
70 m_preconditioner->pre(x, b);
71 }
72 }
73
77 virtual void apply(X& v, const Y& d) override
78 {
79 m_preconditioner->apply(v, d);
80 m_communication->copyOwnerToAll(v, v);
81 }
82
83
84 virtual void update() override
85 {
86 m_preconditioner->update();
87 }
88
89 virtual void post(X& x) override
90 {
91 if constexpr (detail::shouldCallPreconditionerPost<P>()) {
92 m_preconditioner->post(x);
93 }
94 }
95
97 virtual Dune::SolverCategory::Category category() const override
98 {
99 return Dune::SolverCategory::overlapping;
100 }
101
102 static constexpr bool shouldCallPre()
103 {
104 return detail::shouldCallPreconditionerPost<P>();
105 }
106 static constexpr bool shouldCallPost()
107 {
108 return detail::shouldCallPreconditionerPre<P>();
109 }
110
111 virtual std::shared_ptr<Dune::PreconditionerWithUpdate<X, Y>> getUnderlyingPreconditioner() override
112 {
113 return m_preconditioner;
114 }
115
116
117private:
119 std::shared_ptr<P> m_preconditioner;
120
122 std::shared_ptr<const communication_type> m_communication;
123};
124} // namespace Opm::cuistl
125#endif
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32
Is an adaptation of Dune::BlockPreconditioner that works within the CuISTL framework.
Definition: CuBlockPreconditioner.hpp:35
virtual void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition: CuBlockPreconditioner.hpp:65
X domain_type
Definition: CuBlockPreconditioner.hpp:37
virtual void update() override
Definition: CuBlockPreconditioner.hpp:84
virtual std::shared_ptr< Dune::PreconditionerWithUpdate< X, Y > > getUnderlyingPreconditioner() override
getUnderlyingPreconditioner gets the underlying preconditioner (preconditioner being held)
Definition: CuBlockPreconditioner.hpp:111
virtual void apply(X &v, const Y &d) override
Apply the preconditioner.
Definition: CuBlockPreconditioner.hpp:77
static constexpr bool shouldCallPost()
Definition: CuBlockPreconditioner.hpp:106
C communication_type
Definition: CuBlockPreconditioner.hpp:40
CuBlockPreconditioner(const std::shared_ptr< P > &p, const communication_type &c)
Definition: CuBlockPreconditioner.hpp:56
Y range_type
Definition: CuBlockPreconditioner.hpp:38
CuBlockPreconditioner(const std::shared_ptr< P > &p, const std::shared_ptr< const communication_type > &c)
Constructor.
Definition: CuBlockPreconditioner.hpp:50
static constexpr bool shouldCallPre()
Definition: CuBlockPreconditioner.hpp:102
typename X::field_type field_type
Definition: CuBlockPreconditioner.hpp:39
virtual void post(X &x) override
Definition: CuBlockPreconditioner.hpp:89
virtual Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
Definition: CuBlockPreconditioner.hpp:97
Common interface for adapters that hold preconditioners.
Definition: PreconditionerHolder.hpp:34
Definition: SupportsFaceTag.hpp:27
Definition: CuBlockPreconditioner.hpp:29