Skip to content

Commit 6ed304b

Browse files
authored
Keep non-array connector variable collected (#296)
* Keep non-array connector variable collected * format * update guess tests * update tests
1 parent 3ae7030 commit 6ed304b

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

src/Blocks/utils.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@connector function RealInput(;
22
name, nin = 1, u_start = nothing, guess = nin > 1 ? zeros(nin) : 0.0)
3-
nin > 1 && @warn "For inputs greater than one, use `RealInputArray`."
43
if u_start !== nothing
54
Base.depwarn(
65
"The keyword argument `u_start` is deprecated. Use `guess` instead.", :u_start)
@@ -16,8 +15,9 @@
1615
input = true,
1716
description = "Inner variable in RealInput $name"
1817
]
18+
u = collect(u)
1919
end
20-
ODESystem(Equation[], t, [u], []; name = name, guesses = [u => guess])
20+
ODESystem(Equation[], t, [u;], []; name = name, guesses = [(u .=> guess);])
2121
end
2222
@doc """
2323
RealInput(;name, guess)
@@ -58,7 +58,6 @@ Connector with an array of input signals of type Real.
5858

5959
@connector function RealOutput(;
6060
name, nout = 1, u_start = nothing, guess = nout > 1 ? zeros(nout) : 0.0)
61-
nout > 1 && @warn "For outputs greater than one, use `RealOutputArray`."
6261
if u_start !== nothing
6362
Base.depwarn(
6463
"The keyword argument `u_start` is deprecated. Use `guess` instead.", :u_start)
@@ -74,8 +73,9 @@ Connector with an array of input signals of type Real.
7473
output = true,
7574
description = "Inner variable in RealOutput $name"
7675
]
76+
u = collect(u)
7777
end
78-
ODESystem(Equation[], t, [u], []; name = name, guesses = [u => guess])
78+
ODESystem(Equation[], t, [u;], []; name = name, guesses = [(u .=> guess);])
7979
end
8080
@doc """
8181
RealOutput(;name, guess)

test/Blocks/test_analysis_points.jl

+5-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ matrices, _ = get_comp_sensitivity(sys, :plant_input)
5959

6060
## get_looptransfer
6161

62-
matrices, _ = Blocks.get_looptransfer(sys, :plant_input; p = Dict(P.input.u => P.u_start))
62+
matrices, _ = Blocks.get_looptransfer(sys, :plant_input)
6363
@test matrices.A[] == -1
6464
@test matrices.B[] * matrices.C[] == -1 # either one negative
6565
@test matrices.D[] == 0
@@ -308,7 +308,7 @@ T = -CS.feedback(Kss * Pss, I(2), pos_feedback = true)
308308
@test CS.tf(CS.ss(matrices...)) CS.tf(T)
309309

310310
matrices, _ = Blocks.get_looptransfer(
311-
sys, :plant_input; p = Dict(P.input.u[1] => 0.0, P.input.u[2] => 0.0))
311+
sys, :plant_input)
312312
L = Kss * Pss
313313
@test CS.tf(CS.ss(matrices...)) CS.tf(L)
314314

@@ -361,18 +361,17 @@ To = CS.feedback(Ps * Cs)
361361

362362
# matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output])
363363
matrices, _ = get_looptransfer(
364-
sys_outer, :inner_plant_input; p = Dict(sys_inner.P.input.u => sys_inner.P.u_start))
364+
sys_outer, :inner_plant_input)
365365
L = CS.ss(matrices...) |> sminreal
366366
@test tf(L) -tf(Cs * Ps)
367367

368368
matrices, _ = get_looptransfer(
369-
sys_outer, :inner_plant_output; p = Dict(sys_inner.add.input2.u => 0.0))
369+
sys_outer, :inner_plant_output)
370370
L = CS.ss(matrices...) |> sminreal
371371
@test tf(L[1, 1]) -tf(Ps * Cs)
372372

373373
# Calling looptransfer like below is not the intended way, but we can work out what it should return if we did so it remains a valid test
374-
matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output];
375-
p = Dict(sys_inner.P.input.u => sys_inner.P.u_start, sys_inner.add.input2.u => 0.0))
374+
matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output])
376375
L = CS.ss(matrices...) |> sminreal
377376
@test tf(L[1, 1]) tf(0)
378377
@test tf(L[2, 2]) tf(0)

test/Blocks/utils.jl

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using ModelingToolkitStandardLibrary.Blocks
22
using ModelingToolkit
33

4-
@testset "Guesses" begin
4+
@testset "Array Guesses" begin
55
for (block, guess) in [
6-
(RealInput(; name = :a), 0.0),
7-
(RealInput(; nin = 3, name = :a), zeros(3)),
8-
(RealOutput(; name = :a), 0.0),
9-
(RealOutput(; nout = 3, name = :a), zeros(3)),
106
(RealInputArray(; nin = 3, name = :a), zeros(3)),
117
(RealOutputArray(; nout = 3, name = :a), zeros(3))
128
]
@@ -15,6 +11,18 @@ using ModelingToolkit
1511
end
1612
end
1713

14+
@testset "Scalarized Guesses" begin
15+
for (block, guess) in [
16+
(RealInput(; name = :a), 0.0),
17+
(RealInput(; nin = 3, name = :a), zeros(3)),
18+
(RealOutput(; name = :a), 0.0),
19+
(RealOutput(; nout = 3, name = :a), zeros(3))
20+
]
21+
guesses = ModelingToolkit.guesses(block)
22+
@test guesses[@nonamespace block.u[1]] == guess[1]
23+
end
24+
end
25+
1826
@test_deprecated RealInput(; name = :a, u_start = 1.0)
1927
@test_deprecated RealInput(; name = :a, nin = 2, u_start = ones(2))
2028
@test_deprecated RealOutput(; name = :a, u_start = 1.0)

0 commit comments

Comments
 (0)