My Project
Loading...
Searching...
No Matches
parallelbicgstabbackend.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef EWOMS_PARALLEL_BICGSTAB_BACKEND_HH
28#define EWOMS_PARALLEL_BICGSTAB_BACKEND_HH
29
36
37#include <memory>
38
39namespace Opm::Linear {
40
41template <class TypeTag>
42class ParallelBiCGStabSolverBackend;
43
44} // namespace Opm::Linear
45
46namespace Opm::Properties {
47
48// Create new type tags
49namespace TTag {
50
52{ using InheritsFrom = std::tuple<ParallelBaseLinearSolver>; };
53
54} // end namespace TTag
55
56template<class TypeTag>
57struct LinearSolverBackend<TypeTag, TTag::ParallelBiCGStabLinearSolver>
59
60} // namespace Opm::Properties
61
62namespace Opm::Linear {
63
91template <class TypeTag>
92class ParallelBiCGStabSolverBackend : public ParallelBaseBackend<TypeTag>
93{
94 using ParentType = ParallelBaseBackend<TypeTag>;
95
99
100 using ParallelOperator = typename ParentType::ParallelOperator;
101 using OverlappingVector = typename ParentType::OverlappingVector;
102 using ParallelPreconditioner = typename ParentType::ParallelPreconditioner;
103 using ParallelScalarProduct = typename ParentType::ParallelScalarProduct;
104
105 using MatrixBlock = typename SparseMatrixAdapter::MatrixBlock;
106
107 using RawLinearSolver = BiCGStabSolver<ParallelOperator,
108 OverlappingVector,
109 ParallelPreconditioner>;
110
111 static_assert(std::is_same<SparseMatrixAdapter, IstlSparseMatrixAdapter<MatrixBlock> >::value,
112 "The ParallelIstlSolverBackend linear solver backend requires the IstlSparseMatrixAdapter");
113
114public:
115 ParallelBiCGStabSolverBackend(const Simulator& simulator)
116 : ParentType(simulator)
117 { }
118
119 static void registerParameters()
120 {
121 ParentType::registerParameters();
122
123 Parameters::Register<Parameters::LinearSolverMaxError<Scalar>>
124 ("The maximum residual error which the linear solver tolerates"
125 " without giving up");
126 }
127
128protected:
129 friend ParentType;
130
131 std::shared_ptr<RawLinearSolver> prepareSolver_(ParallelOperator& parOperator,
132 ParallelScalarProduct& parScalarProduct,
133 ParallelPreconditioner& parPreCond)
134 {
135 const auto& gridView = this->simulator_.gridView();
136 using CCC = CombinedCriterion<OverlappingVector, decltype(gridView.comm())>;
137
138 Scalar linearSolverTolerance = Parameters::Get<Parameters::LinearSolverTolerance<Scalar>>();
139 Scalar linearSolverAbsTolerance = Parameters::Get<Parameters::LinearSolverAbsTolerance<Scalar>>();
141 linearSolverAbsTolerance = this->simulator_.model().newtonMethod().tolerance() / 100.0;
142
143 convCrit_.reset(new CCC(gridView.comm(),
144 /*residualReductionTolerance=*/linearSolverTolerance,
145 /*absoluteResidualTolerance=*/linearSolverAbsTolerance,
146 Parameters::Get<Parameters::LinearSolverMaxError<Scalar>>()));
147
148 auto bicgstabSolver =
149 std::make_shared<RawLinearSolver>(parPreCond, *convCrit_, parScalarProduct);
150
151 int verbosity = 0;
152 if (parOperator.overlap().myRank() == 0)
153 verbosity = Parameters::Get<Parameters::LinearSolverVerbosity>();
154 bicgstabSolver->setVerbosity(verbosity);
155 bicgstabSolver->setMaxIterations(Parameters::Get<Parameters::LinearSolverMaxIterations>());
156 bicgstabSolver->setLinearOperator(&parOperator);
157 bicgstabSolver->setRhs(this->overlappingb_);
158
159 return bicgstabSolver;
160 }
161
162 std::pair<bool,int> runSolver_(std::shared_ptr<RawLinearSolver> solver)
163 {
164 bool converged = solver->apply(*this->overlappingx_);
165 return std::make_pair(converged, int(solver->report().iterations()));
166 }
167
168 void cleanupSolver_()
169 { /* nothing to do */ }
170
171 std::unique_ptr<ConvergenceCriterion<OverlappingVector> > convCrit_;
172};
173
174} // namespace Opm::Linear
175
176#endif
Implements a preconditioned stabilized BiCG linear solver.
Implements a preconditioned stabilized BiCG linear solver.
Definition bicgstabsolver.hh:54
Convergence criterion which looks at the absolute value of the residual and fails if the linear solve...
Definition combinedcriterion.hh:56
An overlap aware linear operator usable by ISTL.
Definition overlappingoperator.hh:42
An overlap aware preconditioner for any ISTL linear solver.
Definition overlappingpreconditioner.hh:48
An overlap aware ISTL scalar product.
Definition overlappingscalarproduct.hh:42
Implements a generic linear solver abstraction.
Definition parallelbicgstabbackend.hh:93
Convergence criterion which looks at the absolute value of the residual and fails if the linear solve...
A sparse matrix interface backend for BCRSMatrix from dune-istl.
Declares the parameters for the black oil model.
Declares the properties required by the black oil model.
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:235
Provides the common code which is required by most linear solvers.
The type of the linear solver to be used.
Definition linalgproperties.hh:38
Definition parallelbicgstabbackend.hh:52