7 #ifndef TBCI_SOLVER_CG_H 8 #define TBCI_SOLVER_CG_H 10 #include "tbci/basics.h" 11 #include "tbci/solver/precond.h" 44 template < typename T, typename SysMatrix, typename SysVector >
49 unsigned int dim = A.rows();
51 typename SysVector::value_type alpha, beta, rho, rho_1(0);
53 double normb =
b.fabs();
54 if (normb == 0.0) normb = 1.0;
else normb = 1.0 / normb;
59 if ((resid = r.fabs() * normb) <= tol)
67 for (
unsigned int i = 1;
i <= max_iter;
i++)
80 alpha = rho/
dot(
p,q);
85 if ((resid = r.fabs() * normb) <= tol)
111 template < typename T, typename SysMatrix, typename SysVector>
116 unsigned int dim = A.rows();
118 typename SysVector::value_type alpha, beta, rho, rho_1(0);
120 double normb =
b.fabs();
121 if (normb == 0.0) normb = 1;
else normb = 1 / normb;
123 SysVector r(
b - A*
x);
126 if ((resid = r.fabs() * normb) <= tol)
134 for (
unsigned int i = 1;
i <= max_iter;
i++)
152 if ((resid = r.fabs() * normb) <= tol)
Abstract base class for all Preconditioners.
const Vector< T > const Vector< T > const Vector< T > & p
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
NAMESPACE_TBCI Vector< T > class NN friend int CG(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &)
const Vector< T > const Vector< T > & x
T dot(const T &a1, const T &a2)
virtual TVector< T > solve(const Vector< T > &) const =0
Vector< T > class NN friend int CG2(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &)
NAMESPACE_TBCI INST3(template< typename T, Matrix< T >, Vector< T > > class NN friend int CG(const Matrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, Matrix< T > > &, unsigned int &, double &);) INST3(template< typename T