Skip to content

Commit

Permalink
Unify methods so that CheckInit is default for all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ickaser committed Dec 3, 2024
1 parent 2c930ba commit e9eedf8
Showing 1 changed file with 4 additions and 46 deletions.
50 changes: 4 additions & 46 deletions lib/OrdinaryDiffEqCore/src/initialize_dae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,62 +37,20 @@ variable, then the system is not Index 1!

function DiffEqBase.initialize_dae!(integrator::ODEIntegrator,
initializealg = integrator.initializealg)
if !hasmethod(_initialize_dae!, (typeof(integrator),
typeof(integrator.sol.prob), BrownFullBasicInit,
Val{DiffEqBase.isinplace(integrator.sol.prob)}))
error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.")
end
_initialize_dae!(integrator, integrator.sol.prob,
initializealg,
Val(DiffEqBase.isinplace(integrator.sol.prob)))
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,
CheckInit(), 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,
CheckInit(), x)
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::DefaultInit, x::Val{false})
function _initialize_dae!(integrator,
prob::Union{ODEProblem, DAEProblem},
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)
else
_initialize_dae!(integrator, prob,
CheckInit(), x)
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::DefaultInit, x::Val{true})
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)
else
_initialize_dae!(integrator, prob,
CheckInit(), x)
Expand Down

0 comments on commit e9eedf8

Please sign in to comment.