G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsBiCgStab.hpp
Go to the documentation of this file.
1 
14 namespace gismo
15 {
16 
17 template<class T>
19  typename gsBiCgStab<T>::VectorType& x )
20 {
21  if (Base::initIteration(rhs,x))
22  return true;
23 
24  // m_res = rhs - A * x;
25  m_mat->apply(x,m_tmp);
26  m_res = rhs - m_tmp;
27 
28  m_r0 = m_res;
29 
30  m_p.setZero(m_mat->cols(), 1);
31  m_v.setZero(m_mat->cols(), 1);
32 
33  m_alpha = 1;
34  m_rho = 1;
35  m_w = 1;
36 
37  m_error = m_res.norm() / m_rhs_norm;
38 
39  return m_error < m_tol;
40 
41 }
42 
43 template<class T>
45 {
46  T rho_old = m_rho;
47  m_rho = m_r0.col(0).dot(m_res.col(0));
48 
49  if (math::abs(m_rho) < m_restartThereshold * m_r0.col(0).dot(m_r0.col(0)) )
50  {
51  gsInfo << "Residual almost orthogonal, restart with new r0 \n";
52  m_r0 = m_res;
53  m_rho = m_r0.col(0).dot(m_r0.col(0)); //= r0_sqnorm
54  }
55 
56  T beta = (m_rho/rho_old)*(m_alpha/m_w);
57  m_p = m_res + beta*(m_p - m_w * m_v);
58 
59  // Apply preconditioning by solving Ahat m_y = m_p
60  m_precond->apply(m_p, m_y);
61  // m_v = A * m_y;
62  m_mat->apply(m_y, m_v);
63  m_alpha = m_rho/(m_r0.col(0).dot(m_v.col(0)));
64 
65  m_s.noalias() = m_res - m_alpha * m_v;
66  // Apply preconditioning by solving Ahat m_z = m_s
67  m_precond->apply(m_s, m_z);
68 
69  // m_t = A * m_z;
70  m_mat->apply(m_z, m_t);
71 
72  if (m_t.col(0).dot(m_t.col(0)) > 0)
73  m_w = m_t.col(0).dot(m_s.col(0))/m_t.col(0).dot(m_t.col(0));
74  else
75  m_w = 0;
76 
77  // Update iterate and residual
78  x.noalias() += m_alpha * m_y + m_w * m_z;
79  m_res.noalias() -= m_alpha * m_v + m_w * m_t;
80 
81  m_error = m_res.norm() / m_rhs_norm;
82  return m_error < m_tol;
83 
84 }
85 
86 } // end namespace gismo
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsBiCgStab.hpp:44
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsBiCgStab.hpp:18
#define gsInfo
Definition: gsDebug.h:43
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4488