@@ -2,6 +2,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary.Blocks
2
2
using OrdinaryDiffEq, LinearAlgebra
3
3
using Test
4
4
using ModelingToolkit: t_nounits as t, D_nounits as D, AnalysisPoint, AbstractSystem
5
+ import ModelingToolkit as MTK
5
6
using Symbolics: NAMESPACE_SEPARATOR
6
7
7
8
@testset " AnalysisPoint is lowered to `connect`" begin
@@ -69,26 +70,21 @@ sys = ODESystem(eqs, t, systems = [P, C], name = :hej)
69
70
@test norm (sol. u[end ]) < 1e-6 # This fails without the feedback through C
70
71
end
71
72
72
- @testset " get_sensitivity - $name " for (name, sys, ap) in [
73
+ test_cases = [
73
74
(" inner" , sys, sys. plant_input),
74
75
(" 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))
78
78
]
79
+
80
+ @testset " get_sensitivity - $name " for (name, sys, ap) in test_cases
79
81
matrices, _ = get_sensitivity (sys, ap)
80
82
@test matrices. A[] == - 2
81
83
@test matrices. B[] * matrices. C[] == - 1 # either one negative
82
84
@test matrices. D[] == 1
83
85
end
84
86
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
92
88
matrices, _ = get_comp_sensitivity (sys, ap)
93
89
@test matrices. A[] == - 2
94
90
@test matrices. B[] * matrices. C[] == 1 # both positive or negative
@@ -104,13 +100,7 @@ S = sensitivity(P, C) # or feedback(1, P*C)
104
100
T = comp_sensitivity(P, C) # or feedback(P*C)
105
101
=#
106
102
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
114
104
matrices, _ = get_looptransfer (sys, ap)
115
105
@test matrices. A[] == - 1
116
106
@test matrices. B[] * matrices. C[] == - 1 # either one negative
@@ -125,13 +115,7 @@ C = -1
125
115
L = P*C
126
116
=#
127
117
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
135
119
open_sys, (du, u) = open_loop (sys, ap)
136
120
matrices, _ = linearize (open_sys, [du], [u])
137
121
@test matrices. A[] == - 1
@@ -146,13 +130,14 @@ eqs = [connect(P.output, :plant_output, C.input)
146
130
sys = ODESystem (eqs, t, systems = [P, C], name = :hej )
147
131
@named nested_sys = ODESystem (Equation[], t; systems = [sys])
148
132
149
- @testset " get_sensitivity - $name " for (name, sys, ap) in [
133
+ test_cases = [
150
134
(" inner" , sys, sys. plant_input),
151
135
(" 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))
155
138
]
139
+
140
+ @testset " get_sensitivity - $name " for (name, sys, ap) in test_cases
156
141
matrices, _ = get_sensitivity (sys, ap)
157
142
@test matrices. A[] == - 2
158
143
@test matrices. B[] * matrices. C[] == - 1 # either one negative
@@ -163,15 +148,19 @@ end
163
148
(" inner" , sys, sys. plant_input, sys. plant_output),
164
149
(" nested" , nested_sys, nested_sys. hej. plant_input, nested_sys. hej. plant_output)
165
150
]
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))
166
155
@testset " input - $(typeof (input)) , output - $(typeof (output)) " for (input, output) in [
167
156
(inputap, outputap),
168
- (nameof (inputap) , outputap),
169
- (inputap, nameof (outputap) ),
170
- (nameof (inputap), nameof (outputap) ),
157
+ (inputname , outputap),
158
+ (inputap, outputname ),
159
+ (inputname, outputname ),
171
160
(inputap, [outputap]),
172
- (nameof (inputap) , [outputap]),
173
- (inputap, [nameof (outputap) ]),
174
- (nameof (inputap) , [nameof (outputap) ])
161
+ (inputname , [outputap]),
162
+ (inputap, [outputname ]),
163
+ (inputname , [outputname ])
175
164
]
176
165
matrices, _ = linearize (sys, input, output)
177
166
# 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