Skip to content

Commit c1be362

Browse files
feat: allow initializeprobmap to be nothing
1 parent f4eb248 commit c1be362

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/initialization.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ struct OverrideInitData{IProb, UIProb, IProbMap, IProbPmap}
1919
update_initializeprob!::UIProb
2020
"""
2121
A function which takes the solution of `initializeprob` and returns
22-
the state vector of the original problem.
22+
the state vector of the original problem. If absent, the existing state vector
23+
will be used.
2324
"""
2425
initializeprobmap::IProbMap
2526
"""
@@ -260,7 +261,9 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
260261
success = SciMLBase.successful_retcode(nlsol)
261262
end
262263

263-
u0 = initdata.initializeprobmap(nlsol)
264+
if initdata.initializeprobmap !== nothing
265+
u0 = initdata.initializeprobmap(nlsol)
266+
end
264267
if initdata.initializeprobpmap !== nothing
265268
p = initdata.initializeprobpmap(valp, nlsol)
266269
end

test/initialization.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ end
230230
@test success
231231
end
232232

233+
@testset "Solves without `initializeprobmap`" begin
234+
initdata = SciMLBase.@set initialization_data.initializeprobmap = nothing
235+
fn = ODEFunction(rhs2; initialization_data = initdata)
236+
prob = ODEProblem(fn, [2.0, 0.0], (0.0, 1.0), 0.0)
237+
integ = init(prob; initializealg = NoInit())
238+
239+
u0, p, success = SciMLBase.get_initial_values(
240+
prob, integ, fn, SciMLBase.OverrideInit(),
241+
Val(false); nlsolve_alg = NewtonRaphson(), abstol, reltol)
242+
243+
@test u0 [2.0, 0.0]
244+
@test p 1.0
245+
@test success
246+
end
247+
233248
@testset "Solves without `initializeprobpmap`" begin
234249
initdata = SciMLBase.@set initialization_data.initializeprobpmap = nothing
235250
fn = ODEFunction(rhs2; initialization_data = initdata)

0 commit comments

Comments
 (0)