Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
solver_relaxation.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2010 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_solver_relaxation_h
17 #define dealii_solver_relaxation_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/logstream.h>
23 #include <deal.II/base/subscriptor.h>
24 
25 #include <deal.II/lac/solver.h>
26 #include <deal.II/lac/solver_control.h>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
58 template <typename VectorType = Vector<double>>
59 class SolverRelaxation : public SolverBase<VectorType>
60 {
61 public:
67  {};
68 
73  const AdditionalData &data = AdditionalData());
74 
78  virtual ~SolverRelaxation();
79 
85  template <typename MatrixType, class RelaxationType>
86  void
87  solve(const MatrixType & A,
88  VectorType & x,
89  const VectorType & b,
90  const RelaxationType &R);
91 };
92 
93 //----------------------------------------------------------------------//
94 
95 template <class VectorType>
97  const AdditionalData &)
98  : SolverBase<VectorType>(cn)
99 {}
100 
101 
102 
103 template <class VectorType>
105 {}
106 
107 
108 template <class VectorType>
109 template <typename MatrixType, class RelaxationType>
110 void
112  VectorType & x,
113  const VectorType & b,
114  const RelaxationType &R)
115 {
118 
119  // Memory allocation
120  typename VectorMemory<VectorType>::Pointer Vr(mem);
121  VectorType & r = *Vr;
122  r.reinit(x);
123  typename VectorMemory<VectorType>::Pointer Vd(mem);
124  VectorType & d = *Vd;
125  d.reinit(x);
126 
127  LogStream::Prefix prefix("Relaxation");
128 
129  int iter = 0;
130  // Main loop
131  for (; conv == SolverControl::iterate; iter++)
132  {
133  // Compute residual
134  A.vmult(r, x);
135  r.sadd(-1., 1., b);
136 
137  // The required norm of the
138  // (preconditioned)
139  // residual is computed in
140  // criterion() and stored
141  // in res.
142  conv = this->iteration_status(iter, r.l2_norm(), x);
143  if (conv != SolverControl::iterate)
144  break;
145  R.step(x, b);
146  }
147 
148  // in case of failure: throw exception
150  SolverControl::NoConvergence(iter, r.l2_norm()));
151  // otherwise exit as normal
152 }
153 
154 
155 DEAL_II_NAMESPACE_CLOSE
156 
157 #endif
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const RelaxationType &R)
virtual ~SolverRelaxation()
Continue iteration.
#define AssertThrow(cond, exc)
Definition: exceptions.h:1519
Stop iteration, goal reached.
SolverRelaxation(SolverControl &cn, const AdditionalData &data=AdditionalData())