Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ Keyword arguments:
If the former is `nothing`, this keyword argument will be used. If it is also not provided,
an error will be thrown.

All additional keyword arguments are forwarded to `solve`.

In case the initialization problem is trivial, `nlsolve_alg`, `abstol` and `reltol` are
not required.
not required. `solve` is also not called.
"""
function get_initial_values(prob, valp, f, alg::OverrideInit,
iip::Union{Val{true}, Val{false}}; nlsolve_alg = nothing, abstol = nothing, reltol = nothing, kwargs...)
Expand Down Expand Up @@ -257,7 +259,7 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
else
throw(OverrideInitNoTolerance(:reltol))
end
nlsol = solve(initprob, nlsolve_alg; abstol = _abstol, reltol = _reltol)
nlsol = solve(initprob, nlsolve_alg; abstol = _abstol, reltol = _reltol, kwargs...)
success = SciMLBase.successful_retcode(nlsol)
end

Expand Down Expand Up @@ -304,7 +306,8 @@ function initialization_status(prob::AbstractSciMLProblem)
iprob = prob.f.initialization_data.initializeprob
isnothing(prob) && return nothing

nunknowns = iprob.u0 === nothing ? 0 : length(iprob.u0)
iu0 = state_values(iprob)
nunknowns = iu0 === nothing ? 0 : length(iu0)
neqs = if __has_resid_prototype(iprob.f) && iprob.f.resid_prototype !== nothing
length(iprob.f.resid_prototype)
else
Expand Down
17 changes: 17 additions & 0 deletions test/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ end
@test p ≈ 1.0
@test success
end
@testset "with kwargs provided to `get_initial_values`" begin
u0, p, success = SciMLBase.get_initial_values(
prob, integ, fn, SciMLBase.OverrideInit(),
Val(false); nlsolve_alg = NewtonRaphson(), abstol, reltol, u0 = [-1.0, 1.0])
@test u0 ≈ [2.0, -2.0]
@test p ≈ 1.0
@test success
end
end

@testset "Solves with non-integrator value provider" begin
Expand Down Expand Up @@ -262,6 +270,15 @@ end
@test success
end

@testset "Initialization status for `SCCNonlinearProblem`" begin
initprob = SCCNonlinearProblem([initprob], [Returns(nothing)])
initialization_data = SciMLBase.OverrideInitData(
initprob, nothing, nothing, nothing)
fn = ODEFunction(rhs2; initialization_data)
prob = ODEProblem(fn, [2.0, 0.0], (0.0, 1.0), 0.0)
@test SciMLBase.initialization_status(prob) == SciMLBase.FULLY_DETERMINED
end

@testset "Trivial initialization" begin
initprob = NonlinearProblem(Returns(nothing), nothing, [1.0])
update_initializeprob! = function (iprob, integ)
Expand Down
Loading