Skip to content

[Fix]: Check convergence in NLSolver before returning solution#1283

Merged
JordiManyer merged 3 commits into
gridap:masterfrom
Ady0333:fix/nlsolver-convergence-check
Apr 27, 2026
Merged

[Fix]: Check convergence in NLSolver before returning solution#1283
JordiManyer merged 3 commits into
gridap:masterfrom
Ady0333:fix/nlsolver-convergence-check

Conversation

@Ady0333
Copy link
Copy Markdown
Contributor

@Ady0333 Ady0333 commented Apr 24, 2026

Summary

Fixes #1282

When nlsolve() fails to converge, NLSolver now checks the convergence status before returning the solution. Previously, it silently copied the unconverged last iterate.


Changes

  • src/Algebra/NLSolvers.jl: Add converged() check after nlsolve() call
  • src/ODEs/StageOperators.jl: Same fix for ODE/transient context

Behavior

Before: Unconverged Newton iterates silently returned as valid solutions
After: Throws error with iteration count and residual norm


Testing

Tested with a nonlinear problem that fails to converge:

  • Previously: returned x=44.44 (wrong) with no error
  • Now: throws "Newton solver did not converge after 5 iterations. Final residual norm: 87788"

All existing Gridap tests pass.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333
Copy link
Copy Markdown
Contributor Author

Ady0333 commented Apr 24, 2026

Hello @JordiManyer and @oriolcg!!! Please review this pr and let me know if any changes are needed...

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.82%. Comparing base (d6858fa) to head (77a9ed7).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/Algebra/NLSolvers.jl 50.00% 1 Missing ⚠️
src/ODEs/StageOperators.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1283      +/-   ##
==========================================
- Coverage   88.83%   88.82%   -0.01%     
==========================================
  Files         227      227              
  Lines       29749    29753       +4     
==========================================
+ Hits        26427    26429       +2     
- Misses       3322     3324       +2     
Flag Coverage Δ
drivers 39.35% <25.00%> (-0.01%) ⬇️
extensions 5.13% <0.00%> (-0.01%) ⬇️
unit-adaptivity 40.11% <0.00%> (-0.01%) ⬇️
unit-basics 14.67% <25.00%> (+<0.01%) ⬆️
unit-celldata 21.15% <0.00%> (-0.01%) ⬇️
unit-fespaces-1 32.34% <25.00%> (-0.01%) ⬇️
unit-fespaces-2 38.83% <25.00%> (-0.01%) ⬇️
unit-fields 17.59% <0.00%> (-0.01%) ⬇️
unit-geometry 28.80% <0.00%> (-0.01%) ⬇️
unit-multifield 30.86% <0.00%> (-0.01%) ⬇️
unit-odes 28.75% <50.00%> (+<0.01%) ⬆️
unit-referencefes 34.28% <0.00%> (-0.01%) ⬇️
unit-visualization 11.92% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JordiManyer
Copy link
Copy Markdown
Member

Thanks @Ady0333 for the contribution, I don't see any issue with the PR. Could you please update NEWS.md with the changes? Cheers!

@Ady0333
Copy link
Copy Markdown
Contributor Author

Ady0333 commented Apr 27, 2026

Thanks @Ady0333 for the contribution, I don't see any issue with the PR. Could you please update NEWS.md with the changes? Cheers!

Thanks for the review...I have updated the NEWS.md file.

@JordiManyer JordiManyer merged commit 670f802 into gridap:master Apr 27, 2026
55 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: NLSolver returns wrong solutions when Newton doesn't converge (no error thrown)

2 participants