Skip to content

Commit

Permalink
Merge pull request #688 from evalf/niter
Browse files Browse the repository at this point in the history
Niter
  • Loading branch information
gertjanvanzwieten committed Jun 1, 2022
2 parents f1e57d6 + 79743e4 commit 2e45fd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ features in inverse chronological order.
New in v8.0 (in development)
----------------------------

- New: iteration count via info.niter

The info struct returned by ``solve_withinfo`` newly contains the amount of
iterations as the ``niter`` attribute:

>>> res, info = solver.newton('u:v', res).solve_withinfo(1e-10, maxiter=10)
>>> assert info.niter <= 10

- New: test fields and residual functionals

The :mod:`nutils.solver` methods have been generalized to accept scalar
Expand Down
7 changes: 3 additions & 4 deletions nutils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ def solve_withinfo(self, tol, maxiter=float('inf'), miniter=0):
if miniter > maxiter:
raise ValueError('The minimum number of iterations cannot be larger than the maximum.')
with log.iter.wrap(_progress(self._wrapped.__class__.__name__, tol), self) as items:
i = 0
for lhs, info in items:
for i, (lhs, info) in enumerate(items):
if info.resnorm <= tol and i >= miniter:
break
if i > maxiter:
raise SolverError('failed to reach target tolerance')
i += 1
log.info('converged in {} steps to residual {:.1e}'.format(i, info.resnorm))
log.info(f'converged in {i} steps to residual {info.resnorm:.1e}')
info.niter = i
return lhs, info


Expand Down

0 comments on commit 2e45fd6

Please sign in to comment.