opm-simulators
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  template <class Comm>
90  void initSolver(const Opm::PropertyTree& prm, const Comm& comm);
91 
92  void recreateDirectSolver();
93 
94  // Main initialization routine.
95  // Call with Comm == Dune::Amg::SequentialInformation to get a serial solver.
96  template <class Comm>
97  void init(Operator& op,
98  const Comm& comm,
99  const Opm::PropertyTree& prm,
100  const std::function<VectorType()> weightsCalculator,
101  std::size_t pressureIndex);
102 
103  Operator* linearoperator_for_solver_;
104  std::shared_ptr<AbstractPrecondType> preconditioner_;
105  std::shared_ptr<AbstractScalarProductType> scalarproduct_;
106  std::shared_ptr<AbstractSolverType> linsolver_;
107  bool direct_solver_ = false;
108 };
109 
110 } // namespace Dune
111 
112 //#include <opm/simulators/linalg/FlexibleSolver_impl.hpp>
113 
114 
115 #endif // OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
Definition: fvbaseprimaryvariables.hh:161
FlexibleSolver(Operator &op, const Opm::PropertyTree &prm, const std::function< VectorType()> &weightsCalculator, std::size_t pressureIndex)
Create a sequential solver.
Definition: FlexibleSolver_impl.hpp:60
A solver class that encapsulates all needed objects for a linear solver (operator, scalar product, iterative solver and preconditioner) and sets them up based on runtime parameters, using the PreconditionerFactory for setting up preconditioners.
Definition: FlexibleSolver.hpp:43
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
AbstractPrecondType & preconditioner()
Access the contained preconditioner.
Definition: FlexibleSolver_impl.hpp:108
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:38