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
7 changes: 5 additions & 2 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct OverrideInitData{IProb, UIProb, IProbMap, IProbPmap}
update_initializeprob!::UIProb
"""
A function which takes the solution of `initializeprob` and returns
the state vector of the original problem.
the state vector of the original problem. If absent, the existing state vector
will be used.
"""
initializeprobmap::IProbMap
"""
Expand Down Expand Up @@ -260,7 +261,9 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
success = SciMLBase.successful_retcode(nlsol)
end

u0 = initdata.initializeprobmap(nlsol)
if initdata.initializeprobmap !== nothing
u0 = initdata.initializeprobmap(nlsol)
end
if initdata.initializeprobpmap !== nothing
p = initdata.initializeprobpmap(valp, nlsol)
end
Expand Down
15 changes: 15 additions & 0 deletions test/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ end
@test success
end

@testset "Solves without `initializeprobmap`" begin
initdata = SciMLBase.@set initialization_data.initializeprobmap = nothing
fn = ODEFunction(rhs2; initialization_data = initdata)
prob = ODEProblem(fn, [2.0, 0.0], (0.0, 1.0), 0.0)
integ = init(prob; initializealg = NoInit())

u0, p, success = SciMLBase.get_initial_values(
prob, integ, fn, SciMLBase.OverrideInit(),
Val(false); nlsolve_alg = NewtonRaphson(), abstol, reltol)

@test u0 ≈ [2.0, 0.0]
@test p ≈ 1.0
@test success
end

@testset "Solves without `initializeprobpmap`" begin
initdata = SciMLBase.@set initialization_data.initializeprobpmap = nothing
fn = ODEFunction(rhs2; initialization_data = initdata)
Expand Down
Loading