Handle zero right hand side in CG and GMRES

This commit is contained in:
Desire NUENTSA
2013-03-20 11:22:45 +01:00
parent 9bfeeba1c5
commit 4107b371e3
2 changed files with 8 additions and 1 deletions

View File

@@ -48,6 +48,12 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
VectorType z(n), tmp(n);
RealScalar absNew = internal::real(residual.dot(p)); // the square of the absolute value of r scaled by invM
RealScalar rhsNorm2 = rhs.squaredNorm();
// Check Zero right hand side
if(!rhsNorm2)
{
x.setZero();
return;
}
RealScalar residualNorm2 = 0;
RealScalar threshold = tol*tol*rhsNorm2;
int i = 0;