-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"[IDAS ERROR] IDAGetDky Illegal value for k." with event callbacks #292
Comments
The issue does not happen with Sundials 3.8.3. |
function cond1(u, t, integrator)
if (t < 1e1)
val = -1
else
val = 1
end
return val
end This doesn't make sense. The condition of a ContinuousCallback is supposed to be a rootfinding function, and this won't have a root. First of all, this should probably be a |
I wondered the same. Like I said the first post in Discourse, this problem is from Octave ode15i-function tests when Sundials is available in Octave. I am guessing that the event definitions are intended to be a "tough" case for the event finding and not a realistic problem. |
In our world, it's not a tough case but an ill-defined one. @kanav99 it would be interesting to somehow support non-root cases though. |
My guess is that the purpose of the discontinuous event function is to mimic some possible real world case where there would be need to differentiate two almost simultaneous events. Anyway, the discontinuity does not seem to be the issue.
and actually even with:
Both the above cases work correctly with Sundials 3.8.3 |
Saw your latest post. t-9 should be a zero-cross right? |
Yes, it should detect two events at t=9 and t=10. The first t=9 event is detected, the second is not, instead the IDA error is generated. |
SciML uses its own rootfinding because it fixes a few root misdetection issues. However, it always looks for the rootfinding 0. We haven't special-cased for the chance that the sign change is at a point which is not a zero, but a shift from -Inf to Inf. We can do that though. |
Oh just read the other message. That's... weird. And it's an interpolation issue that Sundials throws? That needs to be looked into. Maybe it's something to do with the reinitialization |
Below is the error: [IDAS ERROR] IDAGetDky ┌ Warning: IDAGetDky failed with error code = |
I'm experiencing the same, or a similar, issue. I want to simulate a hybrid DAE system with a zero-order-hold controller. I use ContinuousCallbacks for triggering jumps in the dynamics and a PeriodicCallback to run the controller. The attached example is a toy example. I realize that it is an ODE I am solving, and it does work fine to formulate as an ODEproblem and solve with Tsit5, in which case I have no issues with CallbackSets that combine ContinuousCallbaks and PeriodicCallbacks. However, I eventually want to simulate a DAE that is not an ODE. using DifferentialEquations
using Sundials
# ODE disquised as DAE
function dyns!(y,dx,x,p,t)
y[1] = dx[1] - x[1]
end
# xmin callback
xmin= -0.5
function xmin_cond(x,t,integrator)
x[1]-xmin
end
function xmin_affect_neg!(integrator)
integrator.u[1] = 0.01 # Reset x1. A bit confusing: integrator.u is x, DifferentialEquations reserves u for the state
end
xmin_cb = ContinuousCallback(xmin_cond,nothing,xmin_affect_neg!)
# xmax callback
xmax= 1.0
function xmax_cond(x,t,integrator)
-(x[1]-xmax)
end
function xmax_affect_neg!(integrator)
integrator.u[1] = -0.01 # Reset x1. A bit confusing: integrator.u is x, DifferentialEquations reserves u for the state
end
xmax_cb = ContinuousCallback(xmax_cond,nothing,xmax_affect_neg!)
# Nonsense ZOH controller with state in struct
mutable struct Controller_state
u
Controller_state() = new()
end
cs = Controller_state()
cs.u = 0.01
h = 1.0
function control_affect!(integrator)
#nothing
integrator.u[1] = 0.01
end
control_cb = PeriodicCallback(control_affect!,h)
# Initial state
x0 = [0.5]
dx0 = 0*x0
# Simulation time
tf=10.0
tspan = (0.0,tf)
# Formulate, simulate, plot
differential_vars = [true]
prob = DAEProblem(dyns!,dx0,x0,tspan,differential_vars=differential_vars)
#cbs=CallbackSet(control_cb) # this works
#cbs=CallbackSet(xmin_cb, xmax_cb) # this works
#cbs=CallbackSet(xmin_cb,control_cb) # this works
cbs=CallbackSet(xmin_cb,xmax_cb,control_cb) # this breaks - even if I set control_affect!(integrator) = nothing
sol = solve(prob,IDA(),callback=cbs)
plot(sol,vars=(1)) |
I see, this issue only happens when you have a callback set and do two different reinits in the same step. |
…rivatives for essentially no reason (and doing so caused problems whenever you hit callbacks). As a nice side-benefit, this removes the 200 warnings
…ives for essentially no reason (and doing so caused problems whenever you hit callbacks). As a nice side-benefit, this removes the 200 warnings
When solving the "Robertson model" with event callbacks the following error occurs:
The event defitions are from Octave ode15i function tests. The events should occur nearly simultaneously, but with the error the second event is not detected.
The error happens when "save_everystep=true" option is given to "solve".
If "save_everystep=false" the error does not happen and the both events are correctly detected.
Also without events the problem is solved successfully.
Julia 1.5.3 and DifferentialEquations 6.15 with Sundials v4.3.0
Below is test code.
The text was updated successfully, but these errors were encountered: