From 420f8e96c9f972411e4c4f8367ad08497875016c Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 6 Mar 2025 15:31:41 +0530 Subject: [PATCH 1/3] fix: turn default for `HeatingResistor` into guess --- src/Electrical/Analog/ideal_components.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index da25edf15..7efeb3fa0 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -210,7 +210,7 @@ Temperature dependent electrical resistor alpha = 0, [description = "Temperature coefficient of resistance"] end @variables begin - R(t) = R_ref + R(t), [guess = R_ref] end @equations begin R ~ R_ref * (1 + alpha * (heat_port.T - T_ref)) From 09457d8c31bb7e3fe5876f00c4296c2de2e006a5 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 6 Mar 2025 15:31:49 +0530 Subject: [PATCH 2/3] test: add guess for test --- test/multi_domain.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/multi_domain.jl b/test/multi_domain.jl index bb2baca03..dd337e669 100644 --- a/test/multi_domain.jl +++ b/test/multi_domain.jl @@ -196,7 +196,7 @@ end @mtkbuild sys = ElHeatingCircuit() - prob = ODEProblem(sys, unknowns(sys) .=> 0.0, (0, 6.0)) + prob = ODEProblem(sys, [], (0, 6.0); guesses = [sys.heating_resistor.i => 0.0]) sol = solve(prob, Rodas4()) @test sol.retcode == Success @test sol[sys.source.v * sys.source.i] == -sol[sys.env.port.Q_flow] From d5aa78485fa0a0186d1fc4fe9034b2e1bf3d704d Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 6 Mar 2025 15:43:41 +0530 Subject: [PATCH 3/3] test: fix analysis point tests --- test/Blocks/test_analysis_points.jl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/Blocks/test_analysis_points.jl b/test/Blocks/test_analysis_points.jl index f18309c86..c92e34e24 100644 --- a/test/Blocks/test_analysis_points.jl +++ b/test/Blocks/test_analysis_points.jl @@ -130,7 +130,7 @@ prob = ODEProblem(ssys, Pair[], (0, 10)) # sol = solve(prob, Rodas5()) # plot(sol) -matrices, _ = get_sensitivity(sys_outer, :inner_plant_input) +matrices, _ = get_sensitivity(sys_outer, sys_outer.inner.plant_input) using ControlSystemsBase # This is required to simplify the results to test against known solution lsys = sminreal(ss(matrices...)) @@ -138,7 +138,7 @@ lsys = sminreal(ss(matrices...)) @test lsys.B[] * lsys.C[] == -1 # either one negative @test lsys.D[] == 1 -matrices_So, _ = get_sensitivity(sys_outer, :inner_plant_output) +matrices_So, _ = get_sensitivity(sys_outer, sys_outer.inner.plant_output) lsyso = sminreal(ss(matrices_So...)) @test lsys == lsyso || lsys == -1 * lsyso * (-1) # Output and input sensitivities are equal for SISO systems @@ -241,7 +241,6 @@ Si = ss(matrices...) t, systems = [P_inner, feedback, ref]) -@test_nowarn Blocks.find_analysis_points(sys_inner) P_not_broken, _ = linearize(sys_inner, :u, :y) @test P_not_broken.A[] == -2 P_broken, _ = linearize(sys_inner, :u, :y, loop_openings = [:u]) @@ -265,9 +264,9 @@ Sinner = sminreal(ss(get_sensitivity(sys_inner, :u)[1]...)) t, systems = [P_outer, sys_inner]) -Souter = sminreal(ss(get_sensitivity(sys_outer, :sys_inner_u)[1]...)) +Souter = sminreal(ss(get_sensitivity(sys_outer, sys_outer.sys_inner.u)[1]...)) -Sinner2 = sminreal(ss(get_sensitivity(sys_outer, :sys_inner_u, loop_openings = [:y2])[1]...)) +Sinner2 = sminreal(ss(get_sensitivity(sys_outer, sys_outer.sys_inner.u, loop_openings = [:y2])[1]...)) @test Sinner.nx == 1 @test Sinner == Sinner2 @@ -333,7 +332,7 @@ eqs = [connect(r.output, F.input) connect(F.output, sys_inner.add.input1)] sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer) -matrices, _ = get_sensitivity(sys_outer, [:inner_plant_input, :inner_plant_output]) +matrices, _ = get_sensitivity(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output]) Ps = tf(1, [1, 1]) |> ss Cs = tf(1) |> ss @@ -347,7 +346,7 @@ So = CS.feedback(1, Ps * Cs) @test tf(G[1, 2]) ≈ tf(-CS.feedback(Cs, Ps)) @test tf(G[2, 1]) ≈ tf(CS.feedback(Ps, Cs)) -matrices, _ = get_comp_sensitivity(sys_outer, [:inner_plant_input, :inner_plant_output]) +matrices, _ = get_comp_sensitivity(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output]) G = CS.ss(matrices...) |> sminreal Ti = CS.feedback(Cs * Ps) @@ -360,23 +359,23 @@ To = CS.feedback(Ps * Cs) # matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output]) matrices, _ = get_looptransfer( - sys_outer, :inner_plant_input) + sys_outer, sys_outer.inner.plant_input) L = CS.ss(matrices...) |> sminreal @test tf(L) ≈ -tf(Cs * Ps) matrices, _ = get_looptransfer( - sys_outer, :inner_plant_output) + sys_outer, 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]) +matrices, _ = get_looptransfer(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output]) L = CS.ss(matrices...) |> sminreal @test tf(L[1, 1]) ≈ tf(0) @test tf(L[2, 2]) ≈ tf(0) @test sminreal(L[1, 2]) ≈ ss(-1) @test tf(L[2, 1]) ≈ tf(Ps) -matrices, _ = linearize(sys_outer, [:inner_plant_input], [:inner_plant_output]) +matrices, _ = linearize(sys_outer, [sys_outer.inner.plant_input], [sys_outer.inner.plant_output]) G = CS.ss(matrices...) |> sminreal @test tf(G) ≈ tf(CS.feedback(Ps, Cs))