Skip to content

Commit b072a12

Browse files
fix: fix initializeprobpmap call in OverrideInit
1 parent b44504b commit b072a12

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/initialization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct OverrideInitData{IProb, UIProb, IProbMap, IProbPmap}
2323
"""
2424
initializeprobmap::IProbMap
2525
"""
26-
A function which takes the solution of `initializeprob` and returns
26+
A function which takes `value_provider` and the solution of `initializeprob` and returns
2727
the parameter object of the original problem. If absent (`nothing`),
2828
this will not be called and the parameters of the problem being
2929
initialized will be returned as-is.
@@ -210,7 +210,7 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
210210

211211
u0 = initdata.initializeprobmap(nlsol)
212212
if initdata.initializeprobpmap !== nothing
213-
p = initdata.initializeprobpmap(nlsol)
213+
p = initdata.initializeprobpmap(valp, nlsol)
214214
end
215215

216216
return u0, p, SciMLBase.successful_retcode(nlsol)

test/downstream/initialization.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OrdinaryDiffEq, Sundials, SciMLBase, Test
1+
using ModelingToolkit, NonlinearSolve, OrdinaryDiffEq, Sundials, SciMLBase, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
23

34
@testset "CheckInit" begin
45
abstol = 1e-10
@@ -59,3 +60,26 @@ using OrdinaryDiffEq, Sundials, SciMLBase, Test
5960
end
6061
end
6162
end
63+
64+
@testset "OverrideInit with MTK" begin
65+
abstol = 1e-10
66+
reltol = 1e-8
67+
68+
@variables x(t) [guess = 1.0] y(t) [guess = 1.0]
69+
@parameters p=missing [guess = 1.0] q=missing [guess = 1.0]
70+
@mtkbuild sys = ODESystem([D(x) ~ p * y + q * t, D(y) ~ 5x + q], t;
71+
initialization_eqs = [p^2 + q^2 ~ 3, x^3 + y^3 ~ 5])
72+
prob = ODEProblem(
73+
sys, [x => 1.0], (0.0, 1.0), [p => 1.0]; initializealg = SciMLBase.NoInit())
74+
75+
@test prob.f.initialization_data isa SciMLBase.OverrideInitData
76+
integ = init(prob, Tsit5())
77+
u0, pobj, success = SciMLBase.get_initial_values(
78+
prob, integ, prob.f, SciMLBase.OverrideInit(), Val(true);
79+
nlsolve_alg = NewtonRaphson(), abstol, reltol)
80+
81+
@test getu(sys, x)(u0) 1.0
82+
@test getu(sys, y)(u0) cbrt(4)
83+
@test getp(sys, p)(pobj) 1.0
84+
@test getp(sys, q)(pobj) sqrt(2)
85+
end

0 commit comments

Comments
 (0)