Skip to content

Commit

Permalink
rm more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 3, 2024
1 parent 53b9fe7 commit 96a15d8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Check warning on line 501 in src/systems/callbacks.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/callbacks.jl#L501

Added line #L501 was not covered by tests
if has_continuous_events(sys)
contin_cb = generate_rootfinding_callback(sys; kwargs...)
else
Expand All @@ -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...)

Check warning on line 513 in src/systems/callbacks.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/callbacks.jl#L513

Added line #L513 was not covered by tests
end
44 changes: 0 additions & 44 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions test/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 96a15d8

Please sign in to comment.