|
1 |
| -using ModelingToolkit |
| 1 | +using ModelingToolkit, OrdinaryDiffEq |
2 | 2 | using ModelingToolkit: t_nounits as t, D_nounits as D
|
3 | 3 |
|
4 | 4 | @testset "`generate_custom_function`" begin
|
@@ -54,3 +54,27 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
|
54 | 54 | fn5 = generate_custom_function(sys, ifelse(!p4, p1, p2[2]); expression = Val(false))
|
55 | 55 | @test fn5(u0, p, 1.0) == 1.0
|
56 | 56 | end
|
| 57 | + |
| 58 | +@testset "Non-standard array variables" begin |
| 59 | + @variables x(t) |
| 60 | + @parameters p[0:2] (f::Function)(..) |
| 61 | + @mtkbuild sys = ODESystem(D(x) ~ p[0] * x + p[1] * t + p[2] + f(p), t) |
| 62 | + prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [p => [1.0, 2.0, 3.0], f => sum]) |
| 63 | + @test prob.ps[p] == [1.0, 2.0, 3.0] |
| 64 | + @test prob.ps[p[0]] == 1.0 |
| 65 | + sol = solve(prob, Tsit5()) |
| 66 | + @test SciMLBase.successful_retcode(sol) |
| 67 | + |
| 68 | + @testset "Array split across buffers" begin |
| 69 | + @variables x(t)[0:2] |
| 70 | + @parameters p[1:2] (f::Function)(..) |
| 71 | + @named sys = ODESystem( |
| 72 | + [D(x[0]) ~ p[1] * x[0] + x[2], D(x[1]) ~ p[2] * f(x) + x[2]], t) |
| 73 | + sys, = structural_simplify(sys, ([x[2]], [])) |
| 74 | + @test is_parameter(sys, x[2]) |
| 75 | + prob = ODEProblem(sys, [x[0] => 1.0, x[1] => 1.0], (0.0, 1.0), |
| 76 | + [p => ones(2), f => sum, x[2] => 2.0]) |
| 77 | + sol = solve(prob, Tsit5()) |
| 78 | + @test SciMLBase.successful_retcode(sol) |
| 79 | + end |
| 80 | +end |
0 commit comments