Skip to content

Commit d648bc1

Browse files
committed
Test that defaults are overridden when sys is initialized with map from unknowns(sys)
1 parent f156381 commit d648bc1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/initializationsystem.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,22 @@ sys = extend(sysx, sysy)
486486
ssys = structural_simplify(sys)
487487
@test_throws ArgumentError ODEProblem(ssys, [x => 3], (0, 1), []) # y should have a guess
488488
end
489+
490+
# https://github.com/SciML/ModelingToolkit.jl/issues/3025
491+
@testset "Override defaults when setting initial conditions with unknowns(sys) or similar" begin
492+
@variables x(t) y(t)
493+
494+
# system 1 should solve to x = 1
495+
ics1 = [x => 1]
496+
sys1 = ODESystem([D(x) ~ 0], t; defaults = ics1, name = :sys1) |> structural_simplify
497+
prob1 = ODEProblem(sys1, [], (0.0, 1.0), [])
498+
sol1 = solve(prob1, Tsit5())
499+
@test all(sol1[x] .== 1)
500+
501+
# system 2 should solve to x = y = 2
502+
sys2 = extend(sys1, ODESystem([D(y) ~ 0], t; initialization_eqs = [y ~ 2], name = :sys2)) |> structural_simplify
503+
ics2 = unknowns(sys1) .=> 2 # should be equivalent to "ics2 = [x => 2]"
504+
prob2 = ODEProblem(sys2, ics2, (0.0, 1.0), []; fully_determined = true)
505+
sol2 = solve(prob2, Tsit5())
506+
@test all(sol2[x] .== 2) && all(sol2[y] .== 2)
507+
end

0 commit comments

Comments
 (0)