21 #ifndef SELDON_FILE_ITERATIVE_GCR_CXX
45 #ifdef SELDON_WITH_VIRTUAL
46 template<
class T,
class Vector1>
47 int Gcr(
const VirtualMatrix<T>& A, Vector1& x,
const Vector1& b,
48 Preconditioner_Base<T>& M,
49 Iteration<
typename ClassComplexType<T>::Treal>& outer)
51 template <
class Titer,
class Matrix1,
class Vector1,
class Preconditioner>
52 int Gcr(
const Matrix1& A, Vector1& x,
const Vector1& b,
56 const int N = A.GetM();
60 typedef typename Vector1::value_type Complexe;
63 int success_init = outer.
Init(b);
64 if (success_init != 0)
67 std::vector<Vector1> p(m+1, b), w(m+1, b);
71 Vector1 r(b), q(b), u(b);
76 for (
int i = 0; i < (m+1); i++)
85 outer.
MltAdd(-one, A, x, one, u);
91 Complexe alpha, delta;
93 typedef typename ClassComplexType<Complexe>::Treal Treal;
94 Treal normr =
Norm2(r);
104 Mlt(Treal(1)/normr, p[0]);
111 outer.
Mlt(A, p[j], u);
116 beta(j) = DotProdConj(w[j], w[j]);
119 outer.
Fail(1,
"Gcr breakdown #1");
125 alpha = DotProdConj(w[j], r) / beta(j);
127 Add(-alpha, w[j], r);
138 for (
int i = 0; i <= j; i++)
140 delta = -DotProdConj(w[i], q)/beta(i);
141 Add(delta, p[i], p[j+1]);
156 #define SELDON_FILE_ITERATIVE_GCR_CXX
int GetNumberIteration() const
Returns the number of iterations.
int GetRestart() const
Returns the restart parameter.
ClassComplexType< T >::Treal Norm2(const VectorExpression< T, E > &X)
returns 2-norm of an expression with vectors
void SetMaxNumberIteration(int max_iteration)
Changes the maximum number of iterations.
int Init(const Vector1 &r)
Initialization with the right hand side.
void Mlt(const Matrix1 &A, const Vector1 &x, Vector1 &y)
Computes y = A x.
int ErrorCode()
Returns the error code (if an error occured)
void Fail(int i, const string &s)
Informs of a failure in the iterative solver.
void MltAdd(const T1 &alpha, const Matrix1 &A, const Vector1 &x, const T1 &beta, Vector1 &y)
Computes y = beta y + alpha A x.
void SetNumberIteration(int nb)
Changes the number of iterations.
Class containing parameters for an iterative resolution.
bool IsInitGuess_Null() const
Returns true if the initial guess is null.
int Gcr(const Matrix1 &A, Vector1 &x, const Vector1 &b, Preconditioner &M, Iteration< Titer > &outer)
Solves a linear system by using Generalized Conjugate Residual (GCR)
bool Finished(const Vector1 &r) const
Returns true if the iterative solver has reached its end.