<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Rahul, please see the logic I used to reduce time step size.</p>
<p style="margin-top:0;margin-bottom:0">Hope this helps you.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Ling</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div><span style="font-family: Consolas, Courier, monospace;">for (timestep = 1; timestep <= N; timestep++) // loop over time steps</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">{</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> // before trying to solve a time step, 1) it is still not successful; 2) we are not giving up; 3) haven't failed yet</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> bool give_up = false; bool success = false; bool experienced_fail_this_time_step = false;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> // save solutions and old solutions into u_copy and u_old_copy, in case a time step fails and we restart from this saved solutions</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> VecCopy(u, u_copy); VecCopy(u_old, u_old_copy);</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;"> while ((!give_up) && (!success)) // as long as not successful and not giving up, we solve again with smaller time step</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> {</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> if (time_step_size < dt_min) { give_up = true; break; } // ok, bad luck, give up due to time step size smaller than a preset value</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> if (experienced_fail_this_time_step) { // get the vectors from backups if this is a re-try, i.e., already failed with a larger time step</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> VecCopy(u_old_copy, u); VecCopy(u_old_copy, u_old);</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;"> try {</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> SNESSolve(snes, NULL, u);</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> SNESGetConvergedReason(snes, &snes_converged_reason);</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;"> if (snes_converged_reason > 0) success = true; // yes, snes converged</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> else { // no, snes did not converge</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> cutTimeStepSize(); // e.g., dt / 2</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> experienced_fail_this_time_step = true;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> catch (int err) { // in case your own pieces of code throws an exception</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> std::cout << "An exception occurred." << std::endl;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> success = false;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> cutTimeStepSize(); // e.g., dt / 2</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> experienced_fail_this_time_step = true;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;"> if (success) {</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> // output, print, whatever</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> // duplicate current solution to old solution in preparing next time step</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> VecCopy(u, u_old);</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> // you can increase time step size here, e.g. * 2</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> increaseTimeStepSize();</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;"> if (give_up) {</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> simulationFailed = true;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> std::cerr << "Simulation failed.\n";</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> //exit(1);// dont exit(1) now, just break the for-loop, let PETSc clean its workspace.</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> break;</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> }</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">}</span></div>
<br>
<p></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Rahul Samala <srahul_05@yahoo.co.in><br>
<b>Sent:</b> Wednesday, August 29, 2018 10:37:30 PM<br>
<b>To:</b> Ling Zou; Smith, Barry F.<br>
<b>Cc:</b> PETSc Users List<br>
<b>Subject:</b> Re: [petsc-users] Problem with SNES convergence</font>
<div> </div>
</div>
<meta content="text/html; charset=utf-8">
<div>
<div style="font-family:garamond,new york,times,serif; font-size:13px">
<div>Thank you Ling, I would definitely like to look at your code for reducing timestep size.</div>
<div>Thank you Barry for your inputs.</div>
<div><br>
</div>
<div>--</div>
<div>Rahul.<br>
</div>
<div><br>
</div>
<div id="x_yahoo_quoted_6410304017" class="x_yahoo_quoted">
<div style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size:13px; color:#26282a">
<div>On Wednesday, August 29, 2018, 9:02:00 PM GMT+5:30, Smith, Barry F. <bsmith@mcs.anl.gov> wrote:
</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div dir="ltr"><br clear="none">
Current time (before start of timestep) 52.5048, iter=5380 Timestep=864.000000
<br clear="none">
0 SNES Function norm 1.650467412595e+05 <br clear="none">
0 KSP preconditioned resid norm 3.979123221160e+03 true resid norm 1.650467412595e+05 ||r(i)||/||b|| 1.000000000000e+00<br clear="none">
1 KSP preconditioned resid norm 9.178246525982e-11 true resid norm 7.006473307032e-09 ||r(i)||/||b|| 4.245144892632e-14<br clear="none">
Linear solve converged due to CONVERGED_RTOL iterations 1<br clear="none">
1 SNES Function norm 6.722712947273e+02 <br clear="none">
Linear solve did not converge due to DIVERGED_NANORINF iterations 0<br clear="none">
Nonlinear solve did not converge due to DIVERGED_LINEAR_SOLVE iterations 1<br clear="none">
<br clear="none">
This usually is an indicator that the LU (ILU) factorization has hit a zero pivot (hence the linear solve has a divide by zero so gives the DIVERGED_NANORINF flag).
<br clear="none">
<br clear="none">
You can/should call SNESGetConvergedReason() immediately after each SNESSolve(), if the result is negative that means something has failed in the nonlinear solve and you can try cutting the time-step and trying again.<br clear="none">
<br clear="none">
Good luck,<br clear="none">
<br clear="none">
Barry<br clear="none">
<br clear="none">
<div class="x_yqt1765626742" id="x_yqtfd14853"><br clear="none">
> On Aug 29, 2018, at 10:11 AM, Ling Zou <<a shape="rect" href="mailto:Ling.Zou@inl.gov">Ling.Zou@inl.gov</a>> wrote:<br clear="none">
> <br clear="none">
> 1) My experience is that this kind of bug or sudden death (everything is fine till suddenly something is broken) is very difficult to debug/fix. I looked at your txt files and could not give any quick comments. Maybe PETSc developers have better idea on this.<br clear="none">
> 2) I do have successful experience on reducing time step size when PETSc fails solving or my own piece of code throws an exception. If you are interested, I can share them.<br clear="none">
> <br clear="none">
> -Ling<br clear="none">
> From: petsc-users <<a shape="rect" href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Rahul Samala <<a shape="rect" href="mailto:srahul_05@yahoo.co.in">srahul_05@yahoo.co.in</a>><br clear="none">
> Sent: Wednesday, August 29, 2018 8:36:58 AM<br clear="none">
> To: PETSc Users List<br clear="none">
> Subject: [petsc-users] Problem with SNES convergence<br clear="none">
> <br clear="none">
> Hello PetSc users,<br clear="none">
> <br clear="none">
> 1) I have problem with SNES convergence. I call SNESSolve in a time loop and use the inbuilt Jacobian feature. The code works fine for about 5380 time steps after which it breaks down. The solution till that point looks fine. I have used newtonls of type
l2. (newtontr and others aren't working). Since I have used inbuilt Jacobian feature and the code worked for about 5000 time steps I don't understand the reason for failure, is it an incorrect function evaluation? Attached are the outputs with -pc_type lu
and ilu along with -snes_linesearch_type l2 -snes_converged_reason -snes_monitor -snes_view -ksp_converged_reason -ksp_monitor_true_residual<br clear="none">
> <br clear="none">
> 2) How to get hold of failure signal, like Nonlinear solve DIVERGED_MAX_IT or DIVERGED_LINEAR_SOLVE so that whenever it occurs I can use a reduced time step and see if the code converges.<br clear="none">
> <br clear="none">
> Thank you,<br clear="none">
> Rahul.<br clear="none">
> <br clear="none">
> output_ilu.txt<br clear="none">
> <br clear="none">
> <br clear="none">
> output_ilu.txt<br clear="none">
> <br clear="none">
> <br clear="none">
> <br clear="none">
> output_lu.txt<br clear="none">
> <br clear="none">
> <br clear="none">
> output_lu.txt<br clear="none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>