# NewtonSolver in v11

**URL:** <https://fenicsproject.discourse.group/t/newtonsolver-in-v11/19778>\
**Category:** dolfinx\
**Created:** [July 17, 2026, 7:14am UTC](https://fenicsproject.discourse.group/t/newtonsolver-in-v11/19778 "2026-07-17T07:14:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lclaire](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lclaire/32/1615_2.png) [@lclaire](https://fenicsproject.discourse.group/u/lclaire)\
**Post date:** [July 17, 2026, 7:14am UTC](https://fenicsproject.discourse.group/t/newtonsolver-in-v11/19778/1 "2026-07-17T07:14:39Z")

</div>

Hello, I am trying to run the hyperelasticity demo from [Hyperelasticity — Computational Mechanics Numerical Tours with FEniCSx](https://bleyerj.github.io/comet-fenicsx/intro/hyperelasticity/hyperelasticity.html) , but I get the following error message, related to NewtonSolver in NonlinearProblem:

```auto
Traceback (most recent call last):
  File "/home/claire/Downloads/hyperelasticity.py", line 224, in <module>
    solver = nls.petsc.NewtonSolver(mesh.comm, problem)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/claire/anaconda3/envs/fenicsx-env-v11/lib/python3.11/site-packages/dolfinx/nls/petsc.py", line 54, in __init__
    self._A = create_matrix(problem.a)
                            ^^^^^^^^^
AttributeError: 'NonlinearProblem' object has no attribute 'a'. Did you mean: 'A'?
Exception ignored in: <function NewtonSolver. __del__ at 0x7fc392df0720>
Traceback (most recent call last):
  File "/home/claire/anaconda3/envs/fenicsx-env-v11/lib/python3.11/site-packages/dolfinx/nls/petsc.py", line 62, in __del__
    for obj in filter(lambda obj: obj is not None, (self._A, self._b)):
                                                    ^^^^^^^
AttributeError: 'NewtonSolver' object has no attribute '_A'

```

I am not sure how to solve this. I have already tried editing lines below line 210:

```auto
petsc_options = {
    "snes_type": "newtonls",
    "snes_linesearch_type": "none",
    "snes_stol": np.sqrt(np.finfo(dolfinx.default_real_type).eps) * 1e-2,
    "snes_atol": 0,
    "snes_rtol": 0,
    "ksp_type": "preonly",
    "pc_type": "lu",
    "pc_factor_mat_solver_type": "mumps",
    "snes_monitor": None,
}
problem = fem.petsc.NonlinearProblem(Residual, u, bcs=bcs, petsc_options_prefix="demo_hyperelasticity_", petsc_options=petsc_options)

```

but I still get the error above.

Many thanks in advance for your help !

Kind regards,

Claire

---

<div class="post-metadata">

**Author:** ![kumar](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kumar](https://fenicsproject.discourse.group/u/kumar)\
**Post date:** [July 17, 2026, 8:36am UTC](https://fenicsproject.discourse.group/t/newtonsolver-in-v11/19778/2 "2026-07-17T08:36:15Z")

</div>

As far as what i know, the referenced hyperelasticity demo corresonding to dolfinx version 0.8. For version V11 it might not be compatible, which is why the possible error.

From the small snippet, i noticed that you have to replace the definition of problem as,

```auto
from dolfinx.fem.petsc import NewtonSolverNonlinearProblem
problem = fem.petsc.NewtonSolverNonlinearProblem(Residual, u, bcs,)
solver = nls.petsc.NewtonSolver(mesh.comm, problem)

```

Also when i tried, there is another modification subjected to v11,

```auto
# u.vector.set(0.0) --> to be replaced as 
u.x.petsc_vec.set(0.0)

```

I hope this works.

---

<div class="post-metadata">

**Author:** ![ottarhellan](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@ottarhellan](https://fenicsproject.discourse.group/u/ottarhellan)\
**Post date:** [July 20, 2026, 1:51pm UTC](https://fenicsproject.discourse.group/t/newtonsolver-in-v11/19778/3 "2026-07-20T13:51:13Z")

</div>

The new `NonlinearProblem` class has been simplified so that it builds its own petsc solver, thus there is no need to use `NewtonSolver`. Just call `problem.solve()` on instance you build in your edited code, then access convergence status and number of solves etc. by

```auto
problem.solve()
num_its = problem.solver.getIterationNumber()
converged = problem.solver.getConvergedReason()

```

The class that was called `NonlinearProblem` in the old versions has been moved to `NewtonSolverNonlinearProblem`, so you can either use that class with a `NewtonSolver`, or just use the new simplified interface.
