My Project
FlexibleSolver.hpp
1 /*
2  Copyright 2019, 2020 SINTEF Digital, Mathematics and Cybernetics.
3  Copyright 2020 Equinor.
4 
5  This file is part of the Open Porous Media project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
23 #define OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
24 
25 #include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
26 #include <opm/simulators/linalg/PropertyTree.hpp>
27 
28 #include <dune/istl/solver.hh>
29 #include <dune/istl/paamg/pinfo.hh>
30 
31 namespace Dune
32 {
33 
38 template <class MatrixTypeT, class VectorTypeT>
39 class FlexibleSolver : public Dune::InverseOperator<VectorTypeT, VectorTypeT>
40 {
41 public:
42  using MatrixType = MatrixTypeT;
43  using VectorType = VectorTypeT;
44 
46  using AbstractOperatorType = Dune::AssembledLinearOperator<MatrixType, VectorType, VectorType>;
49 
52  const Opm::PropertyTree& prm,
53  const std::function<VectorType()>& weightsCalculator,
54  std::size_t pressureIndex);
55 
57  template <class Comm>
59  const Comm& comm,
60  const Opm::PropertyTree& prm,
61  const std::function<VectorType()>& weightsCalculator,
62  std::size_t pressureIndex);
63 
64  virtual void apply(VectorType& x, VectorType& rhs, Dune::InverseOperatorResult& res) override;
65 
66  virtual void apply(VectorType& x, VectorType& rhs, double reduction, Dune::InverseOperatorResult& res) override;
67 
70 
71  virtual Dune::SolverCategory::Category category() const override;
72 
73 private:
74  using AbstractScalarProductType = Dune::ScalarProduct<VectorType>;
75  using AbstractSolverType = Dune::InverseOperator<VectorType, VectorType>;
76 
77  // Machinery for making sequential or parallel operators/preconditioners/scalar products.
78  template <class Comm>
79  void initOpPrecSp(AbstractOperatorType& op, const Opm::PropertyTree& prm,
80  const std::function<VectorType()> weightsCalculator, const Comm& comm,
81  std::size_t pressureIndex);
82 
83  void initOpPrecSp(AbstractOperatorType& op, const Opm::PropertyTree& prm,
84  const std::function<VectorType()> weightsCalculator, const Dune::Amg::SequentialInformation&,
85  std::size_t pressureIndex);
86 
87  void initSolver(const Opm::PropertyTree& prm, const bool is_iorank);
88 
89  // Main initialization routine.
90  // Call with Comm == Dune::Amg::SequentialInformation to get a serial solver.
91  template <class Comm>
92  void init(AbstractOperatorType& op,
93  const Comm& comm,
94  const Opm::PropertyTree& prm,
95  const std::function<VectorType()> weightsCalculator,
96  std::size_t pressureIndex);
97 
98  AbstractOperatorType* linearoperator_for_solver_;
99  std::shared_ptr<AbstractOperatorType> linearoperator_for_precond_;
100  std::shared_ptr<AbstractPrecondType> preconditioner_;
101  std::shared_ptr<AbstractScalarProductType> scalarproduct_;
102  std::shared_ptr<AbstractSolverType> linsolver_;
103 };
104 
105 } // namespace Dune
106 
107 
108 
109 #endif // OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
A solver class that encapsulates all needed objects for a linear solver (operator,...
Definition: FlexibleSolver.hpp:40
Dune::AssembledLinearOperator< MatrixType, VectorType, VectorType > AbstractOperatorType
Base class type of the operator passed to the solver.
Definition: FlexibleSolver.hpp:46
FlexibleSolver(AbstractOperatorType &op, const Opm::PropertyTree &prm, const std::function< VectorType()> &weightsCalculator, std::size_t pressureIndex)
Create a sequential solver.
Definition: FlexibleSolver_impl.hpp:41
AbstractPrecondType & preconditioner()
Access the contained preconditioner.
Definition: FlexibleSolver_impl.hpp:83
Definition: PropertyTree.hpp:37