[petsc-users] help needed for -snes_mf_operator

Barry Smith bsmith at mcs.anl.gov
Thu Apr 26 08:24:52 CDT 2012


On Apr 26, 2012, at 6:28 AM, Dominik Szczerba wrote:

> Jed, Barry, Matt:
> 
> Below a collection of all pending answers in one mail.
> 
>> How do you define "right results"?
> 
> I run the exact same problem on in a commercial FEM package and
> compare the results. The test problem is diffusion-reaction, with a
> nonlinear reaction term of a polynomial form (tested up to order 5). I
> Form the Jacobian as follows. We have a problem Ax = b(x), with A
> constant and b depending pointwise on x (i.e. db/dxn does not depend
> on xm, m!=n). Therefore I provide a simple Jacobian equal to A with
> the diagonal augmented with -db/dx. The relevant code is below. I do
> hope I do something wrong and you can point it out.
> 
> 	ierr = MatCopy(that->system.A, *B, SAME_NONZERO_PATTERN); CHKERRQ(ierr);
> 
> 	ierr = VecScale(that->dbdx, -1.0); CHKERRQ(ierr);
> 	ierr = MatDiagonalSet(*B, that->dbdx, ADD_VALUES); CHKERRQ(ierr);
> 
> 	ierr = MatAssemblyBegin(*B, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
> 	ierr = MatAssemblyEnd(*B, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
> 
> 	if(*J != *B)
> 	{
> 		ierr = MatAssemblyBegin(*J, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
> 		ierr = MatAssemblyEnd(*J, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
> 	}
> 
> 	*flag = SAME_NONZERO_PATTERN;
> 
> 
>> Is SNES converging quadratically when you
>> do not use -snes_mf_operator?
> 
> Without -snes_mf_operator, providing analytically derived Jacobian:
> 
>  0 SNES Function norm 1.747536282885e+01
>  1 SNES Function norm 1.918464419679e-03
>  2 SNES Function norm 1.086746779744e-03
>  3 SNES Function norm 2.904556511511e-06
>  4 SNES Function norm 7.804808098453e-08
> 
> Without -snes_mf_operator, passing A as the jacobian (which you call
> Picard), and slightly underrelaxing the linear solves (otherwise it
> would not converge):
> 
>  0 SNES Function norm 1.747886139999e+01
>  1 SNES Function norm 3.495796117011e+00
>  2 SNES Function norm 6.991806248330e-01
>  3 SNES Function norm 1.398879936054e-01
>  4 SNES Function norm 2.809047018752e-02
>  5 SNES Function norm 5.843745932752e-03
>  6 SNES Function norm 1.594583643926e-03
>  7 SNES Function norm 7.712066092135e-04
>  8 SNES Function norm 4.932447251451e-04
>  9 SNES Function norm 3.217945635817e-04
> 10 SNES Function norm 2.129867244811e-04
> 11 SNES Function norm 1.399983127264e-04
> 12 SNES Function norm 9.246882776024e-05
> 13 SNES Function norm 6.088284618615e-05
> 14 SNES Function norm 4.017029247381e-05
> 15 SNES Function norm 2.646770266042e-05
> 16 SNES Function norm 1.745497080382e-05
> 17 SNES Function norm 1.150437737331e-05
> 18 SNES Function norm 7.585434690336e-06
> 19 SNES Function norm 5.000147553531e-06
> 20 SNES Function norm 3.296560754852e-06
> 21 SNES Function norm 2.173152296533e-06
> 22 SNES Function norm 1.432685503660e-06
> 23 SNES Function norm 9.444717211995e-07
> 24 SNES Function norm 6.226464090397e-07
> 25 SNES Function norm 4.104757979681e-07
> 26 SNES Function norm 2.706068836265e-07
> 27 SNES Function norm 1.783963930887e-07
> 28 SNES Function norm 1.176079057620e-07
> 
> Dominik
> 
>> Run with -snes_type test and see what it reports.
> 
> Running with the options:
> 
> -ksp_type bcgs -pc_type jacobi -ksp_rtol 1e-4 -ksp_max_it 1000
> -ksp_converged_use_initial_residual_norm -ksp_norm_type
> unpreconditioned -ksp_monitor_true_residual -ksp_converged_reason
> -ksp_view -snes_monitor -snes_converged_reason -snes_ls_monitor
> -snes_view -snes_type test -snes_test_display
> 
> I get the output:
> 
> Testing hand-coded Jacobian, if the ratio is
> O(1.e-8), the hand-coded Jacobian is probably correct.
> 
> and the procedure stagnates, calling FormJacobian only once, and then
> FormFunction infinitely, with my own computation of ||F|| indicating
> stagnation.

   It is not calling it infinitely. Run with the -snes_type test option for a small problem, with say 10 unknowns to start.

   Barry

> 
> Regards,
> Dominik



More information about the petsc-users mailing list