71 #ifndef GMM_SOLVER_CG_H__
72 #define GMM_SOLVER_CG_H__
84 template <
typename Matrix,
typename Matps,
typename Precond,
85 typename Vector1,
typename Vector2>
86 void cg(
const Matrix& A, Vector1& x,
const Vector2& b,
const Matps& PS,
87 const Precond &P, iteration &iter) {
89 typedef typename temporary_dense_vector<Vector1>::vector_type temp_vector;
90 typedef typename linalg_traits<Vector1>::value_type T;
93 temp_vector p(vect_size(x)), q(vect_size(x)), r(vect_size(x)),
95 iter.set_rhsnorm(gmm::sqrt(gmm::abs(
vect_hp(PS, b, b))));
97 if (iter.get_rhsnorm() == 0.0)
100 mult(A, scaled(x, T(-1)), b, r);
105 while (!iter.finished_vect(r)) {
110 add(z, scaled(p, rho / rho_1), p);
115 add(scaled(p, a), x);
116 add(scaled(q, -a), r);
124 template <
typename Matrix,
typename Matps,
typename Precond,
125 typename Vector1,
typename Vector2>
126 void cg(
const Matrix& A, Vector1& x,
const Vector2& b,
const Matps& PS,
127 const gmm::identity_matrix &, iteration &iter) {
129 typedef typename temporary_dense_vector<Vector1>::vector_type temp_vector;
130 typedef typename linalg_traits<Vector1>::value_type T;
133 temp_vector p(vect_size(x)), q(vect_size(x)), r(vect_size(x));
134 iter.set_rhsnorm(gmm::sqrt(gmm::abs(
vect_hp(PS, b, b))));
136 if (iter.get_rhsnorm() == 0.0)
139 mult(A, scaled(x, T(-1)), b, r);
143 while (!iter.finished_vect(r)) {
147 add(r, scaled(p, rho / rho_1), p);
151 add(scaled(p, a), x);
152 add(scaled(q, -a), r);
159 template <
typename Matrix,
typename Matps,
typename Precond,
160 typename Vector1,
typename Vector2>
inline
161 void cg(
const Matrix& A,
const Vector1& x,
const Vector2& b,
const Matps& PS,
162 const Precond &P, iteration &iter)
163 { cg(A, linalg_const_cast(x), b, PS, P, iter); }
165 template <
typename Matrix,
typename Precond,
166 typename Vector1,
typename Vector2>
inline
167 void cg(
const Matrix& A, Vector1& x,
const Vector2& b,
168 const Precond &P, iteration &iter)
169 { cg(A, x , b, identity_matrix(), P, iter); }
171 template <
typename Matrix,
typename Precond,
172 typename Vector1,
typename Vector2>
inline
173 void cg(
const Matrix& A,
const Vector1& x,
const Vector2& b,
174 const Precond &P, iteration &iter)
175 { cg(A, x , b , identity_matrix(), P , iter); }
void copy(const L1 &l1, L2 &l2)
*/
strongest_value_type< V1, V2 >::value_type vect_hp(const V1 &v1, const V2 &v2)
*/
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
void add(const L1 &l1, L2 &l2)
*/
Include the base gmm files.