Skip to content

Commit 9d65a33

Browse files
committed
fixing create_array
1 parent 18fdd5f commit 9d65a33

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ version = "9.54.0"
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
88
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
99
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
10+
BoundaryValueDiffEq = "764a87c0-6b3e-53db-9096-fe964310641d"
11+
BoundaryValueDiffEqCore = "56b672f2-a5fe-4263-ab2d-da677488eb3a"
12+
BoundaryValueDiffEqMIRK = "1a22d4ce-7765-49ea-b6f2-13c8438986a6"
1013
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
1114
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
1215
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,19 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
539539
(u, p, t) -> (u[1] - _u0)
540540
end
541541

542-
return BVProblem{iip}(f, bc, u0, tspan, p; kwargs1..., kwargs...)
542+
return BVProblem{iip}(f, bc, _u0, tspan, p; kwargs1..., kwargs...)
543543
end
544544

545545
get_callback(prob::BVProblem) = error("BVP solvers do not support callbacks.")
546546

547+
@inline function create_array(::Type{Base.ReinterpretArray}, ::Nothing, ::Val{1}, ::Val{dims}, elems...) where dims
548+
[elems...]
549+
end
550+
551+
@inline function create_array(::Type{Base.ReinterpretArray}, T, ::Val{1}, ::Val{dims}, elems...) where dims
552+
T[elems...]
553+
end
554+
547555
"""
548556
```julia
549557
DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = unknowns(sys),

test/bvproblem.jl

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using BoundaryValueDiffEq, OrdinaryDiffEq
22
using ModelingToolkit
33
using ModelingToolkit: t_nounits as t, D_nounits as D
44

5+
solvers = [MIRK4, RadauIIa5, LobattoIIIa3]
6+
57
@parameters α = 7.5 β = 4. γ = 8. δ = 5.
68
@variables x(t) = 1. y(t) = 2.
79

@@ -13,20 +15,26 @@ parammap = [:α => 7.5, :β => 4, :γ => 8., :δ => 5.]
1315
tspan = (0., 10.)
1416

1517
@mtkbuild lotkavolterra = ODESystem(eqs, t)
18+
op = ODEProblem(lotkavolterra, u0map, tspan, parammap)
19+
osol = solve(op, Vern9())
1620

17-
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(lotkavolterra, u0map, tspan, parammap)
18-
sol = solve(bvp, MIRK4(), dt = 0.01);
21+
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(lotkavolterra, u0map, tspan, parammap; eval_expression = true)
1922

20-
bvp2 = SciMLBase.BVProblem{false, SciMLBase.AutoSpecialize}(lotkavolterra, u0map, tspan, parammap)
21-
sol2 = solve(bvp, MIRK4(), dt = 0.01);
23+
for solver in solvers
24+
println("$solver")
25+
sol = solve(bvp, solver(), dt = 0.01)
26+
@test isapprox(sol.u[end], osol.u[end]; atol = 0.01)
27+
@test sol.u[1] == [1., 2.]
28+
end
2229

23-
op = ODEProblem(lotkavolterra, u0map, tspan, parammap)
24-
osol = solve(op, Vern9())
30+
# Test out of place
31+
bvp2 = SciMLBase.BVProblem{false, SciMLBase.AutoSpecialize}(lotkavolterra, u0map, tspan, parammap; eval_expression = true)
2532

26-
@test isapprox(sol.u[end],osol.u[end]; atol = 0.01)
27-
@test isapprox(sol2.u[end],osol.u[end]; atol = 0.01)
28-
@test sol.u[1] == [1., 2.]
29-
@test sol2.u[1] == [1., 2.]
33+
for solver in solvers
34+
sol = solve(bvp2, solver(), dt = 0.01)
35+
@test isapprox(sol.u[end],osol.u[end]; atol = 0.01)
36+
@test sol.u[1] == [1., 2.]
37+
end
3038

3139
### Testing on pendulum
3240

@@ -38,19 +46,24 @@ eqs = [D(D(θ)) ~ -(g / L) * sin(θ)]
3846
@mtkbuild pend = ODESystem(eqs, t)
3947

4048
u0map ==> π/2, D(θ) => π/2]
41-
parammap = [:L => 2., :g => 9.81]
49+
parammap = [:L => 1., :g => 9.81]
4250
tspan = (0., 10.)
4351

52+
op = ODEProblem(pend, u0map, tspan, parammap)
53+
osol = solve(op, Vern9())
54+
4455
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap)
45-
sol = solve(bvp, MIRK4(), dt = 0.01);
56+
for solver in solvers
57+
sol = solve(bvp2, solver(), dt = 0.01)
58+
@test isapprox(sol.u[end],osol.u[end]; atol = 0.01)
59+
@test sol.u[1] ==/2, π/2]
60+
end
4661

62+
# Test out-of-place
4763
bvp2 = SciMLBase.BVProblem{false, SciMLBase.FullSpecialize}(pend, u0map, tspan, parammap)
48-
sol2 = solve(bvp2, MIRK4(), dt = 0.01);
49-
50-
op = ODEProblem(pend, u0map, tspan, parammap)
51-
osol = solve(op, Vern9())
5264

53-
@test isapprox(sol.u[end], osol.u[end]; atol = 0.01)
54-
@test sol.u[1] ==/2, π/2]
55-
@test isapprox(sol2.u[end], osol.u[end]; atol = 0.01)
56-
@test sol2.u[1] ==/2, π/2]
65+
for solver in solvers
66+
sol = solve(bvp2, solver(), dt = 0.01)
67+
@test isapprox(sol.u[end],osol.u[end]; atol = 0.01)
68+
@test sol.u[1] ==/2, π/2]
69+
end

0 commit comments

Comments
 (0)