Skip to content

Commit

Permalink
Combine duplicate methods; add error checking if ODENLSolve is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Ickaser committed Dec 9, 2024
1 parent 1749807 commit 5fa3032
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions lib/OrdinaryDiffEqCore/src/initialize_dae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,27 @@ end

## Default algorithms

function _initialize_dae!(integrator, prob::ODEProblem,
alg::DefaultInit, x::Val{true})
if SciMLBase.has_initializeprob(prob.f)
_initialize_dae!(integrator, prob,
OverrideInit(integrator.opts.abstol), x)
else
_initialize_dae!(integrator, prob,
BrownFullBasicInit(integrator.opts.abstol), x)
end
end

function _initialize_dae!(integrator, prob::ODEProblem,
alg::DefaultInit, x::Val{false})
if SciMLBase.has_initializeprob(prob.f)
_initialize_dae!(integrator, prob,
OverrideInit(integrator.opts.abstol), x)
else
_initialize_dae!(integrator, prob,
BrownFullBasicInit(integrator.opts.abstol), x)
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::DefaultInit, x::Val{false})
alg::DefaultInit, x::Union{Val{true}, Val{false}})
if SciMLBase.has_initializeprob(prob.f)
_initialize_dae!(integrator, prob,
OverrideInit(integrator.opts.abstol), x)
elseif prob.differential_vars === nothing
_initialize_dae!(integrator, prob,
ShampineCollocationInit(), x)
elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve)
throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.")
else
_initialize_dae!(integrator, prob,
BrownFullBasicInit(integrator.opts.abstol), x)
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::DefaultInit, x::Val{true})
alg::DefaultInit, x::Union{Val{true}, Val{false}})
if SciMLBase.has_initializeprob(prob.f)
_initialize_dae!(integrator, prob,
OverrideInit(integrator.opts.abstol), x)
elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve)
throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.")
elseif prob.differential_vars === nothing
_initialize_dae!(integrator, prob,
ShampineCollocationInit(), x)
Expand Down

0 comments on commit 5fa3032

Please sign in to comment.