NeoPZ
cheby.h
Go to the documentation of this file.
1 
26 template < class Matrix, class Vector, class Preconditioner, class Real,
27 class Type >
28 int
29 CHEBY(const Matrix &A, Vector &x, const Vector &b,
30  const Preconditioner &M, int64_t &max_iter, Real &tol,
31  Type eigmin, Type eigmax)
32 {
33  Real resid;
34  Type alpha, beta, c, d;
35  Vector p, q, z;
36 
37  Real normb = norm(b);
38  Vector r = b - A * x;
39 
40  if (normb == 0.0)
41  normb = 1;
42 
43  if ((resid = norm(r) / normb) <= tol) {
44  tol = resid;
45  max_iter = 0;
46  return 0;
47  }
48 
49  c = (eigmax - eigmin) / 2.0;
50  d = (eigmax + eigmin) / 2.0;
51 
52  for (int64_t i = 1; i <= max_iter; i++) {
53  z = M.solve(r); // apply preconditioner
54 
55  if (i == 1) {
56  p = z;
57  alpha = 2.0 / d;
58  } else {
59  beta = c * alpha / 2.0; // calculate new beta
60  beta = beta * beta;
61  alpha = 1.0 / (d - beta); // calculate new alpha
62  p = z + beta * p; // update search direction
63  }
64 
65  q = A * p;
66  x += alpha * p; // update approximation vector
67  r -= alpha * q; // compute residual
68 
69  if ((resid = norm(r) / normb) <= tol) {
70  tol = resid;
71  max_iter = i;
72  return 0; // convergence
73  }
74  }
75 
76  tol = resid;
77  return 1; // no convergence
78 }
static const double tol
Definition: pzgeoprism.cpp:23
int CHEBY(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int64_t &max_iter, Real &tol, Type eigmin, Type eigmax)
CHEBY solves the symmetric positive definite linear system using the Preconditioned Chebyshev Method...
Definition: cheby.h:29
Definition: vectors.h:81