Skip to content

Commit 1040ce9

Browse files
fix: handle partially symbolic initial condition for array variable
1 parent 1dc34c6 commit 1040ce9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/ModelingToolkitBase/src/systems/nonlinear/initializesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ function timevaring_initsys_process_op!(
458458
ikk = Initial(kk)
459459
if SU.isconst(vv)
460460
push!(eqs_ics, subkk ~ ikk)
461+
write_possibly_indexed_array!(op, ikk, vv, COMMON_FALSE)
461462
else
462463
write_possibly_indexed_array!(guesses, kk, vv, COMMON_FALSE)
463464
vv = fixpoint_sub(vv, derivative_rules; maxiters = get_maxiters(derivative_rules))

lib/ModelingToolkitBase/test/initializationsystem.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,3 +1914,19 @@ end
19141914
@test_nowarn remake(oprob; p = SA[:p => 2.0, :d => 0.1])
19151915
@test_nowarn remake(oprob; p = (:p => 2.0, :d => 0.1))
19161916
end
1917+
1918+
@testset "Issue#4151: Partially symbolic initial conditions for array variable" begin
1919+
@variables x(t)[1:3] y(t)[1:1]
1920+
eqs = [
1921+
Dt(x)[1:2] ~ sin.(x[1:2]),
1922+
Dt(x)[3] ~ 0,
1923+
y[1] ~ x[1],
1924+
]
1925+
x0 = [1.3, 4.5]
1926+
ics = [x => [x0; y]]
1927+
@mtkcompile sys = System(eqs, t, [x, y], [], initial_conditions = ics)
1928+
prob = ODEProblem(sys, nothing, (0.0, 1.0))
1929+
@test prob.ps[Initial(x)][1:2] == x0
1930+
sol = solve(prob, Tsit5())
1931+
@test sol[x[1:2]][1] == x0
1932+
end

0 commit comments

Comments
 (0)