Reference documentation for deal.II version 8.5.1
solver_relaxation.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2010 - 2015 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  deallog.push("Relaxation");
126 
127  int iter=0;
128  try
129  {
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  catch (...)
149  {
150  deallog.pop();
151  throw;
152  }
153  deallog.pop();
154 
155  // in case of failure: throw exception
157  SolverControl::NoConvergence (iter, r.l2_norm()));
158  // otherwise exit as normal
159 }
160 
161 
162 DEAL_II_NAMESPACE_CLOSE
163 
164 #endif
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const RelaxationType &R)
void pop()
Definition: logstream.cc:306
virtual ~SolverRelaxation()
Continue iteration.
#define AssertThrow(cond, exc)
Definition: exceptions.h:369
Stop iteration, goal reached.
Definition: solver.h:325
void push(const std::string &text)
Definition: logstream.cc:294
SolverRelaxation(SolverControl &cn, const AdditionalData &data=AdditionalData())