Skip to content

Commit a7f6cd2

Browse files
Merge pull request #2904 from aml5600/fix/constants
Use `subs_constants` in `generate_control_function`
2 parents 171c43e + 7a93c8d commit a7f6cd2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,14 @@ matrices, ssys = linearize(augmented_sys,
391391
io_sys, [x + u * t]; inputs = [u])
392392
@test obsfn([1.0], [2.0], nothing, 3.0) == [7.0]
393393
end
394+
395+
# https://github.com/SciML/ModelingToolkit.jl/issues/2896
396+
@testset "Constants substitution" begin
397+
@constants c = 2.0
398+
@variables x(t)
399+
eqs = [D(x) ~ c * x]
400+
@named sys = ODESystem(eqs, t, [x], [])
401+
402+
f, dvs, ps = ModelingToolkit.generate_control_function(sys, simplify = true)
403+
@test f[1]([0.5], nothing, nothing, 0.0) == [1.0]
404+
end

0 commit comments

Comments
 (0)