[petsc-users] Element by element comparison of matrices
Barry Smith
bsmith at petsc.dev
Thu Jan 2 21:07:05 CST 2025
> -snes_test_jacobian -snes_test_jacobian_view
> On Jan 2, 2025, at 5:34 PM, Hammond, Glenn E <glenn.hammond at pnnl.gov> wrote:
>
> 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 <bsmith at 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!epphS19ORHlk58PNC52ioymjvLFv5HFHm_mpJQspG90ykgyw5aaUFtJAkxbYOyhTZ1Jag-BOMLM50u6QJ_9rhhQ$
>>
>>
>> Barry
>>
>>
>>
>>
>>> On Jan 2, 2025, at 4:51 PM, Stefano Zampini <stefano.zampini at 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 at mcs.anl.gov <mailto:petsc-users at 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
>>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250102/d4353982/attachment-0001.html>
More information about the petsc-users
mailing list