Skip to content

Commit ee4ad4d

Browse files
authored
Merge pull request #2336 from SciML/fb/defpar
handle parameters that only appear as defaults
2 parents 0f94b02 + d715ca3 commit ee4ad4d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/utils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ function collect_var!(states, parameters, var, iv)
492492
elseif !isconstant(var)
493493
push!(states, var)
494494
end
495+
# Add also any parameters that appear only as defaults in the var
496+
if hasdefault(var)
497+
collect_vars!(states, parameters, getdefault(var), iv)
498+
end
495499
return nothing
496500
end
497501

test/odesystem.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,26 @@ new_sys2 = complete(substitute(sys2, Dict(:sub => sub)))
10441044
Set(states(new_sys2)) == Set([new_sys2.x1, new_sys2.sys1.x1,
10451045
new_sys2.sys1.sub.s1, new_sys2.sys1.sub.s2,
10461046
new_sys2.sub.s1, new_sys2.sub.s2])
1047+
1048+
let # Issue https://github.com/SciML/ModelingToolkit.jl/issues/2322
1049+
@parameters a=10 b=a / 10 c=a / 20
1050+
1051+
@variables t
1052+
Dt = Differential(t)
1053+
1054+
@variables x(t)=1 z(t)
1055+
1056+
eqs = [Dt(x) ~ -b * (x - z),
1057+
0 ~ z - c * x]
1058+
1059+
sys = ODESystem(eqs, t; name = :kjshdf)
1060+
1061+
sys_simp = structural_simplify(sys)
1062+
1063+
@test a keys(ModelingToolkit.defaults(sys_simp))
1064+
1065+
tspan = (0.0, 1)
1066+
prob = ODEProblem(sys_simp, [], tspan)
1067+
sol = solve(prob, Rodas4())
1068+
@test sol(1)[]0.6065307685451087 rtol=1e-4
1069+
end

0 commit comments

Comments
 (0)