Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Nov 18, 2022
1 parent e2f4f5f commit 61b420c
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions test/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,37 +117,37 @@ if VERSION >= v"1.7"
prob = ODEProblem(ss, [x => 0.0, y => 0.0], (0.0, 1.0),
[kp => 1.0; z => 0.0; z(k + 1) => 0.0])
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
# For all inputs in parameters, just initialize them to 0.0, and then set them
# in the callback.

# kp is the only real parameter
function foo!(du, u, p, t)
x = u[1]
ud = p[2]
du[1] = -x + ud
end
function affect!(integrator, saved_values)
kp = integrator.p[1]
yd = integrator.u[1]
z_t = integrator.p[3]
z = integrator.p[4]
r = 1.0
ud = kp * (r - yd) + z
push!(saved_values.t, integrator.t)
push!(saved_values.saveval, [integrator.p[4], integrator.p[3]])
integrator.p[2] = ud
integrator.p[3] = z + yd
integrator.p[4] = z_t
nothing
end
saved_values = SavedValues(Float64, Vector{Float64})
cb = PeriodicCallback(Base.Fix2(affect!, saved_values), 0.1)
prob = ODEProblem(foo!, [0.0], (0.0, 1.0), [1.0, 0.0, 0.0, 0.0], callback = cb)
sol2 = solve(prob, Tsit5())
@test sol.u == sol2.u
@test saved_values.t == sol.prob.kwargs[:disc_saved_values][1].t
@test saved_values.saveval == sol.prob.kwargs[:disc_saved_values][1].saveval
end
# For all inputs in parameters, just initialize them to 0.0, and then set them
# in the callback.

# kp is the only real parameter
function foo!(du, u, p, t)
x = u[1]
ud = p[2]
du[1] = -x + ud
end
function affect!(integrator, saved_values)
kp = integrator.p[1]
yd = integrator.u[1]
z_t = integrator.p[3]
z = integrator.p[4]
r = 1.0
ud = kp * (r - yd) + z
push!(saved_values.t, integrator.t)
push!(saved_values.saveval, [integrator.p[4], integrator.p[3]])
integrator.p[2] = ud
integrator.p[3] = z + yd
integrator.p[4] = z_t
nothing
end
saved_values = SavedValues(Float64, Vector{Float64});
cb = PeriodicCallback(Base.Fix2(affect!, saved_values), 0.1)
prob = ODEProblem(foo!, [0.0], (0.0, 1.0), [1.0, 0.0, 0.0, 0.0], callback = cb)
sol2 = solve(prob, Tsit5())
@test sol.u == sol2.u
@test saved_values.t == sol.prob.kwargs[:disc_saved_values][1].t
@test saved_values.saveval == sol.prob.kwargs[:disc_saved_values][1].saveval

@info "Testing multi-rate hybrid system"
dt = 0.1
Expand Down

0 comments on commit 61b420c

Please sign in to comment.