[petsc-users] Problem with TS and SNES VI

Huck, Moritz Moritz.Huck at rwth-aachen.de
Wed Aug 28 02:26:19 CDT 2019


Hi,
(since I'm using petsc4py and wasnot able to hook gdb correctly up, I am "debbuging" with prints)

I am using   TS_EQ_DAE_IMPLICIT_INDEX1    as equation type.
The out of  bounds values occur inside the SNES as well after a step has finished.
The occur first after a timestep and then "propgate" into the SNES.
The problem arises with bt, l2 or basic as linesearch.
It seems to occur with ARKIMEX(3,4,5) but not with  ARKIMEX(L2,A2) or BDF (but these have to use much lower time steps), for the later SNESVI also works for bounding .

@Shri the event solution seems not work for me, if an lower bound crossing is detected the solver reduces the time step to a small value and doesnt reach the crossing in a reasonable time frame.

Best Regards,
Moritz




________________________________________
Von: Smith, Barry F. <bsmith at mcs.anl.gov>
Gesendet: Dienstag, 13. August 2019 05:58:29
An: Huck, Moritz
Cc: Abhyankar, Shrirang G; petsc-users at mcs.anl.gov
Betreff: Re: [petsc-users] Problem with TS and SNES VI

> On Aug 12, 2019, at 10:25 AM, Huck, Moritz <Moritz.Huck at rwth-aachen.de> wrote:
>
> Hi,
> at the moment I am trying the Precheck version (I will try the event one afterwards).
> My precheckfunction is (pseudo code):
> precheckfunction(Vec X,Vec Y,PetscBool *changed){
> if any(X+Y<lowerbound)
> *changed=True
> Y[where(X+Y<lowerbound)]=lowerbound-X
> }
> Inside precheck around 10-20 occurences of X+Y<lowerbound but in IFunction call there are about 200-250 occurences of X<lowerbound.

  In what IFunction calls are you getting all these occurrences?

> In my understanding this should not happen, since the precheck should be called before the IFunction call.

   For the nonlinear system solve once the precheck is done the new nonlinear solution approximation is computed via a line search

    X = X + lamba Y    where lambda > 0 and for most line searches lambda <=1 (for example the SNESLINESEARCHBT will always result in lambda <=1, I am not sure about the other line searchs)

  X_i = X_i + lambda (lowerbound - X_i) = X_i - lambda X_i  + lambda lowerbound = (1 - lambda) X_i + lambda lowerbound => (1 - lambda) lowerbound + lambda lowerbound = lowerbound

   Thus it seems you are correct, each step that the line search tries should satisfy the bounds.

   Possible issues:
1) the line search produces lambda > 1. Make sure you use SNESLINESEARCHBT

??? Here you would need to determine exactly when in the algorithm the IFunction is having as input  X < lower bound. Somewhere in the ARKIMEX integrator? Are you using fully implicit? You might need to use fully implicit in order to enforce the bound?

  What I would do is run in the debugger and have it stop inside IFunction when the lower bound is not satisfied. Then do bt to see where the code is, in what part of the algorithms. If inside the line search you'll need to poke around at the values to see why the step could produce something below the bound which in theory it shouldn't

  Good luck

  Barry



>
> ________________________________________
> Von: Abhyankar, Shrirang G <shrirang.abhyankar at pnnl.gov>
> Gesendet: Donnerstag, 8. August 2019 19:16:12
> An: Huck, Moritz; Smith, Barry F.
> Cc: petsc-users at mcs.anl.gov
> Betreff: Re: [petsc-users] Problem with TS and SNES VI
>
> Moritz,
>  I think your case will also work with using TSEvent. I think your problem is similar, correct me if I am wrong, to my application where I need to constrain the states within some limits, lb \le x. I use events to handle this, where I use two event functions:
> (i)                 x – lb = 0.      if x > lb &
> (ii)              \dot{x} = 0       x = lb
>
> The first event function is used to detect when x hits the limit lb. Once it hits the limit, the differential equation for x is changed to (x-lb = 0) in the model to hold x at limit lb. For releasing x, there is an event function on the derivative of x, \dot{x}, and x is released on detection of the condition \dot{x} > 0. This is done through the event function \dot{x} = 0 with a positive zero crossing.
>
> An example of how the above works is in the example src/ts/examples/tutorials/power_grid/stability_9bus/ex9bus.c. In this example, there is an event function that first checks whether the state VR has hit the upper limit VRMAX. Once it does so, the flag VRatmax is set by the post-event function. The event function is then switched to the \dot{VR}
> if (!VRatmax[i]))
>    fvalue[2+2*i] = VRMAX[i] - VR;
> } else {
>     fvalue[2+2*i] = (VR - KA[i]*RF + KA[i]*KF[i]*Efd/TF[i] - KA[i]*(Vref[i] - Vm))/TA[i];
> }
>
> You can either try TSEvent or what Barry suggested SNESLineSearchSetPreCheck(), or both.
>
> Thanks,
> Shri
>
>
> From: "Huck, Moritz" <Moritz.Huck at rwth-aachen.de>
> Date: Wednesday, August 7, 2019 at 8:46 AM
> To: "Smith, Barry F." <bsmith at mcs.anl.gov>
> Cc: "Abhyankar, Shrirang G" <shrirang.abhyankar at pnnl.gov>, "petsc-users at mcs.anl.gov" <petsc-users at mcs.anl.gov>
> Subject: AW: [petsc-users] Problem with TS and SNES VI
>
> Thank you for your response.
> The sizes are only allowed to go down to a certain value.
> The non-physical values do also occur during the function evaluations (IFunction).
>
> I will try to implment your suggestions with SNESLineSearchSetPreCheck. This would mean I dont have to use SNESVISetVariableBounds at all, right?
> ________________________________________
> Von: Smith, Barry F. <bsmith at mcs.anl.gov<mailto:bsmith at mcs.anl.gov>>
> Gesendet: Dienstag, 6. August 2019 17:47:13
> An: Huck, Moritz
> Cc: Abhyankar, Shrirang G; petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>
> Betreff: Re: [petsc-users] Problem with TS and SNES VI
>
>   Thanks, very useful.
>
>   Are the non-physical values appearing in the nonlinear solver ? Or just at the time-step?
>
>   Do you check for non-physical values each time you do a function evaluation needed by SNES/TS?
>
>   If the non-physical values are an artifact of the steps taken in the nonlinear solver in SNES then the correct solution is to use
> SNESLineSearchSetPreCheck() what you do is change the step so the resulting solutions are physical.
>
>   For you case where the sizes go negative I am not sure what to do. Are the sizes allowed to go to zero? If so then adjust the step so that the sizes that go to negative values just go to zero. If they are suppose to be always positive then you need to pick some tolerance (say epsilon) and adjust the step so they are of size epsilon. Note you don't scale the entire step vector by a small number to satisfy the constraint you change each entry in the step as needed to satisfy the constraints.
>
>   Good luck and let us know how it goes
>
>   Barry
>
>
>
> On Aug 6, 2019, at 9:24 AM, Huck, Moritz <Moritz.Huck at rwth-aachen.de<mailto:Moritz.Huck at rwth-aachen.de>> wrote:
>
> At the moment I output only the values at the actual time-step (with the poststep functionality), I dont know the values during the stages.
> Unphysical values are e.g. particle sizes below zero.
>
> My model as no explicit inequalities, the only handling of the constraints is done by setting SNES VI.
>
> The model does not change in the senes that there are new equations. If have put in an conditional that xdot is calculated to be positive of x is on or below the lower bound.
> ________________________________________
> Von: Smith, Barry F. <bsmith at mcs.anl.gov<mailto:bsmith at mcs.anl.gov>>
> Gesendet: Dienstag, 6. August 2019 15:51:16
> An: Huck, Moritz
> Cc: Abhyankar, Shrirang G; petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>
> Betreff: Re: [petsc-users] Problem with TS and SNES VI
>
>  Could you explain in a bit more detail what you mean by "some states go to unphysical values" ?
>
>  Is this within a stage or at the actual time-step after the stage?
>
>   Does you model explicitly have these bounds on the solution; i.e. it is imposed as a variational inequality or does the model not explicitly have the constraints because its "analytic" solution just naturally stays in the physical region anyways? But numerical it can go out?
>
>  Or, is your model suppose to "change" at a certain time, which you don't know in advance when the solution goes out of some predefined bounds" (this is where the event is designed for).
>
>   This information can help us determine what approach you should take.
>
>   Thanks
>
>   Barry
>
>
> On Aug 6, 2019, at 2:12 AM, Huck, Moritz via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:
>
> Hi,
> I think I am missing something here.
> How would events help to constrain the states.
> Do you mean to use the event to "pause" to integration an adjust the state manually?
> Or are the events to enforce smaller timesteps when the state come close to the constraints?
>
> Thank you,
> Moritz
> ________________________________________
> Von: Abhyankar, Shrirang G <shrirang.abhyankar at pnnl.gov<mailto:shrirang.abhyankar at pnnl.gov>>
> Gesendet: Montag, 5. August 2019 17:21:41
> An: Huck, Moritz; petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>
> Betreff: Re: [petsc-users] Problem with TS and SNES VI
>
> For problems with constraints on the states, I would recommend trying the event functionality, TSEvent, that allows detection and location of discrete events, such as one that you have in your problem.
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetEventHandler.html.
>
> An example using TSEvent functionality:  https://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/ex40.c.html
>
> A brief intro to TSEvent can be found here<https://www.mcs.anl.gov/petsc/petsc-20/conference/Abhyankar_S.pdf>.
>
> Thanks,
> Shri
>
>
> From: petsc-users <petsc-users-bounces at mcs.anl.gov<mailto:petsc-users-bounces at mcs.anl.gov>> on behalf of "Huck, Moritz via petsc-users" <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>>
> Reply-To: "Huck, Moritz" <Moritz.Huck at rwth-aachen.de<mailto:Moritz.Huck at rwth-aachen.de>>
> Date: Monday, August 5, 2019 at 5:18 AM
> To: "petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>" <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>>
> Subject: [petsc-users] Problem with TS and SNES VI
>
> Hi,
> I am trying to solve a DAE with the ARKIMEX solver, which works mostly fine.
> The problem arises when some states go to unphysical values. I try to constrain my states with SNESVISetVariableBounds (through the petsc4py interface).
> But TS seems not respect this e.g. I have a state with is usually between 1 and 1e3 for which I set a lower bound of 1, but the state goes t0 -0.8 at some points.
> Are there some tolerances I have to set for VI or something like this?
>
> Best Regards,
> Moritz



More information about the petsc-users mailing list