Skip to content

Commit

Permalink
Merge pull request #2904 from aml5600/fix/constants
Browse files Browse the repository at this point in the history
Use `subs_constants` in `generate_control_function`
  • Loading branch information
ChrisRackauckas authored Jul 29, 2024
2 parents 171c43e + 7a93c8d commit a7f6cd2
Show file tree
Hide file tree
Showing 2 changed files with 12 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
11 changes: 11 additions & 0 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,14 @@ matrices, ssys = linearize(augmented_sys,
io_sys, [x + u * t]; inputs = [u])
@test obsfn([1.0], [2.0], nothing, 3.0) == [7.0]
end

# https://github.com/SciML/ModelingToolkit.jl/issues/2896
@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

0 comments on commit a7f6cd2

Please sign in to comment.