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 
27 #include <dune/istl/solver.hh>
28 #include <dune/istl/paamg/pinfo.hh>
29 
30 namespace Opm
31 {
32 class PropertyTree;
33 }
34 
35 namespace Dune
36 {
37 
42 template <class Operator>
43 class FlexibleSolver : public Dune::InverseOperator<typename Operator::domain_type,
44  typename Operator::range_type>
45 {
46 public:
47  using VectorType = typename Operator::domain_type; // Assuming symmetry: domain == range
48 
51 
53  FlexibleSolver(Operator& op,
54  const Opm::PropertyTree& prm,
55  const std::function<VectorType()>& weightsCalculator,
56  std::size_t pressureIndex);
57 
59  template <class Comm>
60  FlexibleSolver(Operator& op,
61  const Comm& comm,
62  const Opm::PropertyTree& prm,
63  const std::function<VectorType()>& weightsCalculator,
64  std::size_t pressureIndex);
65 
66  virtual void apply(VectorType& x, VectorType& rhs, Dune::InverseOperatorResult& res) override;
67 
68  virtual void apply(VectorType& x, VectorType& rhs, double reduction, Dune::InverseOperatorResult& res) override;
69 
72 
73  virtual Dune::SolverCategory::Category category() const override;
74 
75 private:
76  using AbstractScalarProductType = Dune::ScalarProduct<VectorType>;
77  using AbstractSolverType = Dune::InverseOperator<VectorType, VectorType>;
78 
79  // Machinery for making sequential or parallel operators/preconditioners/scalar products.
80  template <class Comm>
81  void initOpPrecSp(Operator& op, const Opm::PropertyTree& prm,
82  const std::function<VectorType()> weightsCalculator, const Comm& comm,
83  std::size_t pressureIndex);
84 
85  void initOpPrecSp(Operator& op, const Opm::PropertyTree& prm,
86  const std::function<VectorType()> weightsCalculator, const Dune::Amg::SequentialInformation&,
87  std::size_t pressureIndex);
88 
89  void initSolver(const Opm::PropertyTree& prm, const bool is_iorank);
90 
91  // Main initialization routine.
92  // Call with Comm == Dune::Amg::SequentialInformation to get a serial solver.
93  template <class Comm>
94  void init(Operator& op,
95  const Comm& comm,
96  const Opm::PropertyTree& prm,
97  const std::function<VectorType()> weightsCalculator,
98  std::size_t pressureIndex);
99 
100  Operator* linearoperator_for_solver_;
101  std::shared_ptr<AbstractPrecondType> preconditioner_;
102  std::shared_ptr<AbstractScalarProductType> scalarproduct_;
103  std::shared_ptr<AbstractSolverType> linsolver_;
104 };
105 
106 } // namespace Dune
107 
108 //#include <opm/simulators/linalg/FlexibleSolver_impl.hpp>
109 
110 
111 #endif // OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
A solver class that encapsulates all needed objects for a linear solver (operator,...
Definition: FlexibleSolver.hpp:45
FlexibleSolver(Operator &op, const Opm::PropertyTree &prm, const std::function< VectorType()> &weightsCalculator, std::size_t pressureIndex)
Create a sequential solver.
Definition: FlexibleSolver_impl.hpp:45
AbstractPrecondType & preconditioner()
Access the contained preconditioner.
Definition: FlexibleSolver_impl.hpp:87
Definition: PropertyTree.hpp:37
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27