00001
00004
00005
00006 #ifndef TBCI_SOLVER_IR_H
00007 #define TBCI_SOLVER_IR_H
00008
00009 #include "../basics.h"
00010
00011 NAMESPACE_TBCI
00012
00031 INST3(template <typename T, Matrix<T>, Vector<T> > class NN friend \
00032 int IR (const Matrix<T>&, Vector<T>&, const Vector<T>&,\
00033 const Preconditioner_Sig<T, Matrix<T> >&, unsigned int&, double&);)
00034 INST3(template <typename T, BdMatrix<T>, Vector<T> > class NN friend \
00035 int IR (const BdMatrix<T>&, Vector<T>&, const Vector<T>&,\
00036 const Preconditioner_Sig<T, BdMatrix<T> >&, unsigned int&, double&);)
00037
00038
00039
00040 template < typename T, typename SysMatrix, typename SysVector >
00041 int IR (const SysMatrix &A, SysVector &x, const SysVector &b,
00042 const Preconditioner_Sig<T, SysMatrix> &M, unsigned int &max_iter, double &tol)
00043 {
00044 double resid;
00045 unsigned int dim = A.rows();
00046 SysVector z(dim);
00047
00048 double normb = b.fabs();
00049 if (normb == 0.0) normb = 1.0;
00050 SysVector r(b - A*x);
00051
00052
00053 if ((resid = r.fabs() / normb) <= tol)
00054 {
00055 tol = resid;
00056 max_iter = 0;
00057 return 0;
00058 }
00059
00060 for (unsigned int i = 1; i <= max_iter; i++)
00061 {
00062 z = M.solve(r);
00063 x += z;
00064 r = b - A * x;
00065 if ((resid = r.fabs() / normb) <= tol)
00066 {
00067 tol = resid;
00068 max_iter = i;
00069 return 0;
00070 }
00071 }
00072
00073 tol = resid;
00074 return 1;
00075 }
00076
00077 NAMESPACE_END
00078
00079 #endif