[petsc-users] Analytic Jacobian verfication

Jed Brown jed at 59A2.org
Fri Jun 17 06:19:03 CDT 2011


On Fri, Jun 17, 2011 at 12:59, Tian(ICT) <rongtian at ncic.ac.cn> wrote:

> Appreciate the quick answering. I DID get the identical solution, exact to
> all digital numbers (w and w/o -snes_mf_operator).
>

Please run both ways with -snes_view -snes_monitor and send the output.


> so second quick question: if the mesh happen to be structured (say one
> square element), can finite differenced Jacobian be the exactly same as the
> analytic one?
>

Suppose there is no grid at all. Let f(x) = 3*x, the 3 is arbitrary. This is
the simplest case because the function is actually linear, thus df(x,y) =
3*y. Now we compare

z1 = f(x + eps*y) - f(x) / eps = (3*(x + eps*y) - 3*x)/eps;

z2 = df(x,y) = 3*y;

Since floating point arithmetic is not associative, these are not the same.
For example, taking x=1, y=2, eps = 1e-8, we have

z1 = 6.000000052353016
z2 = 6.000000000000000

If it's not exact for a linear scalar problem with all coefficients, inputs,
and (exact) outputs exactly representable in floating point arithmetic, then
it's pretty unlikely to be exact for any PDE.


  Or the exactly same solution whether -snes_mf_operator or not implies
> something wrong in my code?
>

It's more likely that the same algorithm is used in both cases, -snes_view
should tell us what's happening.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110617/71fd25b5/attachment.htm>


More information about the petsc-users mailing list