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