Skip to content

Commit aa1df08

Browse files
committed
generate_control_function test and fix
1 parent c91b53e commit aa1df08

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/inputoutput.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ function generate_control_function(sys::AbstractODESystem, inputs = unbound_inpu
218218
inputs = map(x -> time_varying_as_func(value(x), sys), inputs)
219219

220220
eqs = [eq for eq in full_equations(sys)]
221+
eqs = map(subs_constants, eqs)
221222
if disturbance_inputs !== nothing
222223
# Set all disturbance *inputs* to zero (we just want to keep the disturbance state)
223224
subs = Dict(disturbance_inputs .=> 0)

test/input_output_handling.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ x = [rand()]
171171
u = [rand()]
172172
@test f[1](x, u, p, 1) == -x + u
173173

174+
@testset "Constants substitution" begin
175+
@constants c = 2.0
176+
@variables x(t)
177+
eqs = [D(x) ~ c * x]
178+
@named sys = ODESystem(eqs, t, [x], [])
179+
180+
f, dvs, ps = ModelingToolkit.generate_control_function(sys, simplify = true)
181+
@test f[1]([0.5], nothing, nothing, 0.0) == [1.0]
182+
end
183+
174184
# more complicated system
175185

176186
@variables u(t) [input = true]

0 commit comments

Comments
 (0)