diff --git a/src/initialization.jl b/src/initialization.jl index 7945e64ae..83c4819c7 100644 --- a/src/initialization.jl +++ b/src/initialization.jl @@ -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...) @@ -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 @@ -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 diff --git a/test/initialization.jl b/test/initialization.jl index fed198404..e275751df 100644 --- a/test/initialization.jl +++ b/test/initialization.jl @@ -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 @@ -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)