solverpreconditioner.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  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef EWOMS_SOLVER_PRECONDITIONER_HH
26 #define EWOMS_SOLVER_PRECONDITIONER_HH
27 
28 #include <ewoms/istl/solvers.hh>
29 #include <dune/istl/preconditioners.hh>
30 
31 namespace Ewoms {
32 namespace Linear {
33 
38 template <class Matrix, class DomainVector, class RangeVector>
40  : public Dune::Preconditioner<DomainVector, RangeVector>
41 {
42  typedef Dune::MatrixAdapter<Matrix, DomainVector, RangeVector> InnerOperator;
43  typedef Dune::SeqScalarProduct<DomainVector> InnerScalarProduct;
44  typedef Dune::SeqILU0<Matrix, DomainVector, RangeVector> InnerPreConditioner;
46  typedef typename DomainVector::field_type Scalar;
47 
48 public:
49  typedef DomainVector domain_type;
50  typedef RangeVector range_type;
51 
52  enum { category = Dune::SolverCategory::overlapping };
53 
54  SolverPreconditioner(const Matrix &matrix, int order, Scalar relaxationFactor)
55  {
56  innerOperator_ = new InnerOperator(matrix);
57  innerScalarProduct_ = new InnerScalarProduct;
58  innerPreCond_ = new InnerPreConditioner(matrix, /*relaxation=*/1.0);
59 
60  Scalar tolerance = 1e-6;
61  int maxIter = 10;
62  int verbosity = 0;
63  innerSolver_ = new InnerSolver(*innerOperator_,
64  *innerScalarProduct_,
65  *innerPreCond_,
66  tolerance,
67  maxIter,
68  verbosity);
69  }
70 
72  {
73  delete innerSolver_;
74  delete innerOperator_;
75  delete innerScalarProduct_;
76  delete innerPreCond_;
77  }
78 
79  void pre(domain_type &x, range_type &y)
80  {}
81 
82  void apply(domain_type &x, const range_type &d)
83  {
84  domain_type x0(x);
85  range_type dd(d);
86  Dune::InverseOperatorResult result;
87  innerSolver_->apply(x, dd, result);
88 
89  // make sure that we don't get worse by applying the linear
90  // solver
91  innerOperator_->apply(x0, dd);
92  dd -= d;
93  Scalar defectBefore = dd.two_norm();
94 
95  innerOperator_->apply(x, dd);
96  dd -= d;
97  Scalar defectAfter = dd.two_norm();
98  if (defectBefore < defectAfter) {
99  x = x0;
100  innerPreCond_->apply(x, d);
101  }
102  }
103 
104  void post(domain_type &x)
105  {}
106 
107 private:
108  InnerOperator *innerOperator_;
109  InnerScalarProduct *innerScalarProduct_;
110  InnerPreConditioner *innerPreCond_;
111  InnerSolver *innerSolver_;
112 };
113 
114 } // namespace Linear
115 } // namespace Ewoms
116 
117 #endif
void apply(domain_type &x, const range_type &d)
Definition: solverpreconditioner.hh:82
Copy of dune-istl's linear solvers with added support for pluggable convergence criteria.
DomainVector domain_type
Definition: solverpreconditioner.hh:49
Definition: solverpreconditioner.hh:52
void post(domain_type &x)
Definition: solverpreconditioner.hh:104
RangeVector range_type
Definition: solverpreconditioner.hh:50
Definition: baseauxiliarymodule.hh:35
~SolverPreconditioner()
Definition: solverpreconditioner.hh:71
void pre(domain_type &x, range_type &y)
Definition: solverpreconditioner.hh:79
Bi-conjugate Gradient Stabilized (BiCG-STAB)
Definition: solvers.hh:623
An ISTL preconditioner that solves the linear system of equations locally on each rank...
Definition: solverpreconditioner.hh:39
virtual void apply(X &x, X &b, Dune::InverseOperatorResult &res)
Apply inverse operator.
Definition: solvers.hh:683
SolverPreconditioner(const Matrix &matrix, int order, Scalar relaxationFactor)
Definition: solverpreconditioner.hh:54