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>
93{
95
99
101 using OverlappingVector = typename ParentType::OverlappingVector;
104
105 using MatrixBlock = typename SparseMatrixAdapter::MatrixBlock;
106
108 OverlappingVector,
110
111 static_assert(std::is_same<SparseMatrixAdapter, IstlSparseMatrixAdapter<MatrixBlock> >::value,
112 "The ParallelIstlSolverBackend linear solver backend requires the IstlSparseMatrixAdapter");
113
114public:
116 : ParentType(simulator)
117 { }
118
119 static void registerParameters()
120 {
122
123 Parameters::Register<Parameters::LinearSolverMaxError<Scalar>>
124 ("The maximum residual error which the linear solver tolerates"
125 " without giving up");
126 }
127
128protected:
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>>();
140 if(linearSolverAbsTolerance < 0.0)
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
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.
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
const Overlap & overlap() const
Definition: overlappingoperator.hh:76
An overlap aware preconditioner for any ISTL linear solver.
Definition: overlappingpreconditioner.hh:48
An overlap aware ISTL scalar product.
Definition: overlappingscalarproduct.hh:42
Provides the common code which is required by most linear solvers.
Definition: parallelbasebackend.hh:109
GetPropType< TypeTag, Properties::OverlappingVector > OverlappingVector
Definition: parallelbasebackend.hh:122
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: parallelbasebackend.hh:114
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: parallelbasebackend.hh:113
Opm::Linear::OverlappingScalarProduct< OverlappingVector, Overlap > ParallelScalarProduct
Definition: parallelbasebackend.hh:129
OverlappingVector * overlappingx_
Definition: parallelbasebackend.hh:383
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: parallelbasebackend.hh:116
static void registerParameters()
Register all run-time parameters for the linear solver.
Definition: parallelbasebackend.hh:153
Opm::Linear::OverlappingOperator< OverlappingMatrix, OverlappingVector, OverlappingVector > ParallelOperator
Definition: parallelbasebackend.hh:132
OverlappingVector * overlappingb_
Definition: parallelbasebackend.hh:382
Opm::Linear::OverlappingPreconditioner< SequentialPreconditioner, Overlap > ParallelPreconditioner
Definition: parallelbasebackend.hh:128
const Simulator & simulator_
Definition: parallelbasebackend.hh:377
Implements a generic linear solver abstraction.
Definition: parallelbicgstabbackend.hh:93
friend ParentType
Definition: parallelbicgstabbackend.hh:129
ParallelBiCGStabSolverBackend(const Simulator &simulator)
Definition: parallelbicgstabbackend.hh:115
void cleanupSolver_()
Definition: parallelbicgstabbackend.hh:168
std::unique_ptr< ConvergenceCriterion< OverlappingVector > > convCrit_
Definition: parallelbicgstabbackend.hh:171
std::shared_ptr< RawLinearSolver > prepareSolver_(ParallelOperator &parOperator, ParallelScalarProduct &parScalarProduct, ParallelPreconditioner &parPreCond)
Definition: parallelbicgstabbackend.hh:131
static void registerParameters()
Definition: parallelbicgstabbackend.hh:119
std::pair< bool, int > runSolver_(std::shared_ptr< RawLinearSolver > solver)
Definition: parallelbicgstabbackend.hh:162
Declares the parameters for the black oil model.
Declares the properties required by the black oil model.
Definition: bicgstabsolver.hh:42
Definition: blackoilmodel.hh:72
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
The type of the linear solver to be used.
Definition: linalgproperties.hh:38
Definition: parallelbicgstabbackend.hh:52
std::tuple< ParallelBaseLinearSolver > InheritsFrom
Definition: parallelbicgstabbackend.hh:52