[petsc-users] Problems about tolerances set in TS
Zhang, Hong
hongzhang at anl.gov
Thu Apr 30 13:20:58 CDT 2020
On Apr 30, 2020, at 6:22 AM, Yingjie Wu <yjwu16 at gmail.com<mailto:yjwu16 at gmail.com>> wrote:
I'm sorry for dropping the mailing list in previous mail.
I went over the code and made sure I didn't set the maximum number or final time to zero for TS. And I found a very similar example in petsc/src/ts/tutorials/ex8.c.
I made the following changes:
1. TSSetMaxStepRejections<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxStepRejections.html#TSSetMaxStepRejections>(ts,10); -> TSSetMaxStepRejections<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxStepRejections.html#TSSetMaxStepRejections>(ts,0);
2. TSSetMaxSNESFailures<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxSNESFailures.html#TSSetMaxSNESFailures>(ts,-1); -> TSSetMaxSNESFailures<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxSNESFailures.html#TSSetMaxSNESFailures>(ts,0);
Now it is clear why your code terminates early.
TSSetMaxStepRejections<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxStepRejections.html#TSSetMaxStepRejections> (-td_max_reject) specifies the maximum number of failed time steps that TS adapter allows.
TSSetMaxSNESFailures<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxSNESFailures.html#TSSetMaxSNESFailures> (-ts_max_snes_failures) specifies the maximum number of failed nonlinear solves that TS adapter allows.
The TS adapter can reject a time step and restart it with a decreased step size if the error criterion is not met. Diverged nonlinear solve is one of the reasons that cause a time step rejected.
To avoid termination caused by these constraints, you can use
-ts_max_snes_failures -1
-ts_max_reject -1
to set both of them unlimited.
When the nonlinear solve diverges (e.g. the number of SNES iterations reaches the limit set by -snes_max_it), TS adapter will decrease the step size by a factor (can be changed with -ts_adapt_scale_solve_failed) and repeat the time step. Sometimes you may end up with excessively small steps if the repeated nonlinear solves keep struggling. In that case, I would turn off the adapter with -ts_adapt_type none and stick with the fixed time stepping or control the step size myself.
Hong (Mr.)
These changes adjust the Rejections and SNESFailures to the default state.
Then test the following commands: mpiexec -n 1 ./ex8 -ts_atol 1e-2 -ts_rtol 1e-2 -ts_max_time 15 -ts_type arkimex -ts_arkimex_type 2e -problem_type orego -ts_arkimex_initial_guess_extrapolate 0 -ts_adapt_time_step_increase_delay 4 -ts_monitor -snes_monitor -snes_converged_reason
The output on the screen is:
(......)
7 TS dt 6.86235 time 3.47215
0 SNES Function norm 2.000433909025e-01
1 SNES Function norm 1.991123862317e-01
2 SNES Function norm 1.975627926780e-01
3 SNES Function norm 1.946057832068e-01
4 SNES Function norm 1.900556025613e-01
5 SNES Function norm 1.840284735193e-01
6 SNES Function norm 1.767727556549e-01
7 SNES Function norm 1.685779659858e-01
8 SNES Function norm 1.597281513554e-01
9 SNES Function norm 1.504796576996e-01
10 SNES Function norm 1.410521859210e-01
11 SNES Function norm 1.316269768177e-01
12 SNES Function norm 1.223486899848e-01
13 SNES Function norm 1.127512649756e-01
14 SNES Function norm 1.020567711262e-01
15 SNES Function norm 8.979527463515e-02
16 SNES Function norm 7.508859688939e-02
17 SNES Function norm 7.355450203066e-02
18 SNES Function norm 2.927834451754e-06
19 SNES Function norm 4.107891676938e-15
Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 19
0 SNES Function norm 1.349799651143e-01
1 SNES Function norm 1.333235099246e-01
2 SNES Function norm 1.314928290684e-01
3 SNES Function norm 1.295004620848e-01
4 SNES Function norm 1.273561109747e-01
5 SNES Function norm 1.250670006052e-01
6 SNES Function norm 1.226381484156e-01
7 SNES Function norm 1.200604281861e-01
8 SNES Function norm 1.173313259697e-01
9 SNES Function norm 1.144768440013e-01
10 SNES Function norm 1.141593852677e-01
11 SNES Function norm 1.121207287132e-01
12 SNES Function norm 1.087640960519e-01
13 SNES Function norm 1.044397486143e-01
14 SNES Function norm 9.944173247962e-02
15 SNES Function norm 9.401107464556e-02
16 SNES Function norm 8.834148211449e-02
17 SNES Function norm 8.258574767211e-02
18 SNES Function norm 7.686203062639e-02
19 SNES Function norm 7.076716424793e-02
20 SNES Function norm 6.389435437215e-02
21 SNES Function norm 5.587963465672e-02
22 SNES Function norm 4.597296586383e-02
23 SNES Function norm 3.649153890859e-02
24 SNES Function norm 1.112024137036e-06
25 SNES Function norm 1.368410750160e-14
Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 25
8 TS dt 7.74608 time 10.3345
0 SNES Function norm 2.851716167826e-01
1 SNES Function norm 2.827877334190e-01
2 SNES Function norm 2.803985313138e-01
3 SNES Function norm 2.780035928632e-01
4 SNES Function norm 2.756024874780e-01
5 SNES Function norm 2.731947705882e-01
6 SNES Function norm 2.707799825757e-01
7 SNES Function norm 2.683576476261e-01
8 SNES Function norm 2.659272724924e-01
9 SNES Function norm 2.634883451605e-01
10 SNES Function norm 2.610403334061e-01
11 SNES Function norm 2.585826832306e-01
12 SNES Function norm 2.561148171641e-01
13 SNES Function norm 2.536361324179e-01
14 SNES Function norm 2.511459988719e-01
15 SNES Function norm 2.486437568755e-01
16 SNES Function norm 2.461287148411e-01
17 SNES Function norm 2.461031613348e-01
18 SNES Function norm 2.455705375830e-01
19 SNES Function norm 2.445878823765e-01
20 SNES Function norm 2.432027776816e-01
21 SNES Function norm 2.414549711706e-01
22 SNES Function norm 2.393776915919e-01
23 SNES Function norm 2.369987079777e-01
24 SNES Function norm 2.343411787922e-01
25 SNES Function norm 2.314243298882e-01
26 SNES Function norm 2.282639927909e-01
27 SNES Function norm 2.248730282013e-01
28 SNES Function norm 2.212616539034e-01
29 SNES Function norm 2.174376914167e-01
30 SNES Function norm 2.134067415679e-01
31 SNES Function norm 2.091722954520e-01
32 SNES Function norm 2.047263028819e-01
33 SNES Function norm 2.000468148325e-01
34 SNES Function norm 1.951751560520e-01
35 SNES Function norm 1.946187817680e-01
36 SNES Function norm 1.912149142781e-01
37 SNES Function norm 1.856377137631e-01
38 SNES Function norm 1.784574187852e-01
39 SNES Function norm 1.701485679136e-01
40 SNES Function norm 1.611004146461e-01
41 SNES Function norm 1.516277627394e-01
42 SNES Function norm 1.419813980321e-01
43 SNES Function norm 1.323577340278e-01
44 SNES Function norm 1.224961331340e-01
45 SNES Function norm 1.115622228182e-01
46 SNES Function norm 9.910072225366e-02
47 SNES Function norm 8.425984823824e-02
48 SNES Function norm 6.475245098809e-02
49 SNES Function norm 2.817391391875e-02
50 SNES Function norm 2.187931938195e-06
Nonlinear solve did not converge due to DIVERGED_MAX_IT iterations 50
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR:
[0]PETSC ERROR: TSStep has failed due to DIVERGED_STEP_REJECTED
[0]PETSC ERROR: See https://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.12.4, unknown
[0]PETSC ERROR: ./ex8 on a arch-linux2-c-debug named ubuntu103 by wuyj Thu Apr 30 10:40:07 2020
[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack
[0]PETSC ERROR: #1 TSStep() line 3596 in /home/wuyj/petsc/src/ts/interface/ts.c
[0]PETSC ERROR: #2 TSSolve() line 3768 in /home/wuyj/petsc/src/ts/interface/ts.c
[0]PETSC ERROR: #3 main() line 416 in ex8.c
[0]PETSC ERROR: PETSc Option Table entries:
[0]PETSC ERROR: -problem_type orego
[0]PETSC ERROR: -snes_converged_reason
[0]PETSC ERROR: -snes_monitor
[0]PETSC ERROR: -ts_adapt_time_step_increase_delay 4
[0]PETSC ERROR: -ts_arkimex_initial_guess_extrapolate 0
[0]PETSC ERROR: -ts_arkimex_type 2e
[0]PETSC ERROR: -ts_atol 1e-2
[0]PETSC ERROR: -ts_max_time 15
[0]PETSC ERROR: -ts_monitor
[0]PETSC ERROR: -ts_rtol 1e-2
[0]PETSC ERROR: -ts_type arkimex
[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint at mcs.anl.gov<mailto:petsc-maint at mcs.anl.gov>----------
application called MPI_Abort(MPI_COMM_WORLD, 91) - process 0
At the eighth time step, the maximum iterations number of SNES resulting in the failure of the time step calculation, the program reported errors.
Then I tested the following commands: mpiexec -n 1 ./ex8 -ts_atol 1e-2 -ts_rtol 1e-2 -ts_max_time 15 -ts_type arkimex -ts_arkimex_type 2e -problem_type orego -ts_arkimex_initial_guess_extrapolate 0 -ts_adapt_time_step_increase_delay 4 -snes_monitor -snes_converged_reason -ts_monitor -ts_error_if_step_fails 0
The output in screen:
(......)
7 TS dt 6.86235 time 3.47215
0 SNES Function norm 2.000433909025e-01
1 SNES Function norm 1.991123862317e-01
2 SNES Function norm 1.975627926780e-01
3 SNES Function norm 1.946057832068e-01
4 SNES Function norm 1.900556025613e-01
5 SNES Function norm 1.840284735193e-01
6 SNES Function norm 1.767727556549e-01
7 SNES Function norm 1.685779659858e-01
8 SNES Function norm 1.597281513554e-01
9 SNES Function norm 1.504796576996e-01
10 SNES Function norm 1.410521859210e-01
11 SNES Function norm 1.316269768177e-01
12 SNES Function norm 1.223486899848e-01
13 SNES Function norm 1.127512649756e-01
14 SNES Function norm 1.020567711262e-01
15 SNES Function norm 8.979527463515e-02
16 SNES Function norm 7.508859688939e-02
17 SNES Function norm 7.355450203066e-02
18 SNES Function norm 2.927834451754e-06
19 SNES Function norm 4.107891676938e-15
Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 19
0 SNES Function norm 1.349799651143e-01
1 SNES Function norm 1.333235099246e-01
2 SNES Function norm 1.314928290684e-01
3 SNES Function norm 1.295004620848e-01
4 SNES Function norm 1.273561109747e-01
5 SNES Function norm 1.250670006052e-01
6 SNES Function norm 1.226381484156e-01
7 SNES Function norm 1.200604281861e-01
8 SNES Function norm 1.173313259697e-01
9 SNES Function norm 1.144768440013e-01
10 SNES Function norm 1.141593852677e-01
11 SNES Function norm 1.121207287132e-01
12 SNES Function norm 1.087640960519e-01
13 SNES Function norm 1.044397486143e-01
14 SNES Function norm 9.944173247962e-02
15 SNES Function norm 9.401107464556e-02
16 SNES Function norm 8.834148211449e-02
17 SNES Function norm 8.258574767211e-02
18 SNES Function norm 7.686203062639e-02
19 SNES Function norm 7.076716424793e-02
20 SNES Function norm 6.389435437215e-02
21 SNES Function norm 5.587963465672e-02
22 SNES Function norm 4.597296586383e-02
23 SNES Function norm 3.649153890859e-02
24 SNES Function norm 1.112024137036e-06
25 SNES Function norm 1.368410750160e-14
Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 25
8 TS dt 7.74608 time 10.3345
0 SNES Function norm 2.851716167826e-01
1 SNES Function norm 2.827877334190e-01
2 SNES Function norm 2.803985313138e-01
3 SNES Function norm 2.780035928632e-01
4 SNES Function norm 2.756024874780e-01
5 SNES Function norm 2.731947705882e-01
6 SNES Function norm 2.707799825757e-01
7 SNES Function norm 2.683576476261e-01
8 SNES Function norm 2.659272724924e-01
9 SNES Function norm 2.634883451605e-01
10 SNES Function norm 2.610403334061e-01
11 SNES Function norm 2.585826832306e-01
12 SNES Function norm 2.561148171641e-01
13 SNES Function norm 2.536361324179e-01
14 SNES Function norm 2.511459988719e-01
15 SNES Function norm 2.486437568755e-01
16 SNES Function norm 2.461287148411e-01
17 SNES Function norm 2.461031613348e-01
18 SNES Function norm 2.455705375830e-01
19 SNES Function norm 2.445878823765e-01
20 SNES Function norm 2.432027776816e-01
21 SNES Function norm 2.414549711706e-01
22 SNES Function norm 2.393776915919e-01
23 SNES Function norm 2.369987079777e-01
24 SNES Function norm 2.343411787922e-01
25 SNES Function norm 2.314243298882e-01
26 SNES Function norm 2.282639927909e-01
27 SNES Function norm 2.248730282013e-01
28 SNES Function norm 2.212616539034e-01
29 SNES Function norm 2.174376914167e-01
30 SNES Function norm 2.134067415679e-01
31 SNES Function norm 2.091722954520e-01
32 SNES Function norm 2.047263028819e-01
33 SNES Function norm 2.000468148325e-01
34 SNES Function norm 1.951751560520e-01
35 SNES Function norm 1.946187817680e-01
36 SNES Function norm 1.912149142781e-01
37 SNES Function norm 1.856377137631e-01
38 SNES Function norm 1.784574187852e-01
39 SNES Function norm 1.701485679136e-01
40 SNES Function norm 1.611004146461e-01
41 SNES Function norm 1.516277627394e-01
42 SNES Function norm 1.419813980321e-01
43 SNES Function norm 1.323577340278e-01
44 SNES Function norm 1.224961331340e-01
45 SNES Function norm 1.115622228182e-01
46 SNES Function norm 9.910072225366e-02
47 SNES Function norm 8.425984823824e-02
48 SNES Function norm 6.475245098809e-02
49 SNES Function norm 2.817391391875e-02
50 SNES Function norm 2.187931938195e-06
Nonlinear solve did not converge due to DIVERGED_MAX_IT iterations 50
9 TS dt 1.93652 time 10.3345
steps 9 (1 rejected, 1 SNES fails), ftime 10.3345, nonlinits 126, linits 126
Although the program did not report errors, but end the operation after the eighth time step, and output results.
Note that the program did not reach the set termination time (-ts_max_time 15).
This indicates that the command -ts_error_if_step_fails 0, while avoiding program errors, ends TS solving after a failed SNES and does not proceed to the next step.
And I'd like to continue the next step with the result after a failed SNES time step (although this result is not converged).
In addition, I would like to ask the function of these two functions: TSSetMaxStepRejections<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxStepRejections.html#TSSetMaxStepRejections> and TSSetMaxSNESFailures<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetMaxSNESFailures.html#TSSetMaxSNESFailures>().
I looked it up in manualpages/singleindex.html, but there were very few explanations, and I still didn't quite understand the meaning of Rejection and SNES Failures variables.
Thank you very much for your reply and I hope you can help me to answer these questions.
Thanks,
Yingjie
Zhang, Hong <hongzhang at anl.gov<mailto:hongzhang at anl.gov>> 于2020年4月30日周四 下午1:22写道:
Please do not drop the mailing list when replying.
It looks like the max steps or the final time has been set to zero for TS. You might want to check your code to see if the TS settings are correct or if they are overwritten in some callback functions by mistake.
Hong (Mr.)
> On Apr 29, 2020, at 10:16 PM, Yingjie Wu <yjwu16 at gmail.com<mailto:yjwu16 at gmail.com>> wrote:
>
> Command: mpiexec -n 1 ./SGts -snes_fd -pc_type lu -ts_error_if_step_fails 0 -ts_monitor -snes_monitor \
> -ksp_monitor \
> -ksp_converged_reason \
> -snes_converged_reason \
> -snes_rtol 1.e-2 \
> -ksp_rtol 1.e-5 \
> -snes_max_it 2 \
> -snes_view
> Output: Timestep 0:
> CurrentTime 0.:
> 0 TS dt 1. time 0.
> iter = 0, SNES Function norm 245.204
> 0 SNES Function norm 2.452043863308e+02
> 0 KSP Residual norm 1.641317090793e+04
> 1 KSP Residual norm 2.717662845608e-10
> Linear solve converged due to CONVERGED_RTOL iterations 1
> iter = 1, SNES Function norm 170.58
> 1 SNES Function norm 1.705802879797e+02
> 0 KSP Residual norm 1.146216600447e+04
> 1 KSP Residual norm 3.272076151518e-11
> Linear solve converged due to CONVERGED_RTOL iterations 1
> iter = 2, SNES Function norm 140.625
> 2 SNES Function norm 1.406249065994e+02
> Nonlinear solve did not converge due to DIVERGED_MAX_IT iterations 2
> SNES Object: 1 MPI processes
> type: newtonls maximum iterations=2, maximum function evaluations=-1530494976
> tolerances: relative=0.01, absolute=1e-50, solution=1e-08
> total number of linear solver iterations=2
> total number of function evaluations=1063
> norm schedule ALWAYS
> Jacobian is built using finite differences one column at a time
> SNESLineSearch Object: 1 MPI processes
> type: bt
> interpolation: cubic
> alpha=1.000000e-04
> maxstep=1.000000e+08, minlambda=1.000000e-12
> tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08
> maximum iterations=40
> KSP Object: 1 MPI processes
> type: gmres
> restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement
> happy breakdown tolerance 1e-30
> maximum iterations=10000, initial guess is zero
> tolerances: relative=1e-05, absolute=1e-50, divergence=10000.
> left preconditioning
> using PRECONDITIONED norm type for convergence test
> PC Object: 1 MPI processes
> type: lu
> out-of-place factorization
> tolerance for zero pivot 2.22045e-14
> matrix ordering: nd
> factor fill ratio given 5., needed 2.84376
> Factored matrix follows:
> Mat Object: 1 MPI processes
> type: seqaij rows=528, cols=528
> package used to perform factorization: petsc
> total: nonzeros=7863, allocated nonzeros=7863
> total number of mallocs used during MatSetValues calls=0
> not using I-node routines
> linear system matrix = precond matrix:
> Mat Object: 1 MPI processes
> type: seqaij rows=528, cols=528
> total: nonzeros=2765, allocated nonzeros=5280
> total number of mallocs used during MatSetValues calls=0
> not using I-node routines
> Timestep 1:
> CurrentTime 0.:
> 1 TS dt 1. time 0.
>
> Number of timesteps = 1 final time 0.00e+00
>
> After the first time step, the program directly ends the TS solution process. I've set up 50 time steps, so the program is not running properly.
> Although the program accepted that first time step SNES did not achieve convergence, and there is no error information, but did not continue to go to the next time step calculation, chose to end the program. I hope that when the SNES not converge at a certain time step and reaches the set maximum number SNES iteration steps, it can go to the next time step calculation.
> I am looking forward to your suggestion.
>
> Thanks,
> Yingjie
>
> Zhang, Hong <hongzhang at anl.gov<mailto:hongzhang at anl.gov>> 于2020年4月29日周三 下午11:26写道:
> Please send the list of your command line options and the screen output with -ts_monitor.
>
> Hong (Mr.)
>
>> On Apr 28, 2020, at 11:00 PM, Yingjie Wu <yjwu16 at gmail.com<mailto:yjwu16 at gmail.com>> wrote:
>>
>> Thank you very much for your reply.
>> I tried both switches, but unfortunately they didn't seem to meet my needs.
>> -ts_adapt_always_accept
>> The switch doesn't seem to work, reporting errors
>> when the maximum number of steps is reached without convergence, then the program exits.
>>
>> -ts_error_if_step_fails 0 This switch accepts the non-convergence time step and outputs the result, but does not continue into the next time step calculation (
>>
>> The time step hasn't reached the maximum time step I set
>> ).
>>
>> And I wonder if the variable behind this switch is optional? What does it mean?
>> I hope to achieve in the case of non-convergence Newton step( for example, the maximum number of Newton iteration steps reached -snes_max_it 50), can go in the next time step calculation.
>>
>> Thanks,
>> Yingjie
>>
>> Zhang, Hong <hongzhang at anl.gov<mailto:hongzhang at anl.gov>> 于2020年4月28日周二 下午10:51写道:
>> -ts_error_if_step_fails 0
>>
>> You might want to find out why the nonlinear solver does not converge first. If you have a hand-written Jacobian, you can validate it with -snes_test_jacobian 1 (for a small test case).
>>
>> Hong (Mr.)
>>
>> > On Apr 28, 2020, at 8:21 AM, Yingjie Wu <yjwu16 at gmail.com<mailto:yjwu16 at gmail.com>> wrote:
>> >
>> > Dear PETSc developers
>> > Hi,
>> >
>> > I have recently used TS to solve nonlinear equations with time terms. since the convergence of my model is not very good, i would like to set to iterative fixed nonlinear steps per time step. If the problem does not meet the SNES convergence criteria after fixed number of nonlinear steps , then go to the next time step calculation. I tried -snes_max_it , but didn't achieve the effect I wanted, and the program stopped after iterating the fixed number of steps. How should I set up in the program?
>> >
>> > Thanks,
>> > Yingjie
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200430/340abf09/attachment-0001.html>
More information about the petsc-users
mailing list