Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle parameters that only appear as defaults #2336

Merged
merged 1 commit into from
Nov 3, 2023
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
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 @@
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)

Check warning on line 497 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L496-L497

Added lines #L496 - L497 were not covered by tests
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
Loading