Dear NGSolve team,
I encountered a ZeroDivisionError: float division by zero in ngsolve/krylovspace.py inside the MinResSolver.
This happens when the initial guess exactly solves the problem (e.g., solving a problem from the reference configuration with 0% load) and the initial residual is already zero (or at machine precision).
Looking at the source code of _SolveImpl in MinResSolver, the Lanczos normalisation is performed blindly without a safeguard check:
gamma = sqrt(InnerProduct(z,v))
gamma_new = 0
z.data = 1/gamma * z # <— Crashes here if gamma == 0
v.data = 1/gamma * v
If gamma evaluates to 0.0, the code crashes. In contrast, the CGSolver includes a proper safeguard to prevent this (e.g., if as_s == 0 or wd == 0: break).
Could a similar early-exit or safeguard check (e.g., if gamma < 1e-16: break or if gamma == 0: break) be added to the MinResSolver before the division?
Best regards,
Chris