# Convergence criteria

It is very important to set the global convergence criterion appropriately. This is the `-nl_abs_tol`

, or equivalently, PETSc's `-snes_atol`

. Of course the arguments below will also inform the setting of the relative tolerance `nl_rel_tol`

(or PETSc's `-snes_rtol`

). If set too small, then MOOSE will appear not to converge and will need very small timesteps in order to *do anything*. If set too large, then MOOSE will converge to the *wrong* result. Here are some tips to estimate the global convergence criterion.

## Fluids

Determine an appopriate tolerance on what you mean by *steadystate*. For instance, in a single-phase simulation with reasonably large constant fluid bulk modulus, and gravity acting in the direction, the steadystate solution is (up to a constant). In the case of water, this reads (approximately). Instead of this, suppose you would be happy to say the model is at steadystate if . Here needn't be constant: it may switch in sign, but its magnitude is roughly the same over the domain of interest. For instance, for water, an error of Pa.m might be suitable in your problem.

Then recall that the residual is just (1) Evaluate this for your *almost-steadystate* solution.

For instance, in the case of water just quoted, , and the , and the integral just becomes , the volume of the region of interest, so (2)

For water, this gives , using standard values for and .

In the previous step, an appropriate tolernace on the residual was given as . Now the volume of interest, , must be specified. Often this is not the entire mesh, but a small region where most of the interesting dynamics occurs, and the remainder of the mesh exists just to provide reasonable boundary conditions for this *interesting* region. The residual in the *boring* region can be thought of as virtually zero, while the residual in the *interesting* region is . This is the absolute nonlinear residual that you should aim for.

In the above, it is implicitly assumed is constant, is virtually constant at , only a single-phase is present, etc. In many cases these assumptions are not valid, so the integral of Eq. (1) cannot be done as trivially as in the previous steps. In these cases, a good approximation of a reasonable residual tolerance can be obtained by building a model with initial conditions like and observing what the initial residual is.

## Heat

A similar method can be used to estimate the convergence criterion for heat-flow problems. Suppose there is both heat conduction, and fluid advection. Suppose that is the acceptable error in the fluid equations (as in the previous section). Suppose that is an acceptable error for the temperature. For instance being incorrect by K.m might be appropriate for your problem.

Then the residual is approximately (3) The last term is just the fluid enthalpy, , multiplied by the fluid residual.

## Mechanics

Very similar methods can be used in simulations where mechanical deformations are active. Roughly speaking, MOOSE is attempting to set . Determine the error in that you are willing to accept, and label it . For instance Pa.m might be appropriate for your problem. You may determine from consideration of stresses directly, or you may wish to consider what the accpetable error in strains or displacements would be, and then use the elasticity tensor to find .

The nonlinear residual will be (4) where is the volume of interest.

## Scaling the variables

Often it is appropriate to scale the variables in order to weight their contributions to the overall nonlinear residual appropriately. For instance, suppose the previous arguments provided (5) (with the same in each case). Then, a scaling of around on the porepressure variable (or whatever MOOSE variable is associated to the fluid equation) would be appropriate. Similarly, a scaling of around on the temperature variable would be appropriate.

Scaling the variables is implemented in the input file using the `scaling`

parameter, for instance:

```
[Variables]
[./porepressure]
[../]
[./temperature]
initial_condition = 293
scaling = 1E-8
[../]
[]
```

(modules/porous_flow/examples/tutorial/03.i)