27 m_delta.reserve(m_max_iters / 3);
30 m_gamma.reserve(m_max_iters / 3);
33 if (Base::initIteration(rhs,x))
41 m_mat->apply(x,m_tmp);
44 m_error = m_res.norm() / m_rhs_norm;
48 m_precond->apply(m_res,m_update);
49 m_abs_new = m_res.col(0).dot(m_update.col(0));
57 m_mat->apply(m_update,m_tmp);
59 T alpha = m_abs_new / m_update.col(0).dot(m_tmp.col(0));
61 m_delta.back()+=(1./alpha);
63 x += alpha * m_update;
64 m_res -= alpha * m_tmp;
66 m_error = m_res.norm() / m_rhs_norm;
70 m_precond->apply(m_res, m_tmp);
72 T abs_old = m_abs_new;
74 m_abs_new = m_res.col(0).dot(m_tmp.col(0));
75 T beta = m_abs_new / abs_old;
76 m_update = m_tmp + beta * m_update;
80 m_gamma.push_back(-math::sqrt(beta)/alpha);
81 m_delta.push_back(beta/alpha);
89 if ( m_delta.empty() )
91 gsWarn<<
"Condition number needs eigenvalues set setCalcEigenvalues(true)"
92 " and call solve with an arbitrary right hand side";
104 T tmp_original = m_delta.back();
105 m_mat->apply(m_update,m_tmp);
106 T alpha = m_abs_new / m_update.col(0).dot(m_tmp.col(0));
107 m_delta.back()+=(1./alpha);
110 m_delta.back() = tmp_original;
118 if ( m_delta.empty() )
120 gsWarn<<
"Eigenvalues were not computed, set setCalcEigenvalues(true)"
121 " and call solve with an arbitrary right hand side";
130 eigs = eigensolver.eigenvalues();
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsConjugateGradient.hpp:55
Class for representing a Lanczos matrix and calculating its eigenvalues.
Definition: gsLanczosMatrix.h:27
Class for representing a Lanczos matrix and calculating its eigenvalues.
#define index_t
Definition: gsConfig.h:32
T getConditionNumber()
returns the condition number of the (preconditioned) system matrix
Definition: gsConjugateGradient.hpp:87
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsConjugateGradient.hpp:20
#define gsWarn
Definition: gsDebug.h:50
void getEigenvalues(VectorType &eigs)
returns the eigenvalues of the Lanczos matrix
Definition: gsConjugateGradient.hpp:116
T minEigenvalue(index_t maxIter=20, T tol=1.e-6)
Calculates the smallest eigenvalue.
Definition: gsLanczosMatrix.h:76
gsSparseMatrix< T > matrix()
This function returns the Lanczos matrix as gsSparseMatrix.
Definition: gsLanczosMatrix.h:88
T maxEigenvalue(index_t maxIter=20, T tol=1.e-6)
Calculates the largest eigenvalue.
Definition: gsLanczosMatrix.h:50