All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "parallelbasebackend.hh"
31 #include "bicgstabsolver.hh"
32 #include "combinedcriterion.hh"
33 
34 #include <memory>
35 
36 namespace Ewoms {
37 namespace Linear {
38 template <class TypeTag>
40 }} // namespace Linear, Ewoms
41 
42 namespace Ewoms {
43 namespace Properties {
44 NEW_TYPE_TAG(ParallelBiCGStabLinearSolver, INHERITS_FROM(ParallelBaseLinearSolver));
45 
46 NEW_PROP_TAG(LinearSolverMaxError);
47 
48 SET_TYPE_PROP(ParallelBiCGStabLinearSolver,
49  LinearSolverBackend,
51 
52 SET_SCALAR_PROP(ParallelBiCGStabLinearSolver, LinearSolverMaxError, 1e7);
53 }} // namespace Properties, Ewoms
54 
55 namespace Ewoms {
56 namespace Linear {
83 template <class TypeTag>
84 class ParallelBiCGStabSolverBackend : public ParallelBaseBackend<TypeTag>
85 {
86  typedef ParallelBaseBackend<TypeTag> ParentType;
87 
88  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
89  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
90 
91  typedef typename ParentType::ParallelOperator ParallelOperator;
92  typedef typename ParentType::OverlappingVector OverlappingVector;
93  typedef typename ParentType::ParallelPreconditioner ParallelPreconditioner;
94  typedef typename ParentType::ParallelScalarProduct ParallelScalarProduct;
95 
96  typedef BiCGStabSolver<ParallelOperator,
97  OverlappingVector,
98  ParallelPreconditioner> RawLinearSolver;
99 
100 public:
101  ParallelBiCGStabSolverBackend(const Simulator& simulator)
102  : ParentType(simulator)
103  { }
104 
105  static void registerParameters()
106  {
108 
109  EWOMS_REGISTER_PARAM(TypeTag, Scalar, LinearSolverMaxError,
110  "The maximum residual error which the linear solver tolerates"
111  " without giving up");
112  }
113 
114 protected:
115  friend ParentType;
116 
117  std::shared_ptr<RawLinearSolver> prepareSolver_(ParallelOperator& parOperator,
118  ParallelScalarProduct& parScalarProduct,
119  ParallelPreconditioner& parPreCond)
120  {
121  const auto& gridView = this->simulator_.gridView();
122  typedef CombinedCriterion<OverlappingVector, decltype(gridView.comm())> CCC;
123 
124  Scalar linearSolverTolerance = EWOMS_GET_PARAM(TypeTag, Scalar, LinearSolverTolerance);
125  Scalar linearSolverAbsTolerance = this->simulator_.model().newtonMethod().tolerance() / 10.0;
126 
127  convCrit_.reset(new CCC(gridView.comm(),
128  /*residualReductionTolerance=*/linearSolverTolerance,
129  /*absoluteResidualTolerance=*/linearSolverAbsTolerance,
130  EWOMS_GET_PARAM(TypeTag, Scalar, LinearSolverMaxError)));
131 
132  auto bicgstabSolver =
133  std::make_shared<RawLinearSolver>(parPreCond, *convCrit_, parScalarProduct);
134 
135  int verbosity = 0;
136  if (parOperator.overlap().myRank() == 0)
137  verbosity = EWOMS_GET_PARAM(TypeTag, int, LinearSolverVerbosity);
138  bicgstabSolver->setVerbosity(verbosity);
139  bicgstabSolver->setMaxIterations(EWOMS_GET_PARAM(TypeTag, int, LinearSolverMaxIterations));
140  bicgstabSolver->setLinearOperator(&parOperator);
141  bicgstabSolver->setRhs(this->overlappingb_);
142 
143  return bicgstabSolver;
144  }
145 
146  bool runSolver_(std::shared_ptr<RawLinearSolver> solver)
147  { return solver->apply(*this->overlappingx_); }
148 
149  void cleanupSolver_()
150  { /* nothing to do */ }
151 
152  std::unique_ptr<ConvergenceCriterion<OverlappingVector> > convCrit_;
153 };
154 
155 }} // namespace Linear, Ewoms
156 
157 #endif
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:189
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
#define INHERITS_FROM(...)
Syntactic sugar for NEW_TYPE_TAG.
Definition: propertysystem.hh:230
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
Implements a generic linear solver abstraction.
Definition: parallelbicgstabbackend.hh:39
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
static void registerParameters()
Register all run-time parameters for the linear solver.
Definition: parallelbasebackend.hh:187
Implements a preconditioned stabilized BiCG linear solver.
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247
#define SET_TYPE_PROP(EffTypeTagName, PropTagName,...)
Set a property which defines a type.
Definition: propertysystem.hh:377
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:183
#define SET_SCALAR_PROP(EffTypeTagName, PropTagName,...)
Set a property to a simple constant scalar value.
Definition: propertysystem.hh:394
Provides the common code which is required by most linear solvers.