22 template <
class Matrix,
class Vector,
class Preconditioner,
class Real >
24 CGS(
const Matrix &A, Vector &x,
const Vector &b,
25 const Preconditioner &M,
int &max_iter, Real &tol)
28 Vector rho_1(1), rho_2(1), alpha(1), beta(1);
29 Vector p, phat, q, qhat, vhat, u, uhat;
38 if ((resid =
norm(r) / normb) <= tol) {
44 for (
int i = 1; i <= max_iter; i++) {
45 rho_1(0) =
dot(rtilde, r);
47 tol =
norm(r) / normb;
54 beta(0) = rho_1(0) / rho_2(0);
56 p = u + beta(0) * (q + beta(0) * p);
60 alpha(0) = rho_1(0) /
dot(rtilde, vhat);
61 q = u - alpha(0) * vhat;
62 uhat = M.solve(u + q);
67 if ((resid =
norm(r) / normb) < tol) {
A::value_type dot(const A &a, const B &b)
Dot product of array or expression.
A::value_type norm(const A &a)
Euklidean norm of array or expression.
int CGS(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)