Skip to content

Commit 5507939

Browse files
test: test analysis point transformations with duplicate connections
1 parent 8629c6a commit 5507939

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

test/downstream/analysis_points.jl

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,59 @@ import ControlSystemsBase as CS
8080
@test tf(So) tf(Si)
8181
end
8282

83-
@testset "Analysis points with subsystems" begin
83+
@testset "Duplicate `connect` statements across subsystems with AP transforms - standard `connect`" begin
8484
@named P = FirstOrder(k = 1, T = 1)
8585
@named C = Gain(; k = 1)
8686
@named add = Blocks.Add(k2 = -1)
8787

8888
eqs = [connect(P.output, :plant_output, add.input2)
8989
connect(add.output, C.input)
90-
connect(C.output, :plant_input, P.input)]
90+
connect(C.output, P.input)]
91+
92+
sys_inner = ODESystem(eqs, t, systems = [P, C, add], name = :inner)
93+
94+
@named r = Constant(k = 1)
95+
@named F = FirstOrder(k = 1, T = 3)
96+
97+
eqs = [connect(r.output, F.input)
98+
connect(sys_inner.P.output, sys_inner.add.input2)
99+
connect(sys_inner.C.output, :plant_input, sys_inner.P.input)
100+
connect(F.output, sys_inner.add.input1)]
101+
sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer)
102+
103+
# test first that the structural_simplify works correctly
104+
ssys = structural_simplify(sys_outer)
105+
prob = ODEProblem(ssys, Pair[], (0, 10))
106+
@test_nowarn solve(prob, Rodas5())
91107

92-
# eqs = [connect(P.output, add.input2)
93-
# connect(add.output, C.input)
94-
# connect(C.output, P.input)]
108+
matrices, _ = get_sensitivity(sys_outer, sys_outer.plant_input)
109+
lsys = sminreal(ss(matrices...))
110+
@test lsys.A[] == -2
111+
@test lsys.B[] * lsys.C[] == -1 # either one negative
112+
@test lsys.D[] == 1
113+
114+
matrices_So, _ = get_sensitivity(sys_outer, sys_outer.inner.plant_output)
115+
lsyso = sminreal(ss(matrices_So...))
116+
@test lsys == lsyso || lsys == -1 * lsyso * (-1) # Output and input sensitivities are equal for SISO systems
117+
end
118+
119+
@testset "Duplicate `connect` statements across subsystems with AP transforms - causal variable `connect`" begin
120+
@named P = FirstOrder(k = 1, T = 1)
121+
@named C = Gain(; k = 1)
122+
@named add = Blocks.Add(k2 = -1)
123+
124+
eqs = [connect(P.output.u, :plant_output, add.input2.u)
125+
connect(add.output, C.input)
126+
connect(C.output.u, P.input.u)]
95127

96128
sys_inner = ODESystem(eqs, t, systems = [P, C, add], name = :inner)
97129

98130
@named r = Constant(k = 1)
99131
@named F = FirstOrder(k = 1, T = 3)
100132

101133
eqs = [connect(r.output, F.input)
134+
connect(sys_inner.P.output.u, sys_inner.add.input2.u)
135+
connect(sys_inner.C.output.u, :plant_input, sys_inner.P.input.u)
102136
connect(F.output, sys_inner.add.input1)]
103137
sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer)
104138

@@ -107,7 +141,7 @@ end
107141
prob = ODEProblem(ssys, Pair[], (0, 10))
108142
@test_nowarn solve(prob, Rodas5())
109143

110-
matrices, _ = get_sensitivity(sys_outer, sys_outer.inner.plant_input)
144+
matrices, _ = get_sensitivity(sys_outer, sys_outer.plant_input)
111145
lsys = sminreal(ss(matrices...))
112146
@test lsys.A[] == -2
113147
@test lsys.B[] * lsys.C[] == -1 # either one negative

0 commit comments

Comments
 (0)