@@ -1441,9 +1441,7 @@ end
14411441 @test_nowarn ODEProblem (sys, [], (0.0 , 1.0 ))
14421442end
14431443
1444-
14451444@testset " Automatic inference of `discrete_parameters`" begin
1446-
14471445 # Basic case, checks for both types of events (in combination and isolation).
14481446 let
14491447 # Creates models with continuous, discrete, or both types of events
@@ -1519,4 +1517,52 @@ end
15191517 @test sol. ps[k1] == sol. ps[k2] == sol. ps[k3] == sol. ps[k4] == sol. ps[k5] == 0.0
15201518 @test sol. ps[d1] == sol. ps[d2] == sol. ps[d3] == sol. ps[d4] == sol. ps[d5] == 0.0
15211519 end
1520+
1521+ # Checks that everything works for vector-valued parameters and variables.
1522+ let
1523+ # Creates the model using the macro.
1524+ @mtkmodel VectorParams begin
1525+ @parameters begin
1526+ k (t)[1 : 2 ] = [1 , 1 ]
1527+ kup = 2.0
1528+ end
1529+ @variables begin
1530+ X (t)[1 : 2 ] = [4.0 , 4.0 ]
1531+ end
1532+ @equations begin
1533+ D (X[1 ]) ~ - k[1 ]* X[1 ] + k[2 ]* X[2 ]
1534+ D (X[2 ]) ~ k[1 ]* X[1 ] - k[2 ]* X[2 ]
1535+ end
1536+ @continuous_events begin
1537+ (k[2 ] ~ t) => [k[1 ] ~ Pre (k[1 ] + kup)]
1538+ end
1539+ end
1540+ @mtkcompile model = VectorParams ()
1541+
1542+ # Simulates the model. Checks that the correct values are achieved.
1543+ prob = ODEProblem (model, [], (0.0 , 100.0 ))
1544+ sol = solve (prob, Rosenbrock23 ())
1545+ @test sol. ps[model. kup] == 2.0
1546+ @test sol. ps[model. k[1 ]] == 3.0
1547+ @test sol. ps[model. k[2 ]] == 1.0
1548+ @test sol[model. X[1 ]][end ] ≈ 2.0 atol = 1e-8 rtol = 1e-8
1549+ @test sol[model. X[2 ]][end ] ≈ 6.0 atol = 1e-8 rtol = 1e-8
1550+ end
1551+
1552+ # Checks for a functional affect.
1553+ let
1554+ # Creates model.
1555+ @variables X (t) = 5.0
1556+ @parameters p = 2.0 d (t) = 1.0
1557+ eqs = [D (X) ~ p - d * X]
1558+ affect! (mod, obs, ctx, integ) = return (; d = 2.0 )
1559+ cevent = [t ~ 1.0 ] => (f = affect!, modified = (; d))
1560+ @mtkcompile sys = System (eqs, t; continuous_events = [cevent])
1561+
1562+ # Simualtes the model and checks that values is correct.
1563+ sol = solve (ODEProblem (sys, [], (0.0 , 100.0 )), Rosenbrock23 ())
1564+ @test sol[X][end ] ≈ 1.0 atol = 1e-8 rtol = 1e-8
1565+ @test sol. ps[p] == 2.0
1566+ @test sol. ps[d] == [1.0 , 2.0 ]
1567+ end
15221568end
0 commit comments