Dear All, I have a quick question about the absolute and relative tolerance of Newton solver in FeniCS, does anybody know what is the default value for these two tolerances in FeniCS? Thanks!

Hello Nate, thank you so much for pointing me this, Itâ€™s very helpful! I guess these are the recommended values for absolute and relative tolerance in general, right? Is there any criteria for choosing these tolerance, in other words, is there an upper bound for the acceptable tolerance values? I guess for different problems in reality, the convergence behaviors will be quite different.

I write the following in the context of FE modelling rather than numerical analysis. I.e. this should be interpreted as tips and tricks. Perhaps someone else can contribute something more rigorous, or their own experience.

#### Do you know what to expect the residual of your system to be to machine precision?

Adjust your absolute tolerance accordingly. E.g:

- A Poisson problem with a diffusion coefficient of 1 may yield a residual to machine precision around 10^{-12}.
- Linear elasticity with a Youngâ€™s modulus of 10^9, convergence to machine precision you may see with a residual of around 10^{-3}.

#### Do you have no *a priori* information about the magnitude of the residual to machine precision?

Set the relative error tolerance accordingly, e.g. a relative tolerance of 10^{-12} is very precise.

#### Do you only care about solving your system in a loose approximate sense

Use a larger relative tolerance. This number should still be chosen based on your remaining knowledge of the numerical model.

#### Is your problem linear?

Make sure it converges in one iteration. If it does not, your system is not well defined. Newtonâ€™s method applied to a linear problem is equivalent to solving that linear problem.

#### Is your problem nonlinear, well posed, and the solution is smooth?

Ensure you have at least quadratic convergence of the residual between iterations. Otherwise you have a malformed Jacobian.

#### Does your Newton solver fail on the first step producing `NaN`

s?

You likely have an initial guess leading to singularities in the Jacobian/residual. E.g: for a solution variable u

- Zero initial guess with coefficients of the type 1/u or \sqrt{u}
- Piecewise constant initial guess when invoking \nabla u^{-1} or \sqrt{\varepsilon_{\mathrm{II}}(u)}

#### Does the Newton solver converge initially, then diverge and blow up?

Try easing the relaxation parameter, or design a more sophisticated relaxation parameter e.g. here. This should encourage convergence for â€śhighly nonlinearâ€ť problems.

#### Does the Newton solver slowly diverge or get stuck?

Ensure your initial guess is sufficiently in an attractor region.

Hi Nate, Thank you so much for the kind help!

Hi nate,

I am currently trying to change the initial guess to a nonzero value using the fem.petsc.NonlinearProblem and nls.petsc.NewtonSolver from the tutorial on Nonlinear Poisson(Implementation â€” FEniCSx tutorial), as my solver is failing and producing NaNs. Taking your advice, how would I go about changing the initial guess here?

Thank you

The initial guess should be whatever the initial approximation is populated with. In the context of the tutorial to which youâ€™ve linked itâ€™s whatever `uh = fem.Function(V)`

is initialised with. For example, if you were to set

```
uh = fem.Function(V)
uh.interpolate(lambda x: x[0])
```

then your initial guess is u_{h,0} = x.