Reference documentation for deal.II version 9.0.0
solver_relaxation.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2010 - 2017 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/logstream.h>
22 #include <deal.II/lac/solver.h>
23 #include <deal.II/lac/solver_control.h>
24 #include <deal.II/base/subscriptor.h>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
56 template <typename VectorType = Vector<double> >
57 class SolverRelaxation : public Solver<VectorType>
58 {
59 public:
64  struct AdditionalData {};
65 
70  const AdditionalData &data=AdditionalData());
71 
75  virtual ~SolverRelaxation ();
76 
82  template <typename MatrixType, class RelaxationType>
83  void
84  solve (const MatrixType &A,
85  VectorType &x,
86  const VectorType &b,
87  const RelaxationType &R);
88 };
89 
90 //----------------------------------------------------------------------//
91 
92 template <class VectorType>
94  const AdditionalData &)
95  :
96  Solver<VectorType> (cn)
97 {}
98 
99 
100 
101 template <class VectorType>
103 {}
104 
105 
106 template <class VectorType>
107 template <typename MatrixType, class RelaxationType>
108 void
110  VectorType &x,
111  const VectorType &b,
112  const RelaxationType &R)
113 {
116 
117  // Memory allocation
118  typename VectorMemory<VectorType>::Pointer Vr(mem);
119  VectorType &r = *Vr;
120  r.reinit(x);
121  typename VectorMemory<VectorType>::Pointer Vd(mem);
122  VectorType &d = *Vd;
123  d.reinit(x);
124 
125  LogStream::Prefix prefix("Relaxation");
126 
127  int iter=0;
128  // Main loop
129  for (; conv==SolverControl::iterate; iter++)
130  {
131  // Compute residual
132  A.vmult(r,x);
133  r.sadd(-1.,1.,b);
134 
135  // The required norm of the
136  // (preconditioned)
137  // residual is computed in
138  // criterion() and stored
139  // in res.
140  conv = this->iteration_status (iter, r.l2_norm(), x);
141  if (conv != SolverControl::iterate)
142  break;
143  R.step(x,b);
144  }
145 
146  // in case of failure: throw exception
148  SolverControl::NoConvergence (iter, r.l2_norm()));
149  // otherwise exit as normal
150 }
151 
152 
153 DEAL_II_NAMESPACE_CLOSE
154 
155 #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:1221
Stop iteration, goal reached.
Definition: solver.h:322
SolverRelaxation(SolverControl &cn, const AdditionalData &data=AdditionalData())