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 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
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:285
Definition: FlexibleSolver.hpp:45
virtual Dune::SolverCategory::Category category() const override
Definition: FlexibleSolver_impl.hpp:109
virtual void apply(VectorType &x, VectorType &rhs, Dune::InverseOperatorResult &res) override
Definition: FlexibleSolver_impl.hpp:78
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:53
AbstractPrecondType & preconditioner()
Access the contained preconditioner.
Definition: FlexibleSolver_impl.hpp:101
Definition: PropertyTree.hpp:37
Definition: fvbaseprimaryvariables.hh:141
Definition: blackoilboundaryratevector.hh:37
Dune::InverseOperatorResult InverseOperatorResult
Definition: BdaBridge.hpp:32