Skip to content

Commit 3751c2a

Browse files
committed
up
1 parent b2bf7c0 commit 3751c2a

File tree

2 files changed

+83
-86
lines changed

2 files changed

+83
-86
lines changed

src/systems/diffeqs/abstractodesystem.jl

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

472-
"""
473-
```julia
474-
SciMLBase.BVProblem{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-
Create a `BVProblem` from the [`ODESystem`](@ref). The arguments `dvs` and
483-
`ps` are used to set the order of the dependent variable and parameter vectors,
484-
respectively. `u0map` should be used to specify the initial condition, or be a function returning an initial condition.
485-
"""
486-
function SciMLBase.BVProblem(sys::AbstractODESystem, args...; kwargs...)
487-
BVProblem{true}(sys, args...; kwargs...)
488-
end
489-
490-
function SciMLBase.BVProblem(sys::AbstractODESystem,
491-
u0map::StaticArray,
492-
args...;
493-
kwargs...)
494-
BVProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)
495-
end
496-
497-
function SciMLBase.BVProblem{true}(sys::AbstractODESystem, args...; kwargs...)
498-
BVProblem{true, SciMLBase.AutoSpecialize}(sys, args...; kwargs...)
499-
end
500-
501-
function SciMLBase.BVProblem{false}(sys::AbstractODESystem, args...; kwargs...)
502-
BVProblem{false, SciMLBase.FullSpecialize}(sys, args...; kwargs...)
503-
end
504-
505-
function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = [],
506-
tspan = get_tspan(sys),
507-
parammap = DiffEqBase.NullParameters();
508-
version = nothing, tgrad = false,
509-
callback = nothing,
510-
check_length = true,
511-
warn_initialize_determined = true,
512-
eval_expression = false,
513-
eval_module = @__MODULE__,
514-
kwargs...) where {iip, specialize}
515-
if !iscomplete(sys)
516-
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `BVProblem`")
517-
end
518-
519-
f, u0, p = process_SciMLProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
520-
t = tspan !== nothing ? tspan[1] : tspan,
521-
check_length, warn_initialize_determined, eval_expression, eval_module, kwargs...)
522-
523-
cbs = process_events(sys; callback, eval_expression, eval_module, kwargs...)
524-
kwargs = filter_kwargs(kwargs)
525-
526-
kwargs1 = (;)
527-
if cbs !== nothing
528-
kwargs1 = merge(kwargs1, (callback = cbs,))
529-
end
530-
531-
# Construct initial conditions.
532-
_u0 = u0 isa Function ? u0(tspan[1]) : u0
533-
534-
# Define the boundary conditions.
535-
bc = if iip
536-
(residual, u, p, t) -> (residual .= u[1] .- _u0)
537-
else
538-
(u, p, t) -> (u[1] - _u0)
539-
end
540-
541-
return BVProblem{iip}(f, bc, _u0, tspan, p; kwargs1..., kwargs...)
542-
end
543-
544-
get_callback(prob::BVProblem) = error("BVP solvers do not support callbacks.")
545-
546-
@inline function SymbolicUtils.Code.create_array(::Type{<:Base.ReinterpretArray}, ::Nothing,
547-
::Val{1}, ::Val{dims}, elems...) where {dims}
548-
[elems...]
549-
end
550-
551-
@inline function SymbolicUtils.Code.create_array(
552-
::Type{<:Base.ReinterpretArray}, T, ::Val{1}, ::Val{dims}, elems...) where {dims}
553-
T[elems...]
554-
end
555-
556472
"""
557473
```julia
558474
DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = unknowns(sys),
@@ -943,6 +859,87 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
943859
end
944860
get_callback(prob::ODEProblem) = prob.kwargs[:callback]
945861

862+
"""
863+
```julia
864+
SciMLBase.BVProblem{iip}(sys::AbstractODESystem, u0map, tspan,
865+
parammap = DiffEqBase.NullParameters();
866+
version = nothing, tgrad = false,
867+
jac = true, sparse = true,
868+
simplify = false,
869+
kwargs...) where {iip}
870+
```
871+
872+
Create a `BVProblem` from the [`ODESystem`](@ref). The arguments `dvs` and
873+
`ps` are used to set the order of the dependent variable and parameter vectors,
874+
respectively. `u0map` should be used to specify the initial condition.
875+
"""
876+
function SciMLBase.BVProblem(sys::AbstractODESystem, args...; kwargs...)
877+
BVProblem{true}(sys, args...; kwargs...)
878+
end
879+
880+
function SciMLBase.BVProblem(sys::AbstractODESystem,
881+
u0map::StaticArray,
882+
args...;
883+
kwargs...)
884+
BVProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)
885+
end
886+
887+
function SciMLBase.BVProblem{true}(sys::AbstractODESystem, args...; kwargs...)
888+
BVProblem{true, SciMLBase.AutoSpecialize}(sys, args...; kwargs...)
889+
end
890+
891+
function SciMLBase.BVProblem{false}(sys::AbstractODESystem, args...; kwargs...)
892+
BVProblem{false, SciMLBase.FullSpecialize}(sys, args...; kwargs...)
893+
end
894+
895+
function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = [],
896+
tspan = get_tspan(sys),
897+
parammap = DiffEqBase.NullParameters();
898+
version = nothing, tgrad = false,
899+
callback = nothing,
900+
check_length = true,
901+
warn_initialize_determined = true,
902+
eval_expression = false,
903+
eval_module = @__MODULE__,
904+
kwargs...) where {iip, specialize}
905+
if !iscomplete(sys)
906+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `BVProblem`")
907+
end
908+
909+
f, u0, p = process_SciMLProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
910+
t = tspan !== nothing ? tspan[1] : tspan,
911+
check_length, warn_initialize_determined, eval_expression, eval_module, kwargs...)
912+
913+
cbs = process_events(sys; callback, eval_expression, eval_module, kwargs...)
914+
kwargs = filter_kwargs(kwargs)
915+
916+
kwargs1 = (;)
917+
if cbs !== nothing
918+
kwargs1 = merge(kwargs1, (callback = cbs,))
919+
end
920+
921+
# Define the boundary conditions.
922+
bc = if iip
923+
(residual, u, p, t) -> (residual .= u[1] .- u0)
924+
else
925+
(u, p, t) -> (u[1] - u0)
926+
end
927+
928+
return BVProblem{iip}(f, bc, u0, tspan, p; kwargs1..., kwargs...)
929+
end
930+
931+
get_callback(prob::BVProblem) = error("BVP solvers do not support callbacks.")
932+
933+
@inline function SymbolicUtils.Code.create_array(::Type{<:Base.ReinterpretArray}, ::Nothing,
934+
::Val{1}, ::Val{dims}, elems...) where {dims}
935+
[elems...]
936+
end
937+
938+
@inline function SymbolicUtils.Code.create_array(
939+
::Type{<:Base.ReinterpretArray}, T, ::Val{1}, ::Val{dims}, elems...) where {dims}
940+
T[elems...]
941+
end
942+
946943
"""
947944
```julia
948945
DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan,

test/bvproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ solvers = [MIRK4, RadauIIa5, LobattoIIIa3]
1010
eqs = [D(x) ~ α * x - β * x * y,
1111
D(y) ~ -γ * y + δ * x * y]
1212

13-
u0map = [:x => 1.0, :y => 2.0]
14-
parammap = [:α => 7.5, :β => 4, :γ => 8.0, :δ => 5.0]
13+
u0map = [x => 1.0, y => 2.0]
14+
parammap ==> 7.5, β => 4, γ => 8.0, δ => 5.0]
1515
tspan = (0.0, 10.0)
1616

1717
@mtkbuild lotkavolterra = ODESystem(eqs, t)

0 commit comments

Comments
 (0)