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!ZMikDTtuiW1VhZZbem68GDU-ADoEf8_Mok1dQ18Er-vr4DStxjq-Ula5ZHd0tLvVSXoLbI-NNFYPuV20Gu08oDI$
 


   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