Skip to content

Commit

Permalink
Merge pull request #2336 from SciML/fb/defpar
Browse files Browse the repository at this point in the history
handle parameters that only appear as defaults
  • Loading branch information
baggepinnen authored Nov 3, 2023
2 parents 0f94b02 + d715ca3 commit ee4ad4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ function collect_var!(states, parameters, var, iv)
elseif !isconstant(var)
push!(states, var)
end
# Add also any parameters that appear only as defaults in the var
if hasdefault(var)
collect_vars!(states, parameters, getdefault(var), iv)
end
return nothing
end

Expand Down
23 changes: 23 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,26 @@ new_sys2 = complete(substitute(sys2, Dict(:sub => sub)))
Set(states(new_sys2)) == Set([new_sys2.x1, new_sys2.sys1.x1,
new_sys2.sys1.sub.s1, new_sys2.sys1.sub.s2,
new_sys2.sub.s1, new_sys2.sub.s2])

let # Issue https://github.com/SciML/ModelingToolkit.jl/issues/2322
@parameters a=10 b=a / 10 c=a / 20

@variables t
Dt = Differential(t)

@variables x(t)=1 z(t)

eqs = [Dt(x) ~ -b * (x - z),
0 ~ z - c * x]

sys = ODESystem(eqs, t; name = :kjshdf)

sys_simp = structural_simplify(sys)

@test a keys(ModelingToolkit.defaults(sys_simp))

tspan = (0.0, 1)
prob = ODEProblem(sys_simp, [], tspan)
sol = solve(prob, Rodas4())
@test sol(1)[]0.6065307685451087 rtol=1e-4
end

0 comments on commit ee4ad4d

Please sign in to comment.