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
30#include "linalgproperties.hh"
32#include "bicgstabsolver.hh"
33#include "combinedcriterion.hh"
35
36#include <memory>
37
38namespace Opm::Linear {
39template <class TypeTag>
40class ParallelBiCGStabSolverBackend;
41} // namespace Opm::Linear
42
43namespace Opm::Properties {
44
45// Create new type tags
46namespace TTag {
47struct ParallelBiCGStabLinearSolver { using InheritsFrom = std::tuple<ParallelBaseLinearSolver>; };
48} // end namespace TTag
49
50template<class TypeTag>
51struct LinearSolverBackend<TypeTag, TTag::ParallelBiCGStabLinearSolver>
53
54template<class TypeTag>
55struct LinearSolverMaxError<TypeTag, TTag::ParallelBiCGStabLinearSolver>
56{
58 static constexpr type value = 1e7;
59};
60
61} // namespace Opm::Properties
62
63namespace Opm {
64namespace Linear {
92template <class TypeTag>
94{
96
100
102 using OverlappingVector = typename ParentType::OverlappingVector;
105
106 using MatrixBlock = typename SparseMatrixAdapter::MatrixBlock;
107
109 OverlappingVector,
111
112 static_assert(std::is_same<SparseMatrixAdapter, IstlSparseMatrixAdapter<MatrixBlock> >::value,
113 "The ParallelIstlSolverBackend linear solver backend requires the IstlSparseMatrixAdapter");
114
115public:
117 : ParentType(simulator)
118 { }
119
120 static void registerParameters()
121 {
123
124 Parameters::registerParam<TypeTag, Properties::LinearSolverMaxError>
125 ("The maximum residual error which the linear solver tolerates"
126 " without giving up");
127 }
128
129protected:
131
132 std::shared_ptr<RawLinearSolver> prepareSolver_(ParallelOperator& parOperator,
133 ParallelScalarProduct& parScalarProduct,
134 ParallelPreconditioner& parPreCond)
135 {
136 const auto& gridView = this->simulator_.gridView();
137 using CCC = CombinedCriterion<OverlappingVector, decltype(gridView.comm())>;
138
139 Scalar linearSolverTolerance = Parameters::get<TypeTag, Properties::LinearSolverTolerance>();
140 Scalar linearSolverAbsTolerance = Parameters::get<TypeTag, Properties::LinearSolverAbsTolerance>();
141 if(linearSolverAbsTolerance < 0.0)
142 linearSolverAbsTolerance = this->simulator_.model().newtonMethod().tolerance() / 100.0;
143
144 convCrit_.reset(new CCC(gridView.comm(),
145 /*residualReductionTolerance=*/linearSolverTolerance,
146 /*absoluteResidualTolerance=*/linearSolverAbsTolerance,
147 Parameters::get<TypeTag, Properties::LinearSolverMaxError>()));
148
149 auto bicgstabSolver =
150 std::make_shared<RawLinearSolver>(parPreCond, *convCrit_, parScalarProduct);
151
152 int verbosity = 0;
153 if (parOperator.overlap().myRank() == 0)
154 verbosity = Parameters::get<TypeTag, Properties::LinearSolverVerbosity>();
155 bicgstabSolver->setVerbosity(verbosity);
156 bicgstabSolver->setMaxIterations(Parameters::get<TypeTag, Properties::LinearSolverMaxIterations>());
157 bicgstabSolver->setLinearOperator(&parOperator);
158 bicgstabSolver->setRhs(this->overlappingb_);
159
160 return bicgstabSolver;
161 }
162
163 std::pair<bool,int> runSolver_(std::shared_ptr<RawLinearSolver> solver)
164 {
165 bool converged = solver->apply(*this->overlappingx_);
166 return std::make_pair(converged, int(solver->report().iterations()));
167 }
168
170 { /* nothing to do */ }
171
172 std::unique_ptr<ConvergenceCriterion<OverlappingVector> > convCrit_;
173};
174
175}} // namespace Linear, Opm
176
177#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:94
friend ParentType
Definition: parallelbicgstabbackend.hh:130
ParallelBiCGStabSolverBackend(const Simulator &simulator)
Definition: parallelbicgstabbackend.hh:116
void cleanupSolver_()
Definition: parallelbicgstabbackend.hh:169
std::unique_ptr< ConvergenceCriterion< OverlappingVector > > convCrit_
Definition: parallelbicgstabbackend.hh:172
std::shared_ptr< RawLinearSolver > prepareSolver_(ParallelOperator &parOperator, ParallelScalarProduct &parScalarProduct, ParallelPreconditioner &parPreCond)
Definition: parallelbicgstabbackend.hh:132
static void registerParameters()
Definition: parallelbicgstabbackend.hh:120
std::pair< bool, int > runSolver_(std::shared_ptr< RawLinearSolver > solver)
Definition: parallelbicgstabbackend.hh:163
Declares the properties required by the black oil model.
Definition: bicgstabsolver.hh:42
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
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:242
The type of the linear solver to be used.
Definition: linalgproperties.hh:38
GetPropType< TypeTag, Scalar > type
Definition: parallelbicgstabbackend.hh:57
Definition: linalgproperties.hh:108
Definition: parallelbicgstabbackend.hh:47
std::tuple< ParallelBaseLinearSolver > InheritsFrom
Definition: parallelbicgstabbackend.hh:47