You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using DiffEqBase
using DifferentialEquations
using Plots
using Sundials
import OMBackend
function BouncingBallRealsStartConditions(aux, t)
local x = zeros(2)
local dx = zeros(2)
local p = aux[1]
local reals = aux[2]
begin
begin end
reals[1] = 1.0
dx[1] = reals[2]
dx[2] = -(p[2])
end
x[1] = reals[1]
x[2] = reals[2]
return (x, dx)
end
function BouncingBallRealsAuxVarsHandler(res, dx, x, aux, t)
local p = aux[1]
local reals = aux[2]
end
function BouncingBallRealsDifferentialVars()
return Bool[1, 1]
end
function BouncingBallRealsDAE_equations(res, dx, x, aux, t)
BouncingBallRealsAuxVarsHandler(res, dx, x, aux, t)
local p = aux[1]
local reals = aux[2]
res[1] = dx[1] - reals[2]
res[2] = dx[2] - -(p[2])
reals[1] = x[1]
reals[2] = x[2]
end
function BouncingBallRealsParameterVars()
local aux = Array{Array{Float64}}(undef, 2)
local p = Array{Float64}(undef, 2)
local reals = Array{Float64}(undef, 2)
aux[1] = p
aux[2] = reals
p[1] = 0.7
p[2] = 9.81
return aux
end
begin
saved_values_BouncingBallReals = SavedValues(Float64, Tuple{Float64,Array})
function BouncingBallRealsCallbackSet(aux)
local p = aux[1]
begin
function condition1(x, t, integrator)
x[1] - 0.0
end
function affect1!(integrator)
integrator.u[2] = -(p[1] * integrator.u[2])
end
cb1 = ContinuousCallback(
condition1,
affect1!,
rootfind = true,
save_positions = (false, false),
affect_neg! = affect1!,
)
end
begin
savingFunction(u, t, integrator) =
let
(t, deepcopy(integrator.p[2]))
end
cb2 = SavingCallback(savingFunction, saved_values_BouncingBallReals)
end
return CallbackSet(cb1)
end
end
function BouncingBallRealsSimulate(tspan = (0.0, 1.0))
local aux = BouncingBallRealsParameterVars()
(x0, dx0) = BouncingBallRealsStartConditions(aux, tspan[1])
local differential_vars = BouncingBallRealsDifferentialVars()
local problem = DAEProblem(
BouncingBallRealsDAE_equations,
dx0,
x0,
tspan,
aux,
differential_vars = differential_vars,
callback = BouncingBallRealsCallbackSet(aux),
)
local solution = solve(problem, IDA())
return solution
end
Removing save positions and the OM saving callback produces the correct result for every run.
However, if I add the saving callback:
begin
saved_values_BouncingBallReals = SavedValues(Float64, Tuple{Float64,Array})
function BouncingBallRealsCallbackSet(aux)
local p = aux[1]
begin
function condition1(x, t, integrator)
x[1] - 0.0
end
function affect1!(integrator)
integrator.u[2] = -(p[1] * integrator.u[2])
end
cb1 = ContinuousCallback(
condition1,
affect1!,
rootfind = true,
save_positions = (true, true),
affect_neg! = affect1!,
)
end
begin
savingFunction(u, t, integrator) =
let
(t, deepcopy(integrator.p[2]))
end
cb2 = SavingCallback(savingFunction, saved_values_BouncingBallReals)
end
return CallbackSet(cb1, cb)
end
This results in the following error:
┌ Warning: IDAGetDky failed with error code =
│ flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20
[IDAS ERROR] IDAGetDky
Illegal value for k.
┌ Warning: IDAGetDky failed with error code =
│ flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20
[IDAS ERROR] IDAGetDky
Illegal value for k.
┌ Warning: IDAGetDky failed with error code =
│ flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20
[IDAS ERROR] IDAGetDky
Illegal value for k.
┌ Warning: IDAGetDky failed with error code =
│ flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20
Removing save positions and the OM saving callback produces the correct result for every run.
However, if I add the saving callback:
This results in the following error:
The plot seems correct. SciML/Sundials.jl#292 and SciML/Sundials.jl#290 seems to have the same issues
The text was updated successfully, but these errors were encountered: