NeoPZ
ir.h
Go to the documentation of this file.
1 
23 template < class Matrix, class Vector, class Preconditioner, class Real >
24 int IR( Matrix &A, Vector &x,const Vector &b,
25  Preconditioner &M, Vector *residual, int64_t &max_iter, Real &tol,const int FromCurrent)
26 {
27  Real resid;
28  Vector z;
29 
30  Real normb = TPZExtractVal::val(Norm(b));
31  Vector resbackup;
32  Vector *res = residual;
33  if(!res) res = &resbackup;
34  Vector &r = *res;
35 
36  if(FromCurrent) A.MultAdd(x,b,r,-1.,1.);
37  else {
38  x.Zero();
39  r = b;
40  }
41 
42  if (normb == 0.0)
43  normb = 1;
44 
45  if ((resid = TPZExtractVal::val(Norm(r)) / normb) <= tol) {
46  tol = resid;
47  max_iter = 0;
48  return 0;
49  }
50 
51  for (int64_t i = 1; i <= max_iter; i++) {
52  M.Solve(r,z);
53  x += z;
54  A.MultAdd(x,b,r,-1.,1.);
55 
56  if ((resid = TPZExtractVal::val(Norm(r)) / normb) <= tol) {
57  tol = resid;
58  max_iter = i;
59  return 0;
60  }
61  }
62 
63  tol = resid;
64  return 1;
65 }
66 
67 
68 
static const double tol
Definition: pzgeoprism.cpp:23
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
string res
Definition: test.py:151
static REAL val(const int number)
Definition: pzextractval.h:21
int IR(Matrix &A, Vector &x, const Vector &b, Preconditioner &M, Vector *residual, int64_t &max_iter, Real &tol, const int FromCurrent)
IR solves the unsymmetric linear system Ax = b using Iterative Refinement (preconditioned Richardson ...
Definition: ir.h:24
Definition: vectors.h:81