Skip to content

Commit

Permalink
generate_control_function test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aml5600 committed Jul 28, 2024
1 parent c91b53e commit aa1df08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/inputoutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function generate_control_function(sys::AbstractODESystem, inputs = unbound_inpu
inputs = map(x -> time_varying_as_func(value(x), sys), inputs)

eqs = [eq for eq in full_equations(sys)]
eqs = map(subs_constants, eqs)
if disturbance_inputs !== nothing
# Set all disturbance *inputs* to zero (we just want to keep the disturbance state)
subs = Dict(disturbance_inputs .=> 0)
Expand Down
10 changes: 10 additions & 0 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ x = [rand()]
u = [rand()]
@test f[1](x, u, p, 1) == -x + u

@testset "Constants substitution" begin
@constants c = 2.0
@variables x(t)
eqs = [D(x) ~ c * x]
@named sys = ODESystem(eqs, t, [x], [])

f, dvs, ps = ModelingToolkit.generate_control_function(sys, simplify = true)
@test f[1]([0.5], nothing, nothing, 0.0) == [1.0]
end

# more complicated system

@variables u(t) [input = true]
Expand Down

0 comments on commit aa1df08

Please sign in to comment.