<div dir="auto">I believe you need TSEvent <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetEventHandler.html">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetEventHandler.html</a></div><br><div class="gmail_quote"><div dir="ltr">Il giorno Ven 14 Dic 2018, 20:15 Zhang, Hong via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank" rel="noreferrer">petsc-users@mcs.anl.gov</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Dec 14, 2018, at 10:28 AM, <a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a> wrote:<br>
> <br>
> Hello, <br>
> thank you this seems to be a reasonable explanation.<br>
> I will try this for my "steady" phases.<br>
> I have also phases where my Neumann boundary conditions change with time (in my real application, here I uses constant conditions), in this time I also need the results at exact time points.<br>
> Can I get these without setting explicit end times?<br>
<br>
Are you asking how to terminate the time integration during TSSolve()? If so, one thing you can try is to call TSSetConvergedReason() in your TSPostStep() when certain criteria is met.<br>
<br>
Hong <br>
<br>
<br>
<br>
> Best Regards,<br>
> Moritz<br>
> <br>
> <br>
> -----Ursprüngliche Nachricht-----<br>
> Von: Zhang, Hong <<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a>> <br>
> Gesendet: Freitag, 14. Dezember 2018 17:13<br>
> An: Huck, Moritz <<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>><br>
> Cc: petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
> Betreff: Re: [petsc-users] Solution "jumps" after setting timestep<br>
> <br>
> <br>
> <br>
>> On Dec 14, 2018, at 5:16 AM, <a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a> wrote:<br>
>> <br>
>> Correction.<br>
>> Not exactly more like this<br>
>> While t<2<br>
>> t=TSGetTime<br>
>> h=TSGetTimeStep<br>
>> TSSetMaxTime(min(t+h,2)<br>
>> TSSolve<br>
>> t=TSGetTime<br>
>> TSSetMaxTime(t+1e-3)<br>
>> TSSolve<br>
>> While t<10<br>
>> t=TSGetTime<br>
>> h=TSGetTimeStep<br>
>> TSSetMaxTime(min(t+h,10)<br>
>> TSSolve<br>
>> <br>
>> @Hong<br>
>> No did not reset the time. Shouldn’t the time already 2 in this case?<br>
> <br>
> My mistake. The time looks fine. Now I understand what your code does.<br>
> <br>
> You might want to use TSSetTimeStep() to change the step size and there is no need to have loops. You can define a TSPostStep function and call TSSolve() just once. When solving a DAE, each call to TSSolve() would trigger a restart step internally to calculate an initial slope for the DAE. I suspect that the jump was caused by these restart steps.<br>
> <br>
> Hong <br>
> <br>
>> -----Ursprüngliche Nachricht-----<br>
>> Von: petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users-bounces@mcs.anl.gov</a>> Im Auftrag von <br>
>> Moritz.Huck--- via petsc-users<br>
>> Gesendet: Freitag, 14. Dezember 2018 12:06<br>
>> An: Emil Constantinescu <<a href="mailto:emconsta@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">emconsta@mcs.anl.gov</a>>; Zhang, Hong <br>
>> <<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a>><br>
>> Cc: petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
>> Betreff: Re: [petsc-users] Solution "jumps" after setting timestep<br>
>> <br>
>> In this example yes.<br>
>> <br>
>> -----Ursprüngliche Nachricht-----<br>
>> Von: Emil Constantinescu <<a href="mailto:emconsta@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">emconsta@mcs.anl.gov</a>><br>
>> Gesendet: Donnerstag, 13. Dezember 2018 20:21<br>
>> An: Zhang, Hong <<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a>>; Huck, Moritz <br>
>> <<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>><br>
>> Cc: petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
>> Betreff: Re: [petsc-users] Solution "jumps" after setting timestep<br>
>> <br>
>> Okay, so you start your integration with "TSSetMaxTime and then call TSSolve (TSSetExactFinalTime is set to TS_EXACTFINALTIME_MATCHSTEP)"<br>
>> <br>
>> Then after it's done at t=2 you tell TS that TSSetTimeStep(ts,1e-3) and call TSSolve again?<br>
>> <br>
>> Emil<br>
>> <br>
>> <br>
>> <br>
>> On 12/13/18 11:36 AM, Zhang, Hong via petsc-users wrote:<br>
>>> Please make sure your messages go to petsc-users when replying.<br>
>>> <br>
>>>> On Dec 13, 2018, at 11:25 AM, <a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a> <br>
>>>> <mailto:<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>> wrote:<br>
>>>> <br>
>>>> The first solve to 1e-3<br>
>>>> TSAdapt basic arkimex 0:1bee step 0 rejected t=0 +<br>
>>>> 1.000e-03 dt=1.000e-04 wlte= 102 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:1bee step 0 rejected t=0 +<br>
>>>> 1.000e-04 dt=1.000e-05 wlte= 127 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:1bee step 0 rejected t=0 +<br>
>>>> 1.000e-05 dt=1.995e-06 wlte= 5.09 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:1bee step 0 accepted t=0 +<br>
>>>> 1.995e-06 dt=3.232e-06 wlte=0.309 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 1 accepted t=1.99488e-06+<br>
>>>> 3.232e-06 dt=3.232e-05 wlte=1.65e-06 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 2 accepted t=5.22663e-06+<br>
>>>> 3.232e-05 dt=3.232e-04 wlte=3.96e-05 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 3 accepted t=3.75441e-05+<br>
>>>> 3.232e-04 dt=6.393e-04 wlte=0.000973 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 4 accepted t=0.000360719+<br>
>>>> 6.393e-04 dt=2.962e-03 wlte=0.00142 wltea= -1 wlter= -1 the <br>
>>>> solve steps afterwards:<br>
>>>> TSAdapt basic arkimex 0:4 step 5 accepted t=0.001 +<br>
>>>> 2.962e-03 dt=7.110e-03 wlte=0.0197 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 6 accepted t=0.00396151 +<br>
>>>> 7.110e-03 dt=2.489e-02 wlte=0.00437 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 7 accepted t=0.0110717 +<br>
>>>> 2.489e-02 dt=7.079e-02 wlte= 0.01 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 8 accepted t=0.03596 +<br>
>>>> 7.079e-02 dt=9.672e-02 wlte=0.188 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 9 accepted t=0.106753 +<br>
>>>> 9.672e-02 dt=1.329e-01 wlte=0.184 wltea= -1 wlter= -1 around <br>
>>>> here it reaches a steady state<br>
>>>> TSAdapt basic arkimex 0:4 step 10 accepted t=0.203478 +<br>
>>>> 1.329e-01 dt=2.432e-01 wlte=0.0586 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 11 accepted t=0.336424 +<br>
>>>> 2.432e-01 dt=4.536e-01 wlte=0.0542 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 12 accepted t=0.579616 +<br>
>>>> 4.536e-01 dt=1.112e+00 wlte=0.0182 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 13 accepted t=1.03324 +<br>
>>>> 9.668e-01 dt=3.286e+00 wlte=0.00492 wltea= -1 wlter= -1 here I <br>
>>>> set the timestep to 1e-3 artificially and the solution deviates from <br>
>>>> the steady state solution<br>
>>> <br>
>>> The TS time jumps between step 13 and step 14, which is probably the <br>
>>> cause of the jump in the solution.<br>
>>> Did you reset the time to t=2 by calling TSSetTime() after step 13?<br>
>>> <br>
>>> Hong<br>
>>> <br>
>>>> TSAdapt basic arkimex 0:4 step 14 accepted t=2 +<br>
>>>> 1.000e-03 dt=3.845e-03 wlte=0.003 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 15 accepted t=2.001 +<br>
>>>> 3.845e-03 dt=3.845e-02 wlte=6.95e-06 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 16 accepted t=2.00485 +<br>
>>>> 3.845e-02 dt=3.845e-01 wlte=4.31e-05 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 17 accepted t=2.0433 +<br>
>>>> 3.845e-01 dt=2.473e+00 wlte=0.000384 wltea= -1 wlter= -1<br>
>>>> TSAdapt basic arkimex 0:4 step 18 accepted t=2.42784 +<br>
>>>> 2.473e+00 dt=4.540e+00 wlte=0.0578 wltea= -1 wlter= -1 this <br>
>>>> point is "back on track"<br>
>>>> TSAdapt basic arkimex 0:4 step 19 accepted t=4.90058 +<br>
>>>> 4.540e+00 dt=4.649e+00 wlte=0.596 wltea= -1 wlter= -1 <br>
>>>> *Von:*Zhang, Hong <<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a> <mailto:<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a>>> <br>
>>>> *Gesendet:*Donnerstag, 13. Dezember 2018 17:39 *An:*Huck, Moritz <br>
>>>> <<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a> <br>
>>>> <mailto:<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>>><br>
>>>> *Cc:*<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a> <mailto:<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
>>>> *Betreff:*Re: [petsc-users] Solution "jumps" after setting timestep <br>
>>>> Can you show the outputs of -ts_monitor for both cases (one with <br>
>>>> oscillations and one without)?<br>
>>>> Thanks,<br>
>>>> Hong<br>
>>>> <br>
>>>> <br>
>>>> On Dec 13, 2018, at 9:48 AM,<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a><br>
>>>> <mailto:<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>>wrote:<br>
>>>> Hi,<br>
>>>> Sure after reaching a steady state it looks like this:<br>
>>>> 0 SNES Function norm 3.767377637168e-03<br>
>>>> 1 SNES Function norm 2.529971638368e-05<br>
>>>> 2 SNES Function norm 4.433873358247e-09<br>
>>>> 3 SNES Function norm 4.535675922104e-11<br>
>>>> 0 SNES Function norm 9.898938706929e-04<br>
>>>> 1 SNES Function norm 1.322473621975e-05<br>
>>>> 2 SNES Function norm 1.672724799379e-09<br>
>>>> 3 SNES Function norm 1.338501638801e-11<br>
>>>> 0 SNES Function norm 1.624500221071e-03<br>
>>>> 1 SNES Function norm 2.448515345247e-05<br>
>>>> 2 SNES Function norm 6.225549426481e-09<br>
>>>> 3 SNES Function norm 1.062516222150e-10<br>
>>>> 4 SNES Function norm 6.493758120241e-13<br>
>>>> 0 SNES Function norm 1.106311709708e-03<br>
>>>> 1 SNES Function norm 2.475673243430e-05<br>
>>>> 2 SNES Function norm 9.969586735411e-09<br>
>>>> 3 SNES Function norm 2.479591395229e-10<br>
>>>> 4 SNES Function norm 1.542689576708e-12<br>
>>>> 0 SNES Function norm 6.070943996748e-04<br>
>>>> 1 SNES Function norm 1.648134285171e-05<br>
>>>> 2 SNES Function norm 8.461078655420e-09<br>
>>>> 3 SNES Function norm 2.480863447790e-10<br>
>>>> 4 SNES Function norm 1.513977618851e-12<br>
>>>> TSAdapt basic arkimex 0:4 step 15 accepted t=5.67201 +<br>
>>>> 4.328e+00 dt=4.687e+00 wlte$<br>
>>>> 0.477 wltea= -1 wlter= -1<br>
>>>> If I set the next target time (in tssolve) to be tlast+1e-3 it<br>
>>>> looks like this:<br>
>>>> 0 SNES Function norm 4.734802409365e-03<br>
>>>> 1 SNES Function norm 6.173939866359e-13<br>
>>>> 0 SNES Function norm 5.633294284900e-04<br>
>>>> 1 SNES Function norm 3.575533754564e-13<br>
>>>> 0 SNES Function norm 9.651618110271e-04<br>
>>>> 1 SNES Function norm 6.863177319359e-13<br>
>>>> 0 SNES Function norm 7.706102281617e-04<br>
>>>> 1 SNES Function norm 8.490865565002e-13<br>
>>>> 0 SNES Function norm 5.028108294534e-04<br>
>>>> 1 SNES Function norm 6.905750968862e-13<br>
>>>> TSAdapt basic arkimex 0:4 step 16 accepted t=10 +<br>
>>>> 1.000e-03 dt=2.612e-03 wlte$<br>
>>>> 0.0141 wltea= -1 wlter= -1<br>
>>>> The SNES solver has a atoll of 1e-10, setting the atoll to lower<br>
>>>> values does not change the result.<br>
>>>> Thank you,<br>
>>>> Moritz<br>
>>>> *Von:*Zhang, Hong <<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a> <mailto:<a href="mailto:hongzhang@anl.gov" rel="noreferrer noreferrer" target="_blank">hongzhang@anl.gov</a>>><br>
>>>> *Gesendet:*Donnerstag, 13. Dezember 2018 16:42<br>
>>>> *An:*Huck, Moritz <<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a><br>
>>>> <mailto:<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>>><br>
>>>> *Cc:*<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a> <mailto:<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
>>>> *Betreff:*Re: [petsc-users] Solution "jumps" after setting timestep<br>
>>>> Can you please add command line options -ts_monitor -snes_monitor<br>
>>>> and show us the outputs?<br>
>>>> Thanks,<br>
>>>> Hong (Mr.)<br>
>>>> <br>
>>>> <br>
>>>> <br>
>>>> On Nov 4, 2018, at 6:19 AM, Moritz.Huck--- via petsc-users<br>
>>>> <<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a> <mailto:<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>>> wrote:<br>
>>>> Hi,<br>
>>>> <br>
>>>> I using the basic adaptor.<br>
>>>> If I let the adaptor handle everything it does not oscillates.<br>
>>>> I don’t mean setting the timestep at the start (which does not<br>
>>>> produces the<br>
>>>> problem),<br>
>>>> I need to set during runtime between two steps.<br>
>>>> <br>
>>>> Best Regards,<br>
>>>> <br>
>>>> Moritz<br>
>>>> <br>
>>>> -----Ursprüngliche Nachricht-----<br>
>>>> Von: Constantinescu, Emil M. <<a href="mailto:emconsta@anl.gov" rel="noreferrer noreferrer" target="_blank">emconsta@anl.gov</a><br>
>>>> <mailto:<a href="mailto:emconsta@anl.gov" rel="noreferrer noreferrer" target="_blank">emconsta@anl.gov</a>>><br>
>>>> Gesendet: Samstag, 3. November 2018 15:43<br>
>>>> An: Huck, Moritz <<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a><br>
>>>> <mailto:<a href="mailto:Moritz.Huck@isea.rwth-aachen.de" rel="noreferrer noreferrer" target="_blank">Moritz.Huck@isea.rwth-aachen.de</a>>>;<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a><br>
>>>> <mailto:<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>><br>
>>>> Betreff: Re: [petsc-users] Solution "jumps" after setting <br>
>>>> timestep<br>
>>>> <br>
>>>> On 11/3/18 4:56 AM, Moritz.Huck--- via petsc-users wrote:<br>
>>>> <br>
>>>> <br>
>>>> Hi,<br>
>>>> <br>
>>>> I am using the IMEX Runge Kutta to solve an implicit DAE<br>
>>>> (G=0).<br>
>>>> <br>
>>>> When I manually set the time step (TSSetTimestep) my<br>
>>>> solution jumps.<br>
>>>> <br>
>>>> <br>
>>>> When you don't set the time step, does it still oscillates? If<br>
>>>> not, can you<br>
>>>> check if it oscillates when reducing the fixed initial time step?<br>
>>>> Did you turn the adaptivity off (-ts_adapt_type none)?<br>
>>>> <br>
>>>> Emil<br>
>>>> <br>
>>>> <br>
>>>> <br>
>>>> <br>
>>>> If I go from a steady state to the same state, it<br>
>>>> oscillates a few<br>
>>>> time and comes back to the steady solution.<br>
>>>> <br>
>>>> Can this be prevented?<br>
>>>> <br>
>>>> Thank you,<br>
>>>> <br>
>>>> Moritz<br>
>>>> <br>
>>> <br>
> <br>
<br>
</blockquote></div>