Skip to content

Commit a3789ae

Browse files
committed
test with split true and false
1 parent d75009b commit a3789ae

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed

test/input_output_handling.jl

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -153,61 +153,66 @@ if VERSION >= v"1.8" # :opaque_closure not supported before
153153
end
154154

155155
## Code generation with unbound inputs
156+
@testset "generate_control_function with disturbance inputs" begin
157+
for split in [true, false]
158+
simplify = true
159+
160+
@variables x(t)=0 u(t)=0 [input = true]
161+
eqs = [
162+
D(x) ~ -x + u
163+
]
164+
165+
@named sys = ODESystem(eqs, t)
166+
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys; simplify, split)
167+
168+
@test isequal(dvs[], x)
169+
@test isempty(ps)
170+
171+
p = nothing
172+
x = [rand()]
173+
u = [rand()]
174+
@test f[1](x, u, p, 1) == -x + u
175+
176+
# With disturbance inputs
177+
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
178+
eqs = [
179+
D(x) ~ -x + u + d^2
180+
]
181+
182+
@named sys = ODESystem(eqs, t)
183+
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
184+
sys, [u], [d]; simplify, split)
185+
186+
@test isequal(dvs[], x)
187+
@test isempty(ps)
188+
189+
p = nothing
190+
x = [rand()]
191+
u = [rand()]
192+
@test f[1](x, u, p, 1) == -x + u
193+
194+
## With added d argument
195+
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
196+
eqs = [
197+
D(x) ~ -x + u + d^2
198+
]
199+
200+
@named sys = ODESystem(eqs, t)
201+
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
202+
sys, [u], [d]; simplify, split, disturbance_argument = true)
203+
204+
@test isequal(dvs[], x)
205+
@test isempty(ps)
206+
207+
p = nothing
208+
x = [rand()]
209+
u = [rand()]
210+
d = [rand()]
211+
@test f[1](x, u, p, t, d) == -x + u + [d[]^2]
212+
end
213+
end
156214

157-
@variables x(t)=0 u(t)=0 [input = true]
158-
eqs = [
159-
D(x) ~ -x + u
160-
]
161-
162-
@named sys = ODESystem(eqs, t)
163-
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys, simplify = true)
164-
165-
@test isequal(dvs[], x)
166-
@test isempty(ps)
167-
168-
p = nothing
169-
x = [rand()]
170-
u = [rand()]
171-
@test f[1](x, u, p, 1) == -x + u
172-
173-
# With disturbance inputs
174-
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
175-
eqs = [
176-
D(x) ~ -x + u + d^2
177-
]
178-
179-
@named sys = ODESystem(eqs, t)
180-
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
181-
sys, [u], [d], simplify = true)
182-
183-
@test isequal(dvs[], x)
184-
@test isempty(ps)
185-
186-
p = nothing
187-
x = [rand()]
188-
u = [rand()]
189-
@test f[1](x, u, p, 1) == -x + u
190-
191-
# With added d argument
192-
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
193-
eqs = [
194-
D(x) ~ -x + u + d^2
195-
]
196-
197-
@named sys = ODESystem(eqs, t)
198-
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(
199-
sys, [u], [d], simplify = true, disturbance_argument = true)
200-
201-
@test isequal(dvs[], x)
202-
@test isempty(ps)
203-
204-
p = nothing
205-
x = [rand()]
206-
u = [rand()]
207-
d = [rand()]
208-
@test f[1](x, u, p, 1, d) == -x + u + [d[]^2]
209-
210-
# more complicated system
215+
## more complicated system
211216

212217
@variables u(t) [input = true]
213218

0 commit comments

Comments
 (0)