Skip to content

Commit 8765cb4

Browse files
test: test code generation for non-standard array indexes
1 parent 7dd141d commit 8765cb4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/code_generation.jl

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit
1+
using ModelingToolkit, OrdinaryDiffEq
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33

44
@testset "`generate_custom_function`" begin
@@ -54,3 +54,27 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
5454
fn5 = generate_custom_function(sys, ifelse(!p4, p1, p2[2]); expression = Val(false))
5555
@test fn5(u0, p, 1.0) == 1.0
5656
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

Comments
 (0)