Skip to content

Commit 9783277

Browse files
refactor: improve BVProblem validation
1 parent 573d272 commit 9783277

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/problems/bvproblem.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ If the `System` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
4646
@fallback_iip_specialize function SciMLBase.BVProblem{iip, spec}(
4747
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
4848
check_compatibility = true, cse = true, checkbounds = false, eval_expression = false,
49-
eval_module = @__MODULE__, guesses = Dict(), kwargs...) where {iip, spec}
49+
eval_module = @__MODULE__, guesses = Dict(), callback = nothing, kwargs...) where {
50+
iip, spec}
5051
check_complete(sys, BVProblem)
5152
check_compatibility && check_compatible_system(BVProblem, sys)
53+
isnothing(callback) || error("BVP solvers do not support callbacks.")
5254

53-
# ODESystems without algebraic equations should use both fixed values + guesses
55+
# Systems without algebraic equations should use both fixed values + guesses
5456
# for initialization.
5557
_u0map = has_alg_eqs(sys) ? u0map : merge(Dict(u0map), Dict(guesses))
5658
fode, u0, p = process_SciMLProblem(
@@ -63,17 +65,26 @@ If the `System` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
6365
u0_idxs = has_alg_eqs(sys) ? collect(1:length(dvs)) : [stidxmap[k] for (k, v) in u0map]
6466
fbc = generate_boundary_conditions(
6567
sys, u0, u0_idxs, tspan; expression = Val{false}, cse, checkbounds)
68+
69+
if (length(constraints(sys)) + length(u0map) > length(dvs))
70+
@warn "The BVProblem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by u0map) exceeds the total number of states. The BVP solvers will default to doing a nonlinear least-squares optimization."
71+
end
72+
6673
kwargs = process_kwargs(sys; kwargs...)
6774
# Call `remake` so it runs initialization if it is trivial
6875
return remake(BVProblem{iip}(fode, fbc, u0, tspan[1], p; kwargs...))
6976
end
7077

71-
function check_compatible_system(T::Union{Type{BVPFunction}, Type{BVProblem}}, sys::System)
78+
function check_compatible_system(T::Type{BVProblem}, sys::System)
7279
check_time_dependent(sys, T)
7380
check_not_dde(sys)
7481
check_no_cost(sys, T)
7582
check_has_constraints(sys, T)
7683
check_no_jumps(sys, T)
7784
check_no_noise(sys, T)
7885
check_is_continuous(sys, T)
86+
87+
if !isempty(discrete_events(sys)) || !isempty(continuous_events(sys))
88+
throw(SystemCompatibilityError("BVP solvers do not support events."))
89+
end
7990
end

0 commit comments

Comments
 (0)