TBCI Numerical high perf. C++ Library 2.8.0
ir.h
Go to the documentation of this file.
1
4// $Id: ir.h,v 1.7.2.3 2019/05/28 11:13:02 garloff Exp $
5
6#ifndef TBCI_SOLVER_IR_H
7#define TBCI_SOLVER_IR_H
8
9#include "tbci/basics.h"
10
12
30
31INST3(template <typename T, Matrix<T>, Vector<T> > class NN friend \
32int IR (const Matrix<T>&, Vector<T>&, const Vector<T>&,\
33 const Preconditioner_Sig<T, Matrix<T> >&, unsigned int&, double&);)
34INST3(template <typename T, BdMatrix<T>, Vector<T> > class NN friend \
35int IR (const BdMatrix<T>&, Vector<T>&, const Vector<T>&,\
36 const Preconditioner_Sig<T, BdMatrix<T> >&, unsigned int&, double&);)
37
38
39//Aenderung Marco:
40template < typename T, typename SysMatrix, typename SysVector >
41int IR (const SysMatrix &A, SysVector &x, const SysVector &b,
42 const Preconditioner_Sig<T, SysMatrix> &M, unsigned int &max_iter, double &tol)
43{
44 double resid;
45 unsigned int dim = A.rows();
46 SysVector z(dim);
47
48 double normb = b.fabs();
49 if (normb == 0.0) normb = 1.0;
50 SysVector r(b - A*x);
51
52
53 if ((resid = r.fabs() / normb) <= tol)
54 {
55 tol = resid;
56 max_iter = 0;
57 return 0;
58 }
59
60 for (unsigned int i = 1; i <= max_iter; i++)
61 {
62 z = M.solve(r);
63 x += z;
64 r = b - A * x;
65 if ((resid = r.fabs() / normb) <= tol)
66 {
67 tol = resid;
68 max_iter = i;
69 return 0;
70 }
71 }
72
73 tol = resid;
74 return 1;
75}
76
78
79#endif
const Vector< T > const Vector< T > & x
Definition LM_fit.h:97
int i
Definition LM_fit.h:71
#define INST3(x, y, z)
Definition basics.h:240
#define NAMESPACE_END
Definition basics.h:323
#define NAMESPACE_TBCI
Definition basics.h:317
#define T
Definition bdmatlib.cc:20
SysMatrix
Definition bicgstab.h:90
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
Abstract base class for all Preconditioners.
Definition precond.h:41
virtual TVector< T > solve(const Vector< T > &) const =0
F_TMatrix< T > b
Definition f_matrix.h:736
NAMESPACE_TBCI Vector< T > class NN friend int IR(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &)