6 #ifndef TBCI_SOLVER_CGS_H
7 #define TBCI_SOLVER_CGS_H
9 #include "tbci/basics.h"
69 template < typename T, typename SysMatrix, typename SysVector >
72 double &tol,
const unsigned off = 0)
74 const unsigned int dim = A.rows();
75 SysVector
p(dim), phat(dim), q(dim), qhat(dim), vhat(dim), u(dim), uhat(dim);
76 typename SysVector::value_type rho_1, rho_2((
typename SysVector::value_type)1), alpha, beta;
80 double normbsqr = b.fabssqr();
84 normbsqr = 1.0 / normbsqr;
90 if ((residsqr = r.fabssqr() * normbsqr) <= tolsqr)
98 if (off) cnvg.open (
"cgs_cnvg.gnu",
STD__ ios::app);
99 else cnvg.open (
"cgs_cnvg.gnu");
102 for (
unsigned int i = 1;
i <= max_iter;
i++)
105 cnvg <<
i+off <<
"\t" <<
MATH__ sqrt(residsqr) <<
"\n";
107 rho_1 =
dot(rtilde, r);
108 if (rho_1 == (
typename SysVector::value_type)0)
119 beta = rho_1 / rho_2;
121 p = u + beta * (q + beta *
p);
125 alpha = rho_1 /
dot(rtilde, vhat);
126 q = u - alpha * vhat;
127 uhat = M.
solve(u + q);
132 if ((residsqr = r.fabssqr() * normbsqr) < tolsqr)
137 cnvg <<
i+off <<
"\t" <<
MATH__ sqrt(residsqr) <<
STD__ endl; cnvg.close ();
const Vector< T > const Vector< T > & x
Abstract base class for all Preconditioners.
NAMESPACE_TBCI Vector< T > class NN friend int CGS(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &, const unsigned)
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...
Matrix class with optimized Matrix-Vector multiplication for symmetrical Matrices.
cplx< T > sqr(const cplx< T > &c)
T dot(const T &a1, const T &a2)
virtual TVector< T > solve(const Vector< T > &) const =0