20 template <
class Matrix,
class Vector >
27 for (int64_t i = k; i >= 0; i--) {
29 for (int64_t j = i - 1; j >= 0; j--)
30 y(j) -=
h(j,i) * y(i);
33 for (int64_t j = 0; j <= k; j++)
41 template <
class Real >
45 return (x > ((Real)0.) ? x : -x);
68 template <
class Operator,
class Vector,
class Preconditioner,
69 class Matrix,
class Real >
72 Preconditioner &M, Matrix &H,
int &
m, int64_t &max_iter,
73 Real &
tol,
Vector *residual,
const int FromCurrent)
77 Vector s(m+1), cs(m+1), sn(m+1), w1,w;
82 if(!res) res = &resbackup;
88 A.MultAdd(x,b,r,-1.,1.);
111 while (j <= max_iter) {
112 int64_t rows = r.Rows();
114 for (int64_t i=0; i<rows; i++) {
117 int64_t srows = s.Rows();
118 for (int64_t i=0; i<srows; i++) {
125 for (int64_t i = 0; i < m && j <= max_iter; i++, j++) {
128 for (k = 0; k <= i; k++) {
129 H(k, i) =
Dot(w, v[k]);
130 w.ZAXPY(-H(k, i), v[k]);
136 for (k = 0; k < i; k++)
142 resid = ((Real)
fabs(s(i+1)))/normb;
151 Update(x, m - 1, H, s, v);
152 A.MultAdd(x,b,r,-1.,1.);
157 std::cout <<
"iter " << j <<
" - " << resid << std::endl;
178 if (dy == ((Real)0.0)) {
181 }
else if (
abs(dy) >
abs(dx)) {
183 sn = ((Real)1.0) /
sqrt( ((Real)1.0) + temp*temp );
187 cs = ((Real)1.0) /
sqrt( ((Real)1.0) + temp*temp );
197 Real temp = cs * dx + sn * dy;
198 dy = -sn * dx + cs * dy;
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
int GMRES(Operator &A, Vector &x, const Vector &b, Preconditioner &M, Matrix &H, int &m, int64_t &max_iter, Real &tol, Vector *residual, const int FromCurrent)
GMRES solves the unsymmetric linear system Ax = b using the Generalized Minimum Residual method...
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Implement dot product for matrices.
clarg::argBool h("-h", "help message", false)
void Update(Vector &x, int64_t k, Matrix &h, Vector &s, Vector v[])
Computes back solve. Updates on v vector.
expr_ dx(i) *cos(expr_.val())
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
void GeneratePlaneRotation(Real &dx, Real &dy, Real &cs, Real &sn)
Compute the values cs and sn parameters to rotation.
void ApplyPlaneRotation(Real &dx, Real &dy, Real &cs, Real &sn)
Makes rotation of the plane based on the cs and sn parameters.
Real abs(Real x)
Returns absolute value to real.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")