<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 30, 2020, at 2:05 PM, Salazar De Troya, Miguel <<a href="mailto:salazardetro1@llnl.gov" class="">salazardetro1@llnl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks. I see the example in petsc (<a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ts/tutorials/ex40.c.html" style="color: blue; text-decoration: underline;" class="">https://www.mcs.anl.gov/petsc/petsc-current/src/ts/tutorials/ex40.c.html</a>) modifies the solution vector in the PostEventFunction(), but there is no straightforward way to modify the RHSFunction(). Can one call TSSetRHSFunction() inside PostEventFunction() and set it for another routine? Maybe one can just change a variable in the context which is also used in the original RHSFunction(). Even if I could, such a sudden change in the RHS can make the current solution oscillate heavily. Will the TS solver adapt the time step to accommodate for this drastic change?</div></div></div></blockquote><div><br class=""></div> You should be able to do any of those things to change the function.</div><div><br class=""></div><div> Since PETSc uses multi-stage methods after the event is detected the new ODE is now solved with an initial time of the located event time so it will just start solving the new ODE "from scratch" and hence won't see the old ODE so I don't think the solution should oscillate (unless your new ODE has large oscillations and needs a much smaller time step), if you need a smaller time step after the event then you can just set the new smaller tilmestep in your post event function.</div><div><br class=""></div><div> Barry</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Miguel<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0in 0in;" class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class=""><span style="font-size: 12pt;" class="">From:<span class="Apple-converted-space"> </span></span></b><span style="font-size: 12pt;" class="">Barry Smith <<a href="mailto:bsmith@petsc.dev" style="color: blue; text-decoration: underline;" class="">bsmith@petsc.dev</a>><br class=""><b class="">Date:<span class="Apple-converted-space"> </span></b>Wednesday, September 30, 2020 at 10:19 AM<br class=""><b class="">To:<span class="Apple-converted-space"> </span></b>"Salazar De Troya, Miguel" <<a href="mailto:salazardetro1@llnl.gov" style="color: blue; text-decoration: underline;" class="">salazardetro1@llnl.gov</a>>, "Abhyankar, Shrirang G" <<a href="mailto:shrirang.abhyankar@pnnl.gov" style="color: blue; text-decoration: underline;" class="">shrirang.abhyankar@pnnl.gov</a>>, Emil Constantinescu <<a href="mailto:emconsta@mcs.anl.gov" style="color: blue; text-decoration: underline;" class="">emconsta@mcs.anl.gov</a>><br class=""><b class="">Cc:<span class="Apple-converted-space"> </span></b>Satish Balay via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" style="color: blue; text-decoration: underline;" class="">petsc-users@mcs.anl.gov</a>><br class=""><b class="">Subject:<span class="Apple-converted-space"> </span></b>Re: [petsc-users] Adaptive time stepping for implicit solvers<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> You might consider using the Event feature of TS to manage this. It detects when your "indicator function" changes sign and stops the integration right at that point allowing you to change your ODE or do what ever you need. It allows managing discontinuous changes in the ODE without needing smoothing (that messes up the solution). <o:p class=""></o:p></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> You would write an indicator function that depends on "solution of heat equation equal to a given parameter"<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I am including Shri and Emil on this message because they understand the event handling the best (Shri wrote it).<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> Barry<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite"><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On Sep 30, 2020, at 11:58 AM, Salazar De Troya, Miguel via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" style="color: blue; text-decoration: underline;" class="">petsc-users@mcs.anl.gov</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hello,<span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I have a heat equation with a right-hand side coefficient that changes sign when a certain condition is met (solution of heat equation equal to a given parameter). I am thinking of modeling the sign change with a smoothed-out Heaviside approximation and let the solver adjust the time step to capture the sudden transition. Given that it is a heat equation, I am interested in using an implicit solver. Which ones in the TS suite also have adaptive capabilities?<span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks<span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Miguel<span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="ES" style="font-size: 9pt; font-family: Consolas;" class="">Miguel A. Salazar de Troya</span><span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div><div class=""><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9pt; font-family: Consolas;" class="">Postdoctoral Researcher, Lawrence Livermore National Laboratory</span><span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9pt; font-family: Consolas;" class="">B141</span><span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9pt; font-family: Consolas;" class="">Rm: 1085-5</span><span style="font-size: 12pt;" class=""><o:p class=""></o:p></span></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9pt; font-family: Consolas;" class="">Ph: 1(925) 422-6411</span></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>