7#ifndef TBCI_SOLVER_GMRES_H
8#define TBCI_SOLVER_GMRES_H
10#include "tbci/basics.h"
21template < typename SysMatrix, typename SysVector >
27 for (
int i = k;
i >= 0; --
i) {
29 for (
int j =
i - 1; j >= 0; --j)
30 y(j) -=
h(j,
i) *
y(
i);
33 for (
int j = 0; j <= k; ++j)
49INST(template <typename T>
class NN
friend \
50 void GeneratePlaneRotation(
const T &,
const double &,
double &,
T &);)
53inline void GeneratePlaneRotation(
const T &dx,
const double &
dy,
double &
cs,
T &sn)
65 const double ynorm = 1.0 /
MATH__ sqrt (1.0 + rel);
79INST(template <typename T>
class NN
friend \
80 void ApplyPlaneRotation(
T &,
T &,
const double &,
const T &);)
83inline void ApplyPlaneRotation(
T &dx,
T &
dy,
const double &
cs,
const T &sn)
139template < typename T, typename SysMatrix, typename SysVector >
140int GMRES (
const SysMatrix &A, SysVector &
x,
const SysVector &
b,
142 unsigned int &max_iter,
double &tol)
144 const unsigned int dim = A.rows();
146 m = dim/8+max_iter/4;
147 if ((
unsigned)m > max_iter)
149 SysVector s(m+1), sn(m+1), w(dim), r(dim);
160 const double rel_tol = tol*normb;
162 double beta = r.fabs();
164 if (beta <= rel_tol) {
175 SysVector *V =
new SysVector[m+1];
176 for (j = 0; j <= (unsigned)m; ++j)
180 while (j <= max_iter) {
183 s.fill ((
T)0.0); s(0) = (
T) beta;
186 for (
int i = 0; (
i < m) && (j <= max_iter); ++
i, ++j) {
191 for (k = 0; k <=
i; k++) {
192 H(k,
i) =
dot (V[k], w);
199 const REGISTER double normw = w.fabs();
212 for (k = 0; k <
i; k++)
213 ApplyPlaneRotation(H(k,
i), H(k+1,
i),
cs(k), sn(k));
215 GeneratePlaneRotation(H(
i,
i), normw,
cs(
i), sn(
i));
216 ApplyPlaneRotation(H(
i,
i), H(
i+1,
i),
cs(
i), sn(
i));
217 ApplyPlaneRotation(s(
i), s(
i+1),
cs(
i), sn(
i));
227 if (beta <= rel_tol) {
const Vector< T > const Vector< T > & x
const Vector< T > const Vector< T > const Vector< T > int T h
const Vector< T > const Vector< T > const Vector< T > int T T & err
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
Abstract base class for all Preconditioners.
virtual TVector< T > solve(const Vector< T > &) const =0
double fabs(const TBCI__ cplx< T > &c)
cplx< T > dot(const cplx< T > &a, const cplx< T > &b)
double fabssqr(const cplx< T > &c)
NAMESPACE_END NAMESPACE_CPLX TBCI__ cplx< T > conj(const TBCI__ cplx< T > &c)
NAMESPACE_END NAMESPACE_CSTD TBCI__ cplx< T > sqrt(const TBCI__ cplx< T > &z)
NAMESPACE_TBCI Vector< T > class NN friend void Update(Vector< T > &, int, BdMatrix< T > &, Vector< T > &, Vector< T > *)