11 #ifndef EIGEN_BICGSTAB_H
12 #define EIGEN_BICGSTAB_H
28 template<
typename MatrixType,
typename Rhs,
typename Dest,
typename Preconditioner>
29 bool bicgstab(
const MatrixType& mat,
const Rhs& rhs, Dest& x,
30 const Preconditioner& precond,
Index& iters,
31 typename Dest::RealScalar& tol_error)
35 typedef typename Dest::RealScalar RealScalar;
36 typedef typename Dest::Scalar Scalar;
38 RealScalar tol = tol_error;
39 Index maxIters = iters;
42 VectorType r = rhs - mat * x;
45 RealScalar r0_sqnorm = r0.squaredNorm();
46 RealScalar rhs_sqnorm = rhs.squaredNorm();
56 VectorType v = VectorType::Zero(n), p = VectorType::Zero(n);
57 VectorType
y(n), z(n);
58 VectorType kt(n), ks(n);
60 VectorType s(n), t(n);
62 RealScalar tol2 = tol*tol*rhs_sqnorm;
67 while ( r.squaredNorm() > tol2 && i<maxIters )
72 if (
abs(rho) < eps2*r0_sqnorm)
78 rho = r0_sqnorm = r.squaredNorm();
82 Scalar beta = (rho/rho_old) * (alpha / w);
83 p = r + beta * (p - w * v);
87 v.noalias() = mat *
y;
89 alpha = rho / r0.dot(v);
93 t.noalias() = mat * z;
95 RealScalar tmp = t.squaredNorm();
100 x += alpha *
y + w * z;
104 tol_error =
sqrt(r.squaredNorm()/rhs_sqnorm);
111 template<
typename _MatrixType,
112 typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> >
117 template<
typename _MatrixType,
typename _Preconditioner>
157 template<
typename _MatrixType,
typename _Preconditioner>
168 typedef typename MatrixType::Scalar
Scalar;
187 template<
typename MatrixDerived>
193 template<
typename Rhs,
typename Dest>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
Definition: ArrayCwiseUnaryOps.h:52
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: ArrayCwiseUnaryOps.h:187
A bi conjugate gradient stabilized solver for sparse square problems.
Definition: BiCGSTAB.h:159
MatrixType::RealScalar RealScalar
Definition: BiCGSTAB.h:169
ComputationInfo m_info
Definition: IterativeSolverBase.h:438
_MatrixType MatrixType
Definition: BiCGSTAB.h:167
BiCGSTAB(const EigenBase< MatrixDerived > &A)
Definition: BiCGSTAB.h:188
IterativeSolverBase< BiCGSTAB > Base
Definition: BiCGSTAB.h:160
RealScalar m_error
Definition: IterativeSolverBase.h:436
Index m_iterations
Definition: IterativeSolverBase.h:437
~BiCGSTAB()
Definition: BiCGSTAB.h:190
MatrixType::Scalar Scalar
Definition: BiCGSTAB.h:168
void _solve_vector_with_guess_impl(const Rhs &b, Dest &x) const
Definition: BiCGSTAB.h:194
BiCGSTAB()
Definition: BiCGSTAB.h:175
_Preconditioner Preconditioner
Definition: BiCGSTAB.h:170
const ActualMatrixType & matrix() const
Definition: IterativeSolverBase.h:419
Base class for linear iterative solvers.
Definition: IterativeSolverBase.h:144
Index maxIterations() const
Definition: IterativeSolverBase.h:281
ComputationInfo m_info
Definition: IterativeSolverBase.h:438
RealScalar m_error
Definition: IterativeSolverBase.h:436
Preconditioner m_preconditioner
Definition: IterativeSolverBase.h:431
Index m_iterations
Definition: IterativeSolverBase.h:437
bool m_isInitialized
Definition: SparseSolverBase.h:119
RealScalar m_tolerance
Definition: IterativeSolverBase.h:434
BiCGSTAB< _MatrixType, _Preconditioner > & derived()
Definition: SparseSolverBase.h:79
const ActualMatrixType & matrix() const
Definition: IterativeSolverBase.h:419
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:145
@ NumericalIssue
Definition: Constants.h:444
@ Success
Definition: Constants.h:442
@ NoConvergence
Definition: Constants.h:446
const Scalar & y
Definition: MathFunctions.h:821
bool bicgstab(const MatrixType &mat, const Rhs &rhs, Dest &x, const Preconditioner &precond, Index &iters, typename Dest::RealScalar &tol_error)
Definition: BiCGSTAB.h:29
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: document.h:416
Definition: EigenBase.h:30
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233
_Preconditioner Preconditioner
Definition: BiCGSTAB.h:121
_MatrixType MatrixType
Definition: BiCGSTAB.h:120
Definition: ForwardDeclarations.h:17