Skip to content

Commit

Permalink
test with split true and false
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Dec 16, 2024
1 parent d75009b commit a3789ae
Showing 1 changed file with 59 additions and 54 deletions.
113 changes: 59 additions & 54 deletions test/input_output_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,61 +153,66 @@ if VERSION >= v"1.8" # :opaque_closure not supported before
end

## Code generation with unbound inputs
@testset "generate_control_function with disturbance inputs" begin
for split in [true, false]
simplify = true

@variables x(t)=0 u(t)=0 [input = true]
eqs = [
D(x) ~ -x + u
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys; simplify, split)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
@test f[1](x, u, p, 1) == -x + u

# With disturbance inputs
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
eqs = [
D(x) ~ -x + u + d^2
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
sys, [u], [d]; simplify, split)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
@test f[1](x, u, p, 1) == -x + u

## With added d argument
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
eqs = [
D(x) ~ -x + u + d^2
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
sys, [u], [d]; simplify, split, disturbance_argument = true)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
d = [rand()]
@test f[1](x, u, p, t, d) == -x + u + [d[]^2]
end
end

@variables x(t)=0 u(t)=0 [input = true]
eqs = [
D(x) ~ -x + u
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys, simplify = true)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
@test f[1](x, u, p, 1) == -x + u

# With disturbance inputs
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
eqs = [
D(x) ~ -x + u + d^2
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
sys, [u], [d], simplify = true)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
@test f[1](x, u, p, 1) == -x + u

# With added d argument
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
eqs = [
D(x) ~ -x + u + d^2
]

@named sys = ODESystem(eqs, t)
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
sys, [u], [d], simplify = true, disturbance_argument = true)

@test isequal(dvs[], x)
@test isempty(ps)

p = nothing
x = [rand()]
u = [rand()]
d = [rand()]
@test f[1](x, u, p, 1, d) == -x + u + [d[]^2]

# more complicated system
## more complicated system

@variables u(t) [input = true]

Expand Down

0 comments on commit a3789ae

Please sign in to comment.