Skip to content

Commit 9733460

Browse files
committed
init
1 parent eb681c1 commit 9733460

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,116 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
466466
initializeprobpmap = initializeprobpmap)
467467
end
468468

469+
"""
470+
```julia
471+
SciMLBase.BVProblem{iip}(sys::AbstractODESystem, u0map, tspan,
472+
parammap = DiffEqBase.NullParameters();
473+
version = nothing, tgrad = false,
474+
jac = true, sparse = true,
475+
simplify = false,
476+
kwargs...) where {iip}
477+
```
478+
479+
Create a `BVProblem` from the [`ODESystem`](@ref). The arguments `dvs` and
480+
`ps` are used to set the order of the dependent variable and parameter vectors,
481+
respectively.
482+
"""
483+
function SciMLBase.BVProblem(sys::AbstractODESystem, args...; kwargs...)
484+
BVProblem{true}(sys, args...; kwargs...)
485+
end
486+
487+
function SciMLBase.BVProblem(sys::AbstractODESystem,
488+
u0map::StaticArray,
489+
args...;
490+
kwargs...)
491+
BVProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)
492+
end
493+
494+
function SciMLBase.BVProblem{true}(sys::AbstractODESystem, args...; kwargs...)
495+
BVProblem{true, SciMLBase.AutoSpecialize}(sys, args...; kwargs...)
496+
end
497+
498+
function SciMLBase.BVProblem{false}(sys::AbstractODESystem, args...; kwargs...)
499+
BVProblem{false, SciMLBase.FullSpecialize}(sys, args...; kwargs...)
500+
end
501+
502+
function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = [],
503+
tspan = get_tspan(sys),
504+
parammap = DiffEqBase.NullParameters();
505+
version = nothing, tgrad = false,
506+
jac = true, sparse = true,
507+
sparsity = true,
508+
callback = nothing,
509+
check_length = true,
510+
warn_initialize_determined = true,
511+
eval_expression = false,
512+
eval_module = @__MODULE__,
513+
kwargs...) where {iip, specialize}
514+
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, jac, sparse, sparsity, kwargs...)
522+
523+
# if jac
524+
# jac_gen = generate_jacobian(sys, dvs, ps;
525+
# simplify = simplify, sparse = sparse,
526+
# expression = Val{true},
527+
# expression_module = eval_module,
528+
# checkbounds = checkbounds, kwargs...)
529+
# jac_oop, jac_iip = eval_or_rgf.(jac_gen; eval_expression, eval_module)
530+
531+
# _jac(u, p, t) = jac_oop(u, p, t)
532+
# _jac(J, u, p, t) = jac_iip(J, u, p, t)
533+
# _jac(u, p::Tuple{Vararg{Number}}, t) = jac_oop(u, p, t)
534+
# _jac(J, u, p::Tuple{Vararg{Number}}, t) = jac_iip(J, u, p, t)
535+
# _jac(u, p::Tuple, t) = jac_oop(u, p..., t)
536+
# _jac(J, u, p::Tuple, t) = jac_iip(J, u, p..., t)
537+
# _jac(u, p::MTKParameters, t) = jac_oop(u, p..., t)
538+
# _jac(J, u, p::MTKParameters, t) = jac_iip(J, u, p..., t)
539+
# else
540+
# _jac = nothing
541+
# end
542+
543+
# jac_prototype = if sparse
544+
# uElType = u0 === nothing ? Float64 : eltype(u0)
545+
# if jac
546+
# similar(calculate_jacobian(sys, sparse = sparse), uElType)
547+
# else
548+
# similar(jacobian_sparsity(sys), uElType)
549+
# end
550+
# else
551+
# nothing
552+
# end
553+
554+
# f.jac = _jac
555+
# f.jac_prototype = jac_prototype
556+
# f.sparsity = jac ? jacobian_sparsity(sys) : nothing
557+
558+
cbs = process_events(sys; callback, eval_expression, eval_module, kwargs...)
559+
560+
kwargs = filter_kwargs(kwargs)
561+
562+
kwargs1 = (;)
563+
if cbs !== nothing
564+
kwargs1 = merge(kwargs1, (callback = cbs,))
565+
end
566+
567+
# Define the boundary conditions
568+
bc = if iip
569+
(residual, u, p, t) -> (residual = u[1] - u0)
570+
else
571+
(u, p, t) -> (u[1] - u0)
572+
end
573+
574+
return BVProblem{iip}(f, bc, u0, tspan, p; kwargs1..., kwargs...)
575+
end
576+
577+
get_callback(prob::BVProblem) = prob.kwargs[:callback]
578+
469579
"""
470580
```julia
471581
DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = unknowns(sys),

0 commit comments

Comments
 (0)