mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Handle zero right hand side in CG and GMRES
This commit is contained in:
parent
9bfeeba1c5
commit
4107b371e3
@ -48,6 +48,12 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
|||||||
VectorType z(n), tmp(n);
|
VectorType z(n), tmp(n);
|
||||||
RealScalar absNew = internal::real(residual.dot(p)); // the square of the absolute value of r scaled by invM
|
RealScalar absNew = internal::real(residual.dot(p)); // the square of the absolute value of r scaled by invM
|
||||||
RealScalar rhsNorm2 = rhs.squaredNorm();
|
RealScalar rhsNorm2 = rhs.squaredNorm();
|
||||||
|
// Check Zero right hand side
|
||||||
|
if(!rhsNorm2)
|
||||||
|
{
|
||||||
|
x.setZero();
|
||||||
|
return;
|
||||||
|
}
|
||||||
RealScalar residualNorm2 = 0;
|
RealScalar residualNorm2 = 0;
|
||||||
RealScalar threshold = tol*tol*rhsNorm2;
|
RealScalar threshold = tol*tol*rhsNorm2;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -348,7 +348,8 @@ public:
|
|||||||
template<typename Rhs,typename Dest>
|
template<typename Rhs,typename Dest>
|
||||||
void _solve(const Rhs& b, Dest& x) const
|
void _solve(const Rhs& b, Dest& x) const
|
||||||
{
|
{
|
||||||
x.setZero();
|
x = b;
|
||||||
|
if(!x.squaredNorm()) return; // Check Zero right hand side
|
||||||
_solveWithGuess(b,x);
|
_solveWithGuess(b,x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user