71 #ifndef GMM_SOLVER_BICGSTAB_H__
72 #define GMM_SOLVER_BICGSTAB_H__
84 template <
typename Matrix,
typename Vector,
typename VectorB,
85 typename Preconditioner>
86 void bicgstab(
const Matrix& A, Vector& x,
const VectorB& b,
87 const Preconditioner& M, iteration &iter) {
89 typedef typename linalg_traits<Vector>::value_type T;
90 typedef typename number_traits<T>::magnitude_type R;
91 typedef typename temporary_dense_vector<Vector>::vector_type temp_vector;
93 T rho_1, rho_2(0),
alpha(0), beta, omega(0);
94 temp_vector p(vect_size(x)), phat(vect_size(x)), s(vect_size(x)),
96 t(vect_size(x)), v(vect_size(x)), r(vect_size(x)), rtilde(vect_size(x));
98 gmm::mult(A, gmm::scaled(x, -T(1)), b, r);
101 iter.set_rhsnorm(gmm::vect_norm2(b));
103 if (iter.get_rhsnorm() == 0.0) {
clear(x);
return; }
105 while (!iter.finished(norm_r)) {
110 { GMM_ASSERT1(
false,
"Bicgstab failed to converge"); }
111 else { GMM_WARNING1(
"Bicgstab failed to converge");
return; }
119 { GMM_ASSERT1(
false,
"Bicgstab failed to converge"); }
120 else { GMM_WARNING1(
"Bicgstab failed to converge");
return; }
123 beta = (rho_1 / rho_2) * (alpha / omega);
125 gmm::add(gmm::scaled(v, -omega), p);
126 gmm::add(r, gmm::scaled(p, beta), p);
131 gmm::add(r, gmm::scaled(v, -alpha), s);
133 if (iter.finished_vect(s))
134 {
gmm::add(gmm::scaled(phat, alpha), x);
break; }
140 gmm::add(gmm::scaled(phat, alpha), x);
141 gmm::add(gmm::scaled(shat, omega), x);
142 gmm::add(s, gmm::scaled(t, -omega), r);
150 template <
typename Matrix,
typename Vector,
typename VectorB,
151 typename Preconditioner>
152 void bicgstab(
const Matrix& A,
const Vector& x,
const VectorB& b,
153 const Preconditioner& M, iteration &iter)
154 { bicgstab(A, linalg_const_cast(x), b, M, iter); }
void copy(const L1 &l1, L2 &l2)
*/
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2_sqr(const V &v)
squared Euclidean norm of a vector.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
strongest_value_type< V1, V2 >::value_type vect_sp(const V1 &v1, const V2 &v2)
*/
void add(const L1 &l1, L2 &l2)
*/
Include the base gmm files.
size_t size_type
used as the common size type in the library
size_type alpha(short_type n, short_type d)
Return the value of which is the number of monomials of a polynomial of variables and degree .