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