diff --git a/src/Blocks/utils.jl b/src/Blocks/utils.jl index 946c0d4a2..10ad0261f 100644 --- a/src/Blocks/utils.jl +++ b/src/Blocks/utils.jl @@ -1,6 +1,5 @@ @connector function RealInput(; name, nin = 1, u_start = nothing, guess = nin > 1 ? zeros(nin) : 0.0) - nin > 1 && @warn "For inputs greater than one, use `RealInputArray`." if u_start !== nothing Base.depwarn( "The keyword argument `u_start` is deprecated. Use `guess` instead.", :u_start) @@ -16,8 +15,9 @@ input = true, description = "Inner variable in RealInput $name" ] + u = collect(u) end - ODESystem(Equation[], t, [u], []; name = name, guesses = [u => guess]) + ODESystem(Equation[], t, [u;], []; name = name, guesses = [(u .=> guess);]) end @doc """ RealInput(;name, guess) @@ -58,7 +58,6 @@ Connector with an array of input signals of type Real. @connector function RealOutput(; name, nout = 1, u_start = nothing, guess = nout > 1 ? zeros(nout) : 0.0) - nout > 1 && @warn "For outputs greater than one, use `RealOutputArray`." if u_start !== nothing Base.depwarn( "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. output = true, description = "Inner variable in RealOutput $name" ] + u = collect(u) end - ODESystem(Equation[], t, [u], []; name = name, guesses = [u => guess]) + ODESystem(Equation[], t, [u;], []; name = name, guesses = [(u .=> guess);]) end @doc """ RealOutput(;name, guess) diff --git a/test/Blocks/test_analysis_points.jl b/test/Blocks/test_analysis_points.jl index 9a2a5ed6b..00f040e82 100644 --- a/test/Blocks/test_analysis_points.jl +++ b/test/Blocks/test_analysis_points.jl @@ -59,7 +59,7 @@ matrices, _ = get_comp_sensitivity(sys, :plant_input) ## get_looptransfer -matrices, _ = Blocks.get_looptransfer(sys, :plant_input; p = Dict(P.input.u => P.u_start)) +matrices, _ = Blocks.get_looptransfer(sys, :plant_input) @test matrices.A[] == -1 @test matrices.B[] * matrices.C[] == -1 # either one negative @test matrices.D[] == 0 @@ -308,7 +308,7 @@ T = -CS.feedback(Kss * Pss, I(2), pos_feedback = true) @test CS.tf(CS.ss(matrices...)) ≈ CS.tf(T) matrices, _ = Blocks.get_looptransfer( - sys, :plant_input; p = Dict(P.input.u[1] => 0.0, P.input.u[2] => 0.0)) + sys, :plant_input) L = Kss * Pss @test CS.tf(CS.ss(matrices...)) ≈ CS.tf(L) @@ -361,18 +361,17 @@ To = CS.feedback(Ps * Cs) # matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output]) matrices, _ = get_looptransfer( - sys_outer, :inner_plant_input; p = Dict(sys_inner.P.input.u => sys_inner.P.u_start)) + sys_outer, :inner_plant_input) L = CS.ss(matrices...) |> sminreal @test tf(L) ≈ -tf(Cs * Ps) matrices, _ = get_looptransfer( - sys_outer, :inner_plant_output; p = Dict(sys_inner.add.input2.u => 0.0)) + sys_outer, :inner_plant_output) L = CS.ss(matrices...) |> sminreal @test tf(L[1, 1]) ≈ -tf(Ps * Cs) # 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 -matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output]; - p = Dict(sys_inner.P.input.u => sys_inner.P.u_start, sys_inner.add.input2.u => 0.0)) +matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output]) L = CS.ss(matrices...) |> sminreal @test tf(L[1, 1]) ≈ tf(0) @test tf(L[2, 2]) ≈ tf(0) diff --git a/test/Blocks/utils.jl b/test/Blocks/utils.jl index 5daad8911..6bde3e1d4 100644 --- a/test/Blocks/utils.jl +++ b/test/Blocks/utils.jl @@ -1,12 +1,8 @@ using ModelingToolkitStandardLibrary.Blocks using ModelingToolkit -@testset "Guesses" begin +@testset "Array Guesses" begin for (block, guess) in [ - (RealInput(; name = :a), 0.0), - (RealInput(; nin = 3, name = :a), zeros(3)), - (RealOutput(; name = :a), 0.0), - (RealOutput(; nout = 3, name = :a), zeros(3)), (RealInputArray(; nin = 3, name = :a), zeros(3)), (RealOutputArray(; nout = 3, name = :a), zeros(3)) ] @@ -15,6 +11,18 @@ using ModelingToolkit end end +@testset "Scalarized Guesses" begin + for (block, guess) in [ + (RealInput(; name = :a), 0.0), + (RealInput(; nin = 3, name = :a), zeros(3)), + (RealOutput(; name = :a), 0.0), + (RealOutput(; nout = 3, name = :a), zeros(3)) + ] + guesses = ModelingToolkit.guesses(block) + @test guesses[@nonamespace block.u[1]] == guess[1] + end +end + @test_deprecated RealInput(; name = :a, u_start = 1.0) @test_deprecated RealInput(; name = :a, nin = 2, u_start = ones(2)) @test_deprecated RealOutput(; name = :a, u_start = 1.0)