29 template <
class Matrix,
class Vector,
class Preconditioner,
class Real >
32 Preconditioner &M,
Vector *residual, int64_t &max_iter, Real &
tol,
const int FromCurrent)
36 REAL alpha, beta, rho, rho_1 = 0;
43 std::list< TPZFMatrix<REAL> > plist,qlist;
44 std::list< TPZFMatrix<REAL> >::iterator jt;
45 std::list< TPZFMatrix<REAL> >::iterator kt;
49 if(!res) res = &resbackup;
54 A.MultAdd(x,b,r,-1.,1.);
70 for (i = 1; i <= max_iter; i++) {
78 p.TimesBetaPlusZ(beta,z);
97 REAL energy =
Dot(x,Au)/2.-
Dot(x,b);
104 std::cout <<
"cg iter = " << i <<
" res = " << resid << std::endl;
109 std::cout <<
"cg iter = " << i <<
" res = " << resid << std::endl;
112 std::cout <<
" energy " << energy << std::endl;
116 for(j=0, jt = plist.begin(); jt != plist.end(); jt++,j++)
118 for(k=0, kt = qlist.begin(); kt != qlist.end(); kt++,k++)
120 inner(j,k) =
Dot((*jt),(*kt));
124 inner.
Print(
"Inner product of search directions");
130 std::cout <<
"cg iter = " << i <<
" res = " << resid << std::endl;
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Implement dot product for matrices.
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
int CG(Matrix &A, Vector &x, const Vector &b, Preconditioner &M, Vector *residual, int64_t &max_iter, Real &tol, const int FromCurrent)
CG solves the symmetric positive definite linear system using the Conjugate Gradient method...
virtual void Print(std::ostream &out) const