Maybe you are using a DMDA, with one matrix coming from it and the other not? DMDA changes the View to dump in natural ordering. Il giorno lun 2 mar 2026 alle ore 18:10 Matteo Semplice via petsc-users < [email protected]> ha scritto:
Dear all,
the following output from -snes_test_jacobian_view lokks clear enough to pinpoint my mistake (I must be putting jacobian elements in the wrong place), but it nevertheless left me suprised. 0 SNES Function norm 2.945516399303e-01 ---------- Testing Jacobian ------------- Testing hand-coded Jacobian, if (for double precision runs) ||J - Jfd||_F/||J||_F is O(1.e-8), the hand-coded Jacobian is probably correct. ||J - Jfd||_F/||J||_F = 0.000121529, ||J - Jfd||_F = 0.395752 Hand-coded Jacobian ---------- Mat Object: 4 MPI processes row 84: (84, 60.) (85, 0.) (3446, -80.) (3447, 0.) (6808, 20.) (6809, 0.) row 85: (84, 0.00914434) (85, 1.) (3446, 0.) (3447, 0.) (6808, 0.) (6809, 0.)
Finite difference Jacobian ---------- Mat Object: 4 MPI processes type: mpiaij row 84: (84, 60.) (1806, -80.) (3528, 20.) row 85: (85, 0.999971)
Hand-coded minus finite-difference Jacobian with tolerance 1e-05 ---------- Mat Object: 4 MPI processes type: mpiaij row 84: row 85: (84, 0.00914434) (85, 2.9293e-05)
The difference of the two matrices shoudl be nonzero in row 84 for all elements 1806, 3528, 3446, 6808. Is it intended that the difference is shown only for matrix elements that are present in both the hand-coded and the FD jacobian?
I would have expected an output like
row 84: (1806,80.) (3446,-80.), etc
(This was on PETSc Release Version 3.24.2)
Thanks
Matteo
-- Prof. Matteo Semplice Università degli Studi dell’Insubria Dipartimento di Scienza e Alta Tecnologia – DiSAT Professore Associato Via Valleggio, 11 – 22100 Como (CO) – Italia tel.: +39 031 2386316
-- Stefano