opm-simulators
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 
39 namespace Opm::Linear {
40 
41 template <class TypeTag>
43 
44 } // namespace Opm::Linear
45 
46 namespace Opm::Properties {
47 
48 // Create new type tags
49 namespace TTag {
50 
52 { using InheritsFrom = std::tuple<ParallelBaseLinearSolver>; };
53 
54 } // end namespace TTag
55 
56 template<class TypeTag>
57 struct LinearSolverBackend<TypeTag, TTag::ParallelBiCGStabLinearSolver>
59 
60 } // namespace Opm::Properties
61 
62 namespace Opm::Linear {
63 
91 template <class TypeTag>
92 class 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 
114 public:
115  explicit ParallelBiCGStabSolverBackend(const Simulator& simulator)
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 
128 protected:
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>>();
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 
168  void cleanupSolver_()
169  { /* nothing to do */ }
170 
171  std::unique_ptr<ConvergenceCriterion<OverlappingVector> > convCrit_;
172 };
173 
174 } // namespace Opm::Linear
175 
176 #endif
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:233
Implements a generic linear solver abstraction.
Definition: parallelbicgstabbackend.hh:42
Definition: matrixblock.hh:228
A sparse matrix interface backend for BCRSMatrix from dune-istl.
Definition: bicgstabsolver.hh:42
static void registerParameters()
Register all run-time parameters for the linear solver.
Definition: parallelbasebackend.hh:153
Declares the parameters for the black oil model.
Implements a preconditioned stabilized BiCG linear solver.
Convergence criterion which looks at the absolute value of the residual and fails if the linear solve...
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
Definition: blackoilmodel.hh:80
Definition: parallelbicgstabbackend.hh:51
Declares the properties required by the black oil model.
The type of the linear solver to be used.
Definition: linalgproperties.hh:38
Provides the common code which is required by most linear solvers.