Skip to content

test: fix several tests #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Electrical/Analog/ideal_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 10 additions & 11 deletions test/Blocks/test_analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ 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...))
@test lsys.A[] == -2
@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

Expand Down Expand Up @@ -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])
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))
2 changes: 1 addition & 1 deletion test/multi_domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading