@@ -2,6 +2,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary.Blocks
22using OrdinaryDiffEq, LinearAlgebra
33using Test
44using ModelingToolkit: t_nounits as t, D_nounits as D, AnalysisPoint, AbstractSystem
5+ import ModelingToolkit as MTK
56using Symbolics: NAMESPACE_SEPARATOR
67
78@testset " AnalysisPoint is lowered to `connect`" begin
@@ -69,26 +70,21 @@ sys = ODESystem(eqs, t, systems = [P, C], name = :hej)
6970 @test norm (sol. u[end ]) < 1e-6 # This fails without the feedback through C
7071end
7172
72- @testset " get_sensitivity - $name " for (name, sys, ap) in [
73+ test_cases = [
7374 (" inner" , sys, sys. plant_input),
7475 (" nested" , nested_sys, nested_sys. hej. plant_input),
75- (" inner - nonamespace" , sys, :plant_input ),
76- (" inner - Symbol" , sys, nameof (sys. plant_input)),
77- (" nested - Symbol" , nested_sys, nameof (nested_sys. hej. plant_input))
76+ (" inner - Symbol" , sys, :plant_input ),
77+ (" nested - Symbol" , nested_sys, nameof (sys. plant_input))
7878]
79+
80+ @testset " get_sensitivity - $name " for (name, sys, ap) in test_cases
7981 matrices, _ = get_sensitivity (sys, ap)
8082 @test matrices. A[] == - 2
8183 @test matrices. B[] * matrices. C[] == - 1 # either one negative
8284 @test matrices. D[] == 1
8385end
8486
85- @testset " get_comp_sensitivity - $name " for (name, sys, ap) in [
86- (" inner" , sys, sys. plant_input),
87- (" nested" , nested_sys, nested_sys. hej. plant_input),
88- (" inner - nonamespace" , sys, :plant_input ),
89- (" inner - Symbol" , sys, nameof (sys. plant_input)),
90- (" nested - Symbol" , nested_sys, nameof (nested_sys. hej. plant_input))
91- ]
87+ @testset " get_comp_sensitivity - $name " for (name, sys, ap) in test_cases
9288 matrices, _ = get_comp_sensitivity (sys, ap)
9389 @test matrices. A[] == - 2
9490 @test matrices. B[] * matrices. C[] == 1 # both positive or negative
@@ -104,13 +100,7 @@ S = sensitivity(P, C) # or feedback(1, P*C)
104100T = comp_sensitivity(P, C) # or feedback(P*C)
105101=#
106102
107- @testset " get_looptransfer - $name " for (name, sys, ap) in [
108- (" inner" , sys, sys. plant_input),
109- (" nested" , nested_sys, nested_sys. hej. plant_input),
110- (" inner - nonamespace" , sys, :plant_input ),
111- (" inner - Symbol" , sys, nameof (sys. plant_input)),
112- (" nested - Symbol" , nested_sys, nameof (nested_sys. hej. plant_input))
113- ]
103+ @testset " get_looptransfer - $name " for (name, sys, ap) in test_cases
114104 matrices, _ = get_looptransfer (sys, ap)
115105 @test matrices. A[] == - 1
116106 @test matrices. B[] * matrices. C[] == - 1 # either one negative
@@ -125,13 +115,7 @@ C = -1
125115L = P*C
126116=#
127117
128- @testset " open_loop - $name " for (name, sys, ap) in [
129- (" inner" , sys, sys. plant_input),
130- (" nested" , nested_sys, nested_sys. hej. plant_input),
131- (" inner - nonamespace" , sys, :plant_input ),
132- (" inner - Symbol" , sys, nameof (sys. plant_input)),
133- (" nested - Symbol" , nested_sys, nameof (nested_sys. hej. plant_input))
134- ]
118+ @testset " open_loop - $name " for (name, sys, ap) in test_cases
135119 open_sys, (du, u) = open_loop (sys, ap)
136120 matrices, _ = linearize (open_sys, [du], [u])
137121 @test matrices. A[] == - 1
@@ -146,13 +130,14 @@ eqs = [connect(P.output, :plant_output, C.input)
146130sys = ODESystem (eqs, t, systems = [P, C], name = :hej )
147131@named nested_sys = ODESystem (Equation[], t; systems = [sys])
148132
149- @testset " get_sensitivity - $name " for (name, sys, ap) in [
133+ test_cases = [
150134 (" inner" , sys, sys. plant_input),
151135 (" nested" , nested_sys, nested_sys. hej. plant_input),
152- (" inner - nonamespace" , sys, :plant_input ),
153- (" inner - Symbol" , sys, nameof (sys. plant_input)),
154- (" nested - Symbol" , nested_sys, nameof (nested_sys. hej. plant_input))
136+ (" inner - Symbol" , sys, :plant_input ),
137+ (" nested - Symbol" , nested_sys, nameof (sys. plant_input))
155138]
139+
140+ @testset " get_sensitivity - $name " for (name, sys, ap) in test_cases
156141 matrices, _ = get_sensitivity (sys, ap)
157142 @test matrices. A[] == - 2
158143 @test matrices. B[] * matrices. C[] == - 1 # either one negative
@@ -163,15 +148,19 @@ end
163148 (" inner" , sys, sys. plant_input, sys. plant_output),
164149 (" nested" , nested_sys, nested_sys. hej. plant_input, nested_sys. hej. plant_output)
165150]
151+ inputname = Symbol (join (
152+ MTK. namespace_hierarchy (nameof (inputap))[2 : end ], NAMESPACE_SEPARATOR))
153+ outputname = Symbol (join (
154+ MTK. namespace_hierarchy (nameof (outputap))[2 : end ], NAMESPACE_SEPARATOR))
166155 @testset " input - $(typeof (input)) , output - $(typeof (output)) " for (input, output) in [
167156 (inputap, outputap),
168- (nameof (inputap) , outputap),
169- (inputap, nameof (outputap) ),
170- (nameof (inputap), nameof (outputap) ),
157+ (inputname , outputap),
158+ (inputap, outputname ),
159+ (inputname, outputname ),
171160 (inputap, [outputap]),
172- (nameof (inputap) , [outputap]),
173- (inputap, [nameof (outputap) ]),
174- (nameof (inputap) , [nameof (outputap) ])
161+ (inputname , [outputap]),
162+ (inputap, [outputname ]),
163+ (inputname , [outputname ])
175164 ]
176165 matrices, _ = linearize (sys, input, output)
177166 # Result should be the same as feedpack(P, 1), i.e., the closed-loop transfer function from plant input to plant output
0 commit comments