23 if (Base::initIteration(rhs,x))
28 m_precond->apply(tmp, residual);
29 beta = residual.norm();
31 m_error = beta/m_rhs_norm;
35 v.push_back(residual/beta);
48 H.resize(m_num_iter,m_num_iter);
49 H = H_prev.block(0,0,m_num_iter,m_num_iter);
50 g_tmp.resize(m_num_iter,1);
51 g_tmp = g.block(0,0,m_num_iter,1);
54 solveUpperTriangular(H, g_tmp);
58 for (
index_t k = 0; k< m_num_iter; ++k)
78 Omega_prev_tmp.clear();
92 H.block(0,0,k+1,k) = H_prev;
96 m_mat->apply(v[k],tmp);
97 m_precond->apply(tmp, w);
99 for (
index_t i = 0; i< k+1; ++i)
101 h_tmp(i,0) = (w.transpose()*v[i]).value();
102 w = w - h_tmp(i,0)*v[i];
104 h_tmp(k+1,0) = w.norm();
109 v.push_back(w/h_tmp(k+1,0));
111 h_tmp = Omega_prev*h_tmp;
112 H.block(0,k,k+2,1) = h_tmp;
115 T sk = H(k+1,k)/(math::sqrt(H(k,k)*H(k,k) + H(k+1,k)*H(k+1,k)));
116 T ck = H(k, k)/(math::sqrt(H(k,k)*H(k,k) + H(k+1,k)*H(k+1,k)));
117 Omega(k,k) = ck; Omega(k,k+1) = sk;
118 Omega(k+1,k) =-sk; Omega(k+1,k+1) = ck;
123 g_tmp.setZero(k+2,1);
125 g_tmp.block(0,0,k+1,1) = g;
128 g.noalias() = Omega * g_tmp;
130 T residualNorm2 = g(k+1,0)*g(k+1,0);
131 m_error = math::sqrt(residualNorm2) / m_rhs_norm;
136 Omega_prev_tmp.setZero(k+3,k+3);
137 Omega_prev_tmp.block(0,0,k+2,k+2) = Omega_prev;
138 Omega_prev_tmp(k+2,k+2) = 1;
140 Omega_tmp.setZero(k+3,k+3);
141 Omega_tmp.block(0,0,k+2,k+2) = Omega;
142 Omega_tmp(k+2,k+2) = 1;
144 Omega_prev = Omega_tmp*Omega_prev_tmp;
#define index_t
Definition: gsConfig.h:32
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsGMRes.hpp:83
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsGMRes.hpp:20
void finalizeIteration(VectorType &x)
Some post-processing might be required.
Definition: gsGMRes.hpp:45