My Project
PreconditionerWithUpdate.hpp
1 /*
2  Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
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 
20 #ifndef OPM_PRECONDITIONERWITHUPDATE_HEADER_INCLUDED
21 #define OPM_PRECONDITIONERWITHUPDATE_HEADER_INCLUDED
22 
23 #include <dune/istl/preconditioner.hh>
24 #include <memory>
25 
26 namespace Dune
27 {
28 
30 template <class X, class Y>
31 class PreconditionerWithUpdate : public Preconditioner<X, Y>
32 {
33 public:
34  virtual void update() = 0;
35 };
36 
37 template <class OriginalPreconditioner>
38 class DummyUpdatePreconditioner : public PreconditionerWithUpdate<typename OriginalPreconditioner::domain_type,
39  typename OriginalPreconditioner::range_type>
40 {
41 public:
42  template <class... Args>
43  DummyUpdatePreconditioner(Args&&... args)
44  : orig_precond_(std::forward<Args>(args)...)
45  {
46  }
47 
48  using X = typename OriginalPreconditioner::domain_type;
49  using Y = typename OriginalPreconditioner::range_type;
50 
51  virtual void pre(X& x, Y& b) override
52  {
53  orig_precond_.pre(x, b);
54  }
55 
56  virtual void apply(X& v, const Y& d) override
57  {
58  orig_precond_.apply(v, d);
59  }
60 
61  virtual void post(X& x) override
62  {
63  orig_precond_.post(x);
64  }
65 
66  virtual SolverCategory::Category category() const override
67  {
68  return orig_precond_.category();
69  }
70 
71  // The update() function does nothing for a wrapped preconditioner.
72  virtual void update() override
73  {
74  }
75 
76 private:
77  OriginalPreconditioner orig_precond_;
78 };
79 
80 
81 template <class OriginalPreconditioner, class... Args>
82 std::shared_ptr<DummyUpdatePreconditioner<OriginalPreconditioner>>
83 wrapPreconditioner(Args&&... args)
84 {
85  return std::make_shared<DummyUpdatePreconditioner<OriginalPreconditioner>>(std::forward<Args>(args)...);
86 }
87 
88 
89 } // namespace Dune
90 
91 #endif // OPM_PRECONDITIONERWITHUPDATE_HEADER_INCLUDED
Definition: PreconditionerWithUpdate.hpp:40
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32