<div dir="ltr">Hi Barry,<div><br></div><div>I haven't had time to look into TS so far. But it is definitely interesting. One simple question would like this: If I have a simple loop for time steppers, and each step SNES is called. How hard to convert my code to use TS? </div><div><br></div><div>Any suggestion? Where should I start from?</div><div><br></div><div><br></div><div>Fande,</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 30, 2018 at 11:29 AM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Note also that the PETSc TS component has a large variety of timesteppers with automatic adaptivity which adjust the time-step for accuracy and convergence. Depending on the exact needs of your time-stepper it might be easier in the long run to use PETSc's time-steppers rather than write your own.<br>
<br>
Barry<br>
<br>
<br>
> On Aug 30, 2018, at 10:46 AM, Ling Zou <<a href="mailto:Ling.Zou@inl.gov" target="_blank">Ling.Zou@inl.gov</a>> wrote:<br>
> <br>
> Rahul, please see the logic I used to reduce time step size.<br>
> Hope this helps you.<br>
> <br>
> Ling<br>
> <br>
> for (timestep = 1; timestep <= N; timestep++) // loop over time steps<br>
> {<br>
> // before trying to solve a time step, 1) it is still not successful; 2) we are not giving up; 3) haven't failed yet<br>
> bool give_up = false; bool success = false; bool experienced_fail_this_time_step = false;<br>
> // 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<br>
> VecCopy(u, u_copy); VecCopy(u_old, u_old_copy);<br>
> <br>
> while ((!give_up) && (!success)) // as long as not successful and not giving up, we solve again with smaller time step<br>
> {<br>
> 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<br>
> 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<br>
> VecCopy(u_old_copy, u); VecCopy(u_old_copy, u_old);<br>
> }<br>
> <br>
> try {<br>
> SNESSolve(snes, NULL, u);<br>
> SNESGetConvergedReason(snes, &snes_converged_reason);<br>
> <br>
> if (snes_converged_reason > 0) success = true; // yes, snes converged<br>
> else { // no, snes did not converge<br>
> cutTimeStepSize(); // e.g., dt / 2<br>
> experienced_fail_this_time_step = true;<br>
> }<br>
> }<br>
> catch (int err) { // in case your own pieces of code throws an exception<br>
> std::cout << "An exception occurred." << std::endl;<br>
> success = false;<br>
> cutTimeStepSize(); // e.g., dt / 2<br>
> experienced_fail_this_time_step = true;<br>
> }<br>
> }<br>
> <br>
> if (success) {<br>
> // output, print, whatever<br>
> // duplicate current solution to old solution in preparing next time step<br>
> VecCopy(u, u_old);<br>
> // you can increase time step size here, e.g. * 2<br>
> increaseTimeStepSize();<br>
> }<br>
> <br>
> if (give_up) {<br>
> simulationFailed = true;<br>
> std::cerr << "Simulation failed.\n";<br>
> //exit(1);// dont exit(1) now, just break the for-loop, let PETSc clean its workspace.<br>
> break;<br>
> }<br>
> }<br>
> <br>
> From: Rahul Samala <<a href="mailto:srahul_05@yahoo.co.in" target="_blank">srahul_05@yahoo.co.in</a>><br>
> Sent: Wednesday, August 29, 2018 10:37:30 PM<br>
> To: Ling Zou; Smith, Barry F.<br>
> Cc: PETSc Users List<br>
> Subject: Re: [petsc-users] Problem with SNES convergence<br>
> <br>
> Thank you Ling, I would definitely like to look at your code for reducing timestep size.<br>
> Thank you Barry for your inputs.<br>
> <br>
> --<br>
> Rahul.<br>
> <br>
> On Wednesday, August 29, 2018, 9:02:00 PM GMT+5:30, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
> <br>
> <br>
> <br>
> Current time (before start of timestep) 52.5048, iter=5380 Timestep=864.000000 <br>
> 0 SNES Function norm 1.650467412595e+05 <br>
> 0 KSP preconditioned resid norm 3.979123221160e+03 true resid norm 1.650467412595e+05 ||r(i)||/||b|| 1.000000000000e+00<br>
> 1 KSP preconditioned resid norm 9.178246525982e-11 true resid norm 7.006473307032e-09 ||r(i)||/||b|| 4.245144892632e-14<br>
> Linear solve converged due to CONVERGED_RTOL iterations 1<br>
> 1 SNES Function norm 6.722712947273e+02 <br>
> Linear solve did not converge due to DIVERGED_NANORINF iterations 0<br>
> Nonlinear solve did not converge due to DIVERGED_LINEAR_SOLVE iterations 1<br>
> <br>
> 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>
> <br>
> 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>
> <br>
> Good luck,<br>
> <br>
> Barry<br>
> <br>
> <br>
> > On Aug 29, 2018, at 10:11 AM, Ling Zou <<a href="mailto:Ling.Zou@inl.gov" target="_blank">Ling.Zou@inl.gov</a>> wrote:<br>
> > <br>
> > 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>
> > 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>
> > <br>
> > -Ling<br>
> > From: petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Rahul Samala <<a href="mailto:srahul_05@yahoo.co.in" target="_blank">srahul_05@yahoo.co.in</a>><br>
> > Sent: Wednesday, August 29, 2018 8:36:58 AM<br>
> > To: PETSc Users List<br>
> > Subject: [petsc-users] Problem with SNES convergence<br>
> > <br>
> > Hello PetSc users,<br>
> > <br>
> > 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>
> > <br>
> > 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>
> > <br>
> > Thank you,<br>
> > Rahul.<br>
> > <br>
> > output_ilu.txt<br>
> > <br>
> > <br>
> > output_ilu.txt<br>
> > <br>
> > <br>
> > <br>
> > output_lu.txt<br>
> > <br>
> > <br>
> > output_lu.txt<br>
<br>
</blockquote></div>