Skip to content

Commit f751fbb

Browse files
committed
up
1 parent a3429ea commit f751fbb

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,6 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
469469
initializeprobpmap = initializeprobpmap)
470470
end
471471

472-
"""
473-
```julia
474-
SciMLBase.BVPFunction{iip}(sys::AbstractODESystem, u0map, tspan,
475-
parammap = DiffEqBase.NullParameters();
476-
version = nothing, tgrad = false,
477-
jac = true, sparse = true,
478-
simplify = false,
479-
kwargs...) where {iip}
480-
```
481-
"""
482-
483472
"""
484473
```julia
485474
SciMLBase.BVProblem{iip}(sys::AbstractODESystem, u0map, tspan,
@@ -492,7 +481,7 @@ SciMLBase.BVProblem{iip}(sys::AbstractODESystem, u0map, tspan,
492481
493482
Create a `BVProblem` from the [`ODESystem`](@ref). The arguments `dvs` and
494483
`ps` are used to set the order of the dependent variable and parameter vectors,
495-
respectively. `u0` should be either the initial condition, a vector of values `u(t_i)` for collocation methods, or a function returning one or the other.
484+
respectively. `u0map` should be used to specify the initial condition, or be a function returning an initial condition.
496485
"""
497486
function SciMLBase.BVProblem(sys::AbstractODESystem, args...; kwargs...)
498487
BVProblem{true}(sys, args...; kwargs...)
@@ -517,7 +506,6 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
517506
tspan = get_tspan(sys),
518507
parammap = DiffEqBase.NullParameters();
519508
version = nothing, tgrad = false,
520-
jac = true, sparse = true,
521509
callback = nothing,
522510
check_length = true,
523511
warn_initialize_determined = true,
@@ -531,7 +519,7 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
531519

532520
f, u0, p = process_SciMLProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
533521
t = tspan !== nothing ? tspan[1] : tspan,
534-
check_length, warn_initialize_determined, eval_expression, eval_module, jac, kwargs...)
522+
check_length, warn_initialize_determined, eval_expression, eval_module, kwargs...)
535523

536524
cbs = process_events(sys; callback, eval_expression, eval_module, kwargs...)
537525
kwargs = filter_kwargs(kwargs)
@@ -546,7 +534,7 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
546534

547535
# Define the boundary conditions
548536
bc = if iip
549-
(residual, u, p, t) -> (residual = u[1] - _u0)
537+
(residual, u, p, t) -> residual .= u[1] - _u0
550538
else
551539
(u, p, t) -> (u[1] - _u0)
552540
end

test/bvproblem.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using BoundaryValueDiffEq, OrdinaryDiffEq
2+
using ModelingToolkit
3+
using ModelingToolkit: t_nounits as t, D_nounits as D
4+
5+
@parameters σ = 10. ρ = 28 β = 8/3
6+
@variables x(t) = 1 y(t) = 0 z(t) = 0
7+
8+
eqs = [D(x) ~ σ*(y-x),
9+
D(y) ~ x*-z)-y,
10+
D(z) ~ x*y - β*z]
11+
12+
u0map = [:x => 1., :y => 0., :z => 0.]
13+
parammap = [ => 28., => 8/3, => 10.]
14+
tspan = (0., 10.)
15+
16+
@mtkbuild lorenz = ODESystem(eqs, t)
17+
18+
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(lorenz, u0map, tspan, parammap)
19+
sol = solve(bvp, MIRK4(), dt = 0.1);
20+
21+
bvp2 = SciMLBase.BVProblem{false, SciMLBase.AutoSpecialize}(lorenz, u0map, tspan, parammap)
22+
sol2 = solve(bvp, MIRK4(), dt = 0.1);
23+
24+
op = ODEProblem(lorenz, u0map, tspan, parammap)
25+
osol = solve(op)
26+
27+
@test sol.u[end] osol.u[end]
28+
@test sol2.u[end] osol.u[end]
29+
@test sol.u[1] == [1., 0., 0.]
30+
@test sol2.u[1] == [1., 0., 0.]
31+
32+
### Testing on pendulum
33+
34+
@parameters g = 9.81 L = 1.
35+
@variables θ(t) = π/2
36+
37+
eqs = [D(D(θ)) ~ -(g / L) * sin(θ)]
38+
39+
@mtkbuild pend = ODESystem(eqs, t)
40+
41+
u0map ==> π/2, D(θ) => π/2]
42+
parammap = [:L => 2.]
43+
tspan = (0., 10.)
44+
45+
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap)
46+
sol = solve(bvp, MIRK4(), dt = 0.05);
47+
48+
bvp2 = SciMLBase.BVProblem{false, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap)
49+
sol2 = solve(bvp2, MIRK4(), dt = 0.05);
50+
51+
osol = solve(pend)
52+
53+
@test sol.u[end] osol.u[end]
54+
@test sol.u[1] ==/2, π/2]
55+
@test sol2.u[end] osol.u[end]
56+
@test sol2.u[1] ==/2, π/2]

0 commit comments

Comments
 (0)