Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions test/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,44 +298,42 @@ eqs = [yd ~ Sample(dt)(y)
ss = mtkcompile(cl)
ss_nosplit = mtkcompile(cl; split = false)

if VERSION >= v"1.7"
prob = ODEProblem(ss, [x => 0.0, kp => 1.0], (0.0, 1.0))
prob_nosplit = ODEProblem(ss_nosplit, [x => 0.0, kp => 1.0], (0.0, 1.0))
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
sol_nosplit = solve(prob_nosplit, Tsit5(), kwargshandle = KeywordArgSilent)

function foo!(dx, x, p, t)
kp, ud1, ud2 = p
dx[1] = -x[1] + ud1 + ud2
end
prob = ODEProblem(ss, [x => 0.0, kp => 1.0], (0.0, 1.0))
prob_nosplit = ODEProblem(ss_nosplit, [x => 0.0, kp => 1.0], (0.0, 1.0))
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
sol_nosplit = solve(prob_nosplit, Tsit5(), kwargshandle = KeywordArgSilent)

function affect1!(integrator)
kp = integrator.p[1]
y = integrator.u[1]
r = 1.0
ud1 = kp * (r - y)
integrator.p[2] = ud1
nothing
end
function affect2!(integrator)
kp = integrator.p[1]
y = integrator.u[1]
r = 1.0
ud2 = kp * (r - y)
integrator.p[3] = ud2
nothing
end
cb1 = PeriodicCallback(affect1!, dt; final_affect = true, initial_affect = true)
cb2 = PeriodicCallback(affect2!, dt2; final_affect = true, initial_affect = true)
cb = CallbackSet(cb1, cb2)
# kp ud1 ud2
prob = ODEProblem(foo!, [0.0], (0.0, 1.0), [1.0, 1.0, 1.0], callback = cb)
sol2 = solve(prob, Tsit5())

@test sol.u≈sol2.u atol=1e-6
@test sol_nosplit.u≈sol2.u atol=1e-6
function foo!(dx, x, p, t)
kp, ud1, ud2 = p
dx[1] = -x[1] + ud1 + ud2
end

function affect1!(integrator)
kp = integrator.p[1]
y = integrator.u[1]
r = 1.0
ud1 = kp * (r - y)
integrator.p[2] = ud1
nothing
end
function affect2!(integrator)
kp = integrator.p[1]
y = integrator.u[1]
r = 1.0
ud2 = kp * (r - y)
integrator.p[3] = ud2
nothing
end
cb1 = PeriodicCallback(affect1!, dt; final_affect = true, initial_affect = true)
cb2 = PeriodicCallback(affect2!, dt2; final_affect = true, initial_affect = true)
cb = CallbackSet(cb1, cb2)
# kp ud1 ud2
prob = ODEProblem(foo!, [0.0], (0.0, 1.0), [1.0, 1.0, 1.0], callback = cb)
sol2 = solve(prob, Tsit5())

@test sol.u≈sol2.u atol=1e-6
@test sol_nosplit.u≈sol2.u atol=1e-6

##
@info "Testing hybrid system with components"
using ModelingToolkitStandardLibrary.Blocks
Expand Down
30 changes: 14 additions & 16 deletions test/direct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,20 @@ kwargs = (; name = 3)
@test cool_name[1] == (42,)
@test collect(cool_name[2]) == [:name => 3]

if VERSION >= v"1.5"
name = 3
@named cool_name = foo(42; name)
@test cool_name[1] == (42,)
@test collect(cool_name[2]) == [:name => name]
@named cool_name = foo(; name)
@test collect(cool_name) == [:name => name]

ff = 3
@named cool_name = foo(42; ff)
@test cool_name[1] == (42,)
@test collect(cool_name[2]) == [pp; :ff => ff]

@named cool_name = foo(; ff)
@test collect(cool_name) == [pp; :ff => ff]
end
name = 3
@named cool_name = foo(42; name)
@test cool_name[1] == (42,)
@test collect(cool_name[2]) == [:name => name]
@named cool_name = foo(; name)
@test collect(cool_name) == [:name => name]

ff = 3
@named cool_name = foo(42; ff)
@test cool_name[1] == (42,)
@test collect(cool_name[2]) == [pp; :ff => ff]

@named cool_name = foo(; ff)
@test collect(cool_name) == [pp; :ff => ff]

foo(i; name) = (; i, name)
@named goo[1:3] = foo(10)
Expand Down
6 changes: 2 additions & 4 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
eqs = [D(xx) ~ some_input]
@named model = System(eqs, t)
@test_throws ExtraVariablesSystemException mtkcompile(model)
if VERSION >= v"1.8"
err = "In particular, the unset input(s) are:\n some_input(t)"
@test_throws err mtkcompile(model)
end
err = "In particular, the unset input(s) are:\n some_input(t)"
@test_throws err mtkcompile(model)

# Test input handling
@variables x(t) u(t) [input = true] v(t)[1:2] [input = true]
Expand Down
Loading