@@ -2,6 +2,8 @@ using ModelingToolkit, Test
2
2
using ModelingToolkitStandardLibrary. Blocks
3
3
using OrdinaryDiffEq
4
4
using ModelingToolkit: t_nounits as t, D_nounits as D
5
+ using ModelingToolkit: MTKParameters, ParameterIndex, DEPENDENT_PORTION, NONNUMERIC_PORTION
6
+ using SciMLStructures: Tunable, Discrete, Constants
5
7
6
8
x = [1 , 2.0 , false , [1 , 2 , 3 ], Parameter (1.0 )]
7
9
@@ -189,3 +191,25 @@ connections = [[state_feedback.input.u[i] ~ model_outputs[i] for i in 1:4]
189
191
connect (add. output, :u , model. torque. tau)]
190
192
@named closed_loop = ODESystem (connections, t, systems = [model, state_feedback, add, d])
191
193
S = get_sensitivity (closed_loop, :u )
194
+
195
+ @testset " Indexing MTKParameters with ParameterIndex" begin
196
+ ps = MTKParameters (([1.0 , 2.0 ], [3 , 4 ]),
197
+ ([true , false ], [[1 2 ; 3 4 ]]),
198
+ ([5 , 6 ],),
199
+ ([7.0 , 8.0 ],),
200
+ ([" hi" , " bye" ], [:lie , :die ]),
201
+ nothing ,
202
+ nothing )
203
+ @test ps[ParameterIndex (Tunable (), (1 , 2 ))] === 2.0
204
+ @test ps[ParameterIndex (Tunable (), (2 , 2 ))] === 4
205
+ @test ps[ParameterIndex (Discrete (), (2 , 1 , 2 , 2 ))] === 4
206
+ @test ps[ParameterIndex (Discrete (), (2 , 1 ))] == [1 2 ; 3 4 ]
207
+ @test ps[ParameterIndex (Constants (), (1 , 1 ))] === 5
208
+ @test ps[ParameterIndex (DEPENDENT_PORTION, (1 , 1 ))] === 7.0
209
+ @test ps[ParameterIndex (NONNUMERIC_PORTION, (2 , 2 ))] === :die
210
+
211
+ ps[ParameterIndex (Tunable (), (1 , 2 ))] = 3.0
212
+ ps[ParameterIndex (Discrete (), (2 , 1 , 2 , 2 ))] = 5
213
+ @test ps[ParameterIndex (Tunable (), (1 , 2 ))] === 3.0
214
+ @test ps[ParameterIndex (Discrete (), (2 , 1 , 2 , 2 ))] === 5
215
+ end
0 commit comments