From 96a15d8dbdeea7fd0ec0cc9191af3a230cfef1ba Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 3 Jan 2024 10:43:37 +0100 Subject: [PATCH] rm more stuff --- src/clock.jl | 2 +- src/systems/callbacks.jl | 7 ++----- test/odesystem.jl | 44 ---------------------------------------- test/units.jl | 10 --------- 4 files changed, 3 insertions(+), 60 deletions(-) diff --git a/src/clock.jl b/src/clock.jl index 292577ee49..0ce64980f1 100644 --- a/src/clock.jl +++ b/src/clock.jl @@ -42,7 +42,7 @@ end has_time_domain(x::Num) = has_time_domain(value(x)) has_time_domain(x) = false -for op in [Differential, Difference] +for op in [Differential] @eval input_timedomain(::$op, arg = nothing) = Continuous() @eval output_timedomain(::$op, arg = nothing) = Continuous() end diff --git a/src/systems/callbacks.jl b/src/systems/callbacks.jl index b97112e9e8..98bfc6a86a 100644 --- a/src/systems/callbacks.jl +++ b/src/systems/callbacks.jl @@ -498,7 +498,7 @@ merge_cb(::Nothing, x) = merge_cb(x, nothing) merge_cb(x, ::Nothing) = x merge_cb(x, y) = CallbackSet(x, y) -function process_events(sys; callback = nothing, has_difference = false, kwargs...) +function process_events(sys; callback = nothing, kwargs...) if has_continuous_events(sys) contin_cb = generate_rootfinding_callback(sys; kwargs...) else @@ -509,9 +509,6 @@ function process_events(sys; callback = nothing, has_difference = false, kwargs. else discrete_cb = nothing end - difference_cb = has_difference ? generate_difference_cb(sys; kwargs...) : nothing - cb = merge_cb(contin_cb, difference_cb) - cb = merge_cb(cb, callback) - (discrete_cb === nothing) ? cb : CallbackSet(cb, discrete_cb...) + (discrete_cb === nothing) ? contin_cb : CallbackSet(contin_cb, discrete_cb...) end diff --git a/test/odesystem.jl b/test/odesystem.jl index c4a09b6ecd..5bbfa5e046 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -501,50 +501,6 @@ sol = solve(prob, Tsit5()) map((x, y) -> x[2] .+ 2y, sol[x], sol[y]), map((x, y) -> x[3] .+ 3y, sol[x], sol[y])) -# Mixed Difference Differential equations -@parameters t a b c d -@variables x(t) y(t) -δ = Differential(t) -Δ = Difference(t; dt = 0.1) -U = DiscreteUpdate(t; dt = 0.1) -eqs = [δ(x) ~ a * x - b * x * y - δ(y) ~ -c * y + d * x * y - Δ(x) ~ y - U(y) ~ x + 1] -@named de = ODESystem(eqs, t, [x, y], [a, b, c, d]) -@test generate_difference_cb(de) isa ModelingToolkit.DiffEqCallbacks.DiscreteCallback - -# doesn't work with ODEFunction -# prob = ODEProblem(ODEFunction{false}(de),[1.0,1.0],(0.0,1.0),[1.5,1.0,3.0,1.0]) - -prob = ODEProblem(de, [1.0, 1.0], (0.0, 1.0), [1.5, 1.0, 3.0, 1.0], check_length = false) -@test prob.kwargs[:callback] isa ModelingToolkit.DiffEqCallbacks.DiscreteCallback - -sol = solve(prob, Tsit5(); callback = prob.kwargs[:callback], - tstops = prob.tspan[1]:0.1:prob.tspan[2], verbose = false) - -# Direct implementation -function lotka(du, u, p, t) - x = u[1] - y = u[2] - du[1] = p[1] * x - p[2] * x * y - du[2] = -p[3] * y + p[4] * x * y -end - -prob2 = ODEProblem(lotka, [1.0, 1.0], (0.0, 1.0), [1.5, 1.0, 3.0, 1.0]) -function periodic_difference_affect!(int) - int.u = [int.u[1] + int.u[2], int.u[1] + 1] - return nothing -end - -difference_cb = ModelingToolkit.PeriodicCallback(periodic_difference_affect!, 0.1) - -sol2 = solve(prob2, Tsit5(); callback = difference_cb, - tstops = collect(prob.tspan[1]:0.1:prob.tspan[2])[2:end], verbose = false) - -@test sol(0:0.01:1)[x] ≈ sol2(0:0.01:1)[1, :] -@test sol(0:0.01:1)[y] ≈ sol2(0:0.01:1)[2, :] - using ModelingToolkit function submodel(; name) diff --git a/test/units.jl b/test/units.jl index 9abe428cd2..541dde8e90 100644 --- a/test/units.jl +++ b/test/units.jl @@ -99,16 +99,6 @@ D = Differential(t) eqs = D.(x) .~ v ODESystem(eqs, name = :sys) -# Difference equation -@parameters t [unit = u"s"] a [unit = u"s"^-1] -@variables x(t) [unit = u"kg"] -δ = Differential(t) -D = Difference(t; dt = 0.1u"s") -eqs = [ - δ(x) ~ a * x, -] -de = ODESystem(eqs, t, [x], [a], name = :sys) - # Nonlinear system @parameters a [unit = u"kg"^-1] @variables x [unit = u"kg"]