Introduce finite difference verification for non linear operators
We want to be able to check that the local matrix of the ComputeEltArray()
method of NonLinearVariationalOperators does correspond to the derivative of the local vector. We usually check that the convergence of the Newton method involving these operators is quadratic but we can also estimate the derivative of a residual numerically through finite differences, albeit with a numerical error.
The goal of the test is to make sure that, given an upper bound for the error, the local matrix matches the approximated derivative of the local vector.
We use the fact that
\frac{\partial f(x,y,z)}{\partial x} \simeq \frac{f(x + \Delta h, y, z) - f(x, y,z)}{\Delta h}
One has to be careful with the choice of the numerical value for h
, if it's too high we do not estimate the derivative correctly and if it is too low we are subject to numerical errors (division by a very small value).
Note that this test in itself does not guarantee that an operator does what it is supposed to do, if there is an error in the computation of the local vector and this error is also propagated in the computation of the local matrix it will not be seen by this test (here we only check that the tangent is consistent with respect to the corresponding residual).