[petsc-users] -snes_type test shows differences
(Rebecca) Xuefei YUAN
xy2102 at columbia.edu
Wed Feb 10 14:35:14 CST 2010
Hi,all,
I was writing analytic Jacobian to my FormJacobian(). However, I found
that there are quite big differences between finite difference
Jacobian and hand coded Jacobian. To simply the problem, assume that I
am solving a very simple equation as the residual function has the
form of
F = fxx*fyy - g.
Where f is the unknown, g is the given r.h.s.
The discretization scheme is the central difference, and therefore, in
my FormFunction,
fgrid[j][i].disp = (
+ ihx1hy1*(grid[j][i+1].disp + grid[j][i-1].disp
- 2*grid[j][i].disp)*(grid[j+1][i].disp + grid[j-1][i].disp -
2*grid[j][i].disp)
);
for the interior points.
The crosponding Jacobian has the form
value[0] = 0.0;
value[2] = 0.0;
value[6] = 0.0;
value[8] = 0.0;
value[1] = ihx1hy1*(grid[j][i+1].disp + grid[j][i-1].disp -
2*grid[j][i].disp);
value[3] = ihx1hy1*(grid[j+1][i].disp + grid[j-1][i].disp -
2*grid[j][i].disp);
value[4] = -2*ihx1hy1*(grid[j][i+1].disp + grid[j][i-1].disp +
grid[j+1][i].disp + grid[j-1][i].disp - 4*grid[j][i].disp);
value[5] = ihx1hy1*(grid[j+1][i].disp + grid[j-1][i].disp -
2*grid[j][i].disp);
value[7] = ihx1hy1*(grid[j][i+1].disp + grid[j][i-1].disp -
2*grid[j][i].disp);
where {4} is the center point, {0,2,6,8} are corner pts and {1,3,5,7}
are star pts, i.e, from left top to right bottom, the order is
0,1,2,3,...,7,8.
The difference between finite difference Jac and hand coded Jac
happens at value[4] where it is a nonlinear term (grid[j][i].disp) in
the residual function.
I test with -snes_type test -snes_test_display with different grid
sizes as ratios and norms below. Differences and ratios increase as
grid sizes increase. Did I have the hand coded Jacobian wrong?
When grid size is 5x7:
Norm of matrix ratio 1.58364e-05 difference 0.000322729
Norm of matrix ratio 2.57168e-05 difference 0.000162665
Norm of matrix ratio 2.57168e-05 difference 0.000162665
When grid size is 15x17:
Norm of matrix ratio 0.000725401 difference 0.0385688
Norm of matrix ratio 0.00169032 difference 0.0185166
Norm of matrix ratio 0.00169032 difference 0.0185166
When grid size is 25x27:
Norm of matrix ratio 0.00349658 difference 0.313173
Norm of matrix ratio 0.0105296 difference 0.148911
Norm of matrix ratio 0.0105296 difference 0.148911
When grid size is 35x37:
Norm of matrix ratio 0.00969703 difference 1.22697
Norm of matrix ratio 0.0347181 difference 0.580945
Norm of matrix ratio 0.0347181 difference 0.580945
When grid size is 45x47:
Norm of matrix ratio 0.0206974 difference 3.38781
Norm of matrix ratio 0.0843389 difference 1.60022
Norm of matrix ratio 0.0843389 difference 1.60022
Thanks very much!
Rebecca
More information about the petsc-users
mailing list