I need to element info (which row/col combo) to pinpoint which crossterm may be 
defective. This is important when debugging analytical derivatives for chemical 
reactions. I will look into thr SNES approach.

Thanks,

Glenn

On Jan 2, 2025, at 2:25 PM, Barry Smith <bsm...@petsc.dev> wrote:


Check twice before you click! This email originated from outside PNNL.


   We also have support for this built into SNES. For example, you provide the 
analytic to SNES which then compute via differencing, mostly to check if the 
analytic implementation was correct. You can run an entire set of SNESSolve 
with this turned on and it will check at all vectors the Jacobian is computed 
how closely the match is (that is it does not just compare the two for a single 
vector).

  -snes_test_jacobian <optional threshold>

see the routine SNESTestJacobian() which as the code that compares the matrices 
element by element etc. See also 
https://urldefense.us/v3/__https://petsc.org/release/manual/snes/*checking-accuracy-of-derivatives__;Iw!!G_uCfscf7eWS!ZoaRDcJH_dSH7xTDVlbvY-63elK9LdoGNbUNQJjBmvefqNO0zhpqzpbfTb6TDGKWr_omqNnkE359z37VW1z4usPPRD5q2Ls$
 


   Barry




On Jan 2, 2025, at 4:51 PM, Stefano Zampini <stefano.zamp...@gmail.com> wrote:


MatAXPY for the difference, MatNorm for the relative error

On Thu, Jan 2, 2025, 22:32 Hammond, Glenn E via petsc-users 
<petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>> wrote:
PETSc Users,

I want to compare two Jacobians matrices (one with derivatives calculated 
analytically; the other numerically). I want to apply relatives and/or absolute 
tolerances. Does anyone know if such capability is built into PETSc? I cannot 
find anything other the MatEqual() with compares down to the bit. Otherwise, I 
plan to use MatGetValues() and compare the elements individually. Just hoping 
there is something more convenient hidden somewhere.

Thanks,

Glenn

Reply via email to