Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use subs_constants in generate_control_function #2904

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading