11 #ifndef EIGEN_BICGSTAB_H 12 #define EIGEN_BICGSTAB_H 28 template<
typename MatrixType,
typename Rhs,
typename Dest,
typename Preconditioner>
30 const Preconditioner& precond,
int& iters,
31 typename Dest::RealScalar& tol_error)
35 typedef typename Dest::RealScalar RealScalar;
36 typedef typename Dest::Scalar Scalar;
38 RealScalar tol = tol_error;
43 VectorType r = rhs - mat * x;
46 RealScalar r0_sqnorm = r0.squaredNorm();
47 RealScalar rhs_sqnorm = rhs.squaredNorm();
57 VectorType
v = VectorType::Zero(n), p = VectorType::Zero(n);
58 VectorType
y(n), z(n);
59 VectorType kt(n), ks(n);
61 VectorType s(n), t(n);
63 RealScalar tol2 = tol*tol;
67 while ( r.squaredNorm()/rhs_sqnorm > tol2 && i<maxIters )
77 rho = r0_sqnorm = r.squaredNorm();
81 Scalar beta = (rho/rho_old) * (alpha / w);
82 p = r + beta * (p - w *
v);
86 v.noalias() = mat *
y;
88 alpha = rho / r0.dot(v);
92 t.noalias() = mat * z;
94 RealScalar tmp = t.squaredNorm();
99 x += alpha * y + w * z;
103 tol_error =
sqrt(r.squaredNorm()/rhs_sqnorm);
110 template<
typename _MatrixType,
116 template<
typename _MatrixType,
typename _Preconditioner>
171 template<
typename _MatrixType,
typename _Preconditioner>
175 using Base::mp_matrix;
177 using Base::m_iterations;
179 using Base::m_isInitialized;
182 typedef typename MatrixType::Scalar
Scalar;
183 typedef typename MatrixType::Index
Index;
211 template<
typename Rhs,
typename Guess>
215 eigen_assert(m_isInitialized &&
"BiCGSTAB is not initialized.");
217 &&
"BiCGSTAB::solve(): invalid number of rows of the right hand side matrix b");
219 <
BiCGSTAB, Rhs, Guess>(*
this, b.derived(), x0);
223 template<
typename Rhs,
typename Dest>
227 for(
int j=0; j<b.cols(); ++j)
229 m_iterations = Base::maxIterations();
230 m_error = Base::m_tolerance;
233 if(!
internal::bicgstab(*mp_matrix, b.col(j), xj, Base::m_preconditioner, m_iterations, m_error))
237 : m_error <= Base::m_tolerance ?
Success 239 m_isInitialized =
true;
243 template<
typename Rhs,
typename Dest>
248 _solveWithGuess(b,x);
258 template<
typename _MatrixType,
typename _Preconditioner,
typename Rhs>
265 template<typename Dest>
void evalTo(Dest& dst)
const 267 dec()._solve(
rhs(),dst);
275 #endif // EIGEN_BICGSTAB_H A preconditioner based on the digonal entries.
void _solve(const Rhs &b, Dest &x) const
IntermediateState sqrt(const Expression &arg)
BiCGSTAB< _MatrixType, _Preconditioner > Dec
BiCGSTAB(const MatrixType &A)
_Preconditioner Preconditioner
iterative scaling algorithm to equilibrate rows and column norms in matrices
Block< Derived, internal::traits< Derived >::RowsAtCompileTime, 1,!IsRowMajor > ColXpr
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
void _solveWithGuess(const Rhs &b, Dest &x) const
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
const internal::solve_retval_with_guess< BiCGSTAB, Rhs, Guess > solveWithGuess(const MatrixBase< Rhs > &b, const Guess &x0) const
_Preconditioner Preconditioner
void rhs(const real_t *x, real_t *f)
MatrixType::RealScalar RealScalar
bool bicgstab(const MatrixType &mat, const Rhs &rhs, Dest &x, const Preconditioner &precond, int &iters, typename Dest::RealScalar &tol_error)
#define EIGEN_MAKE_SOLVE_HELPERS(DecompositionType, Rhs)
A bi conjugate gradient stabilized solver for sparse square problems.
MatrixType::Scalar Scalar
IterativeSolverBase< BiCGSTAB > Base
EIGEN_STRONG_INLINE Index cols() const
Base class for linear iterative solvers.
Base class for all dense matrices, vectors, and expressions.