11 #ifndef EIGEN_BICGSTAB_H
12 #define EIGEN_BICGSTAB_H
30 template<
typename MatrixType,
typename Rhs,
typename Dest,
typename Preconditioner>
32 const Preconditioner& precond,
Index& iters,
33 typename Dest::RealScalar& tol_error)
37 typedef typename Dest::RealScalar RealScalar;
38 typedef typename Dest::Scalar Scalar;
40 RealScalar tol = tol_error;
41 Index maxIters = iters;
44 VectorType r = rhs -
mat *
x;
47 RealScalar r0_sqnorm = r0.squaredNorm();
48 RealScalar rhs_sqnorm = rhs.squaredNorm();
58 VectorType
v = VectorType::Zero(
n),
p = VectorType::Zero(
n);
59 VectorType
y(
n), z(
n);
60 VectorType kt(
n), ks(
n);
62 VectorType s(
n), t(
n);
64 RealScalar tol2 = tol*tol*rhs_sqnorm;
69 while ( r.squaredNorm() > tol2 &&
i<maxIters )
74 if (
abs(rho) < eps2*r0_sqnorm)
80 rho = r0_sqnorm = r.squaredNorm();
84 Scalar beta = (rho/rho_old) * (alpha /
w);
85 p = r + beta * (
p -
w *
v);
89 v.noalias() =
mat *
y;
91 alpha = rho / r0.dot(
v);
95 t.noalias() =
mat * z;
97 RealScalar tmp = t.squaredNorm();
102 x += alpha *
y +
w * z;
106 tol_error =
sqrt(r.squaredNorm()/rhs_sqnorm);
113 template<
typename MatrixType_,
114 typename Preconditioner_ = DiagonalPreconditioner<typename MatrixType_::Scalar> >
119 template<
typename MatrixType_,
typename Preconditioner_>
120 struct traits<BiCGSTAB<MatrixType_,Preconditioner_> >
123 typedef Preconditioner_ Preconditioner;
159 template<
typename MatrixType_,
typename Preconditioner_>
170 typedef typename MatrixType::Scalar
Scalar;
189 template<
typename MatrixDerived>
195 template<
typename Rhs,
typename Dest>
const AbsReturnType abs() const
const SqrtReturnType sqrt() const
Array< int, Dynamic, 1 > v
Matrix< float, 1, Dynamic > MatrixType
A bi conjugate gradient stabilized solver for sparse square problems.
BiCGSTAB(const EigenBase< MatrixDerived > &A)
MatrixType::Scalar Scalar
void _solve_vector_with_guess_impl(const Rhs &b, Dest &x) const
IterativeSolverBase< BiCGSTAB > Base
Preconditioner_ Preconditioner
MatrixType::RealScalar RealScalar
const ActualMatrixType & matrix() const
Base class for linear iterative solvers.
Index maxIterations() const
Preconditioner m_preconditioner
BiCGSTAB< MatrixType_, Preconditioner_ > & derived()
const ActualMatrixType & matrix() const
bool bicgstab(const MatrixType &mat, const Rhs &rhs, Dest &x, const Preconditioner &precond, Index &iters, typename Dest::RealScalar &tol_error)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.