Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
solver_relaxation.h
1 // ---------------------------------------------------------------------
2 // @f$Id: solver_relaxation.h 31356 2013-10-20 21:34:20Z maier @f$
3 //
4 // Copyright (C) 2010 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__solver_relaxation_h
18 #define __deal2__solver_relaxation_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/logstream.h>
23 #include <deal.II/lac/solver.h>
24 #include <deal.II/lac/solver_control.h>
25 #include <deal.II/base/subscriptor.h>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
50 template <class VECTOR = Vector<double> >
51 class SolverRelaxation : public Solver<VECTOR>
52 {
53 public:
60  struct AdditionalData {};
61 
66  const AdditionalData &data=AdditionalData());
67 
71  virtual ~SolverRelaxation ();
72 
80  template<class MATRIX, class RELAXATION>
81  void
82  solve (const MATRIX &A,
83  VECTOR &x,
84  const VECTOR &b,
85  const RELAXATION &R);
86 };
87 
88 //----------------------------------------------------------------------//
89 
90 template <class VECTOR>
92  const AdditionalData &)
93  :
94  Solver<VECTOR> (cn)
95 {}
96 
97 
98 
99 template <class VECTOR>
101 {}
102 
103 
104 template <class VECTOR>
105 template <class MATRIX, class RELAXATION>
106 void
108  const MATRIX &A,
109  VECTOR &x,
110  const VECTOR &b,
111  const RELAXATION &R)
112 {
115 
116  // Memory allocation
117  typename VectorMemory<VECTOR>::Pointer Vr(mem);
118  VECTOR &r = *Vr;
119  r.reinit(x);
120  typename VectorMemory<VECTOR>::Pointer Vd(mem);
121  VECTOR &d = *Vd;
122  d.reinit(x);
123 
124  deallog.push("Relaxation");
125 
126  try
127  {
128  // Main loop
129  for (int iter=0; 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->control().check (iter, r.l2_norm());
141  if (conv != SolverControl::iterate)
142  break;
143  R.step(x,b);
144  }
145  }
146  catch (...)
147  {
148  deallog.pop();
149  throw;
150  }
151  deallog.pop();
152 
153  // in case of failure: throw exception
154  if (this->control().last_check() != SolverControl::success)
155  AssertThrow(false, SolverControl::NoConvergence (this->control().last_step(),
156  this->control().last_value()));
157  // otherwise exit as normal
158 }
159 
160 
161 DEAL_II_NAMESPACE_CLOSE
162 
163 #endif
void pop()
void vmult(VECTOR &u, const VECTOR &v) const
Continue iteration.
void solve(const MATRIX &A, VECTOR &x, const VECTOR &b, const RELAXATION &R)
SolverRelaxation(SolverControl &cn, const AdditionalData &data=AdditionalData())
virtual ~SolverRelaxation()
#define AssertThrow(cond, exc)
Definition: exceptions.h:362
Stop iteration, goal reached.
Definition: solver.h:147
void push(const std::string &text)