FlexibleSolver.hpp
Go to the documentation of this file.
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
26
27#include <dune/istl/solver.hh>
28#include <dune/istl/paamg/pinfo.hh>
29
30namespace Opm
31{
32class PropertyTree;
33}
34
35namespace Dune
36{
37
42template <class Operator>
43class FlexibleSolver : public Dune::InverseOperator<typename Operator::domain_type,
44 typename Operator::range_type>
45{
46public:
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
75private:
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 void recreateDirectSolver();
92
93 // Main initialization routine.
94 // Call with Comm == Dune::Amg::SequentialInformation to get a serial solver.
95 template <class Comm>
96 void init(Operator& op,
97 const Comm& comm,
98 const Opm::PropertyTree& prm,
99 const std::function<VectorType()> weightsCalculator,
100 std::size_t pressureIndex);
101
102 Operator* linearoperator_for_solver_;
103 std::shared_ptr<AbstractPrecondType> preconditioner_;
104 std::shared_ptr<AbstractScalarProductType> scalarproduct_;
105 std::shared_ptr<AbstractSolverType> linsolver_;
106 bool direct_solver_ = false;
107};
108
109} // namespace Dune
110
111//#include <opm/simulators/linalg/FlexibleSolver_impl.hpp>
112
113
114#endif // OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:270
Definition: FlexibleSolver.hpp:45
virtual Dune::SolverCategory::Category category() const override
Definition: FlexibleSolver_impl.hpp:105
virtual void apply(VectorType &x, VectorType &rhs, Dune::InverseOperatorResult &res) override
Definition: FlexibleSolver_impl.hpp:74
typename Operator::domain_type VectorType
Definition: FlexibleSolver.hpp:47
FlexibleSolver(Operator &op, const Opm::PropertyTree &prm, const std::function< VectorType()> &weightsCalculator, std::size_t pressureIndex)
Create a sequential solver.
Definition: FlexibleSolver_impl.hpp:49
AbstractPrecondType & preconditioner()
Access the contained preconditioner.
Definition: FlexibleSolver_impl.hpp:97
Definition: PropertyTree.hpp:37
Definition: SupportsFaceTag.hpp:27
Definition: BlackoilPhases.hpp:27
Dune::InverseOperatorResult InverseOperatorResult
Definition: BdaBridge.hpp:32