Validate exact Jacobian by Finite Differences
Dear Firedrakers, I compared my Jacobian generated by finite differences with the Jacobian generated by firedrake. The firedrake Jacobian seems to be wrong... I generated the FD Jacobian in my Fortran code. Is there a way to simply calculate the FD Jacobian within firedrake to validate the exact Jacobian? Thank you! Henrik -- Dipl.-Math. Henrik Büsing Institute for Applied Geophysics and Geothermal Energy E.ON Energy Research Center RWTH Aachen University ------------------------------------------------------ Mathieustr. 10 | Tel +49 (0)241 80 49907 52074 Aachen, Germany | Fax +49 (0)241 80 49889 ------------------------------------------------------ http://www.eonerc.rwth-aachen.de/GGE hbuesing@eonerc.rwth-aachen.de ------------------------------------------------------
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 30/09/15 10:01, Buesing, Henrik wrote:
Dear Firedrakers,
I compared my Jacobian generated by finite differences with the Jacobian generated by firedrake. The firedrake Jacobian seems to be wrong... I generated the FD Jacobian in my Fortran code. Is there a way to simply calculate the FD Jacobian within firedrake to validate the exact Jacobian?
You can utilise PETSc's finite differencing. Firedrake always solves variational problems in residual form (i.e. they're always set up as suitable for passing to Newton). So if you have a linear problem: solve(a == L, ...) or a nonlinear problem: solve(F == 0, ...) You can ask PETSc to validate the Jacobian against a finite difference approximation like so: solve(..., solver_parameters={'snes_type': 'test'}) This computes an FD approximation and prints some info about the difference to the provided Jacobian, it then aborts the solve (this is normal). If you want to see the differences, you need to add: 'snes_test_display': True to the solver_parameters as well. Finally, if you're doing this in a mixed space, you'll need to say: solve(..., solver_parameters={'snes_type': 'test'}, nest=False) This tells Firedrake to assemble a single matrix (rather than separate blocks) for the mixed operator. Cheers, Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJWC6cgAAoJECOc1kQ8PEYvt1UH/RBzKOOkiSHznNNauTuHHOmk lHu21hvgwxxHOtJZMN6kULwgkShxUlQrIsIponH1B+AvicLZ0ykJrsOP4ALb7THv hYNZd0yRyiCFtb3mn2xfWVphF0g5a8QZ/v9uypQg1CaScbIXgNHvxWDuy4IOPbYL /GCizT6HAsxRBj+nejCLnXroiaoGYVLTYguBakcsezq2RihNlgGGQVT6Dd68FOBo gcwtLuvwHIJgL4Jn9s8Ump5uUX693YtECbFsLZtzilGnEzlIpzIdZ+3DqEtxq8JD C+Qkm5+Olvx7oKK14fUzdzQCeBFRASirHaHMoE12Ly1b68kFgmiAUVSije0ieDo= =R3zB -----END PGP SIGNATURE-----
participants (2)
-
Buesing, Henrik
-
Lawrence Mitchell