Skip to content

Commit e855035

Browse files
fix: handle nothing passed as u0 to ODEProblem
fix: handle non-vector non-symbolic array u0 for ODEProblem
1 parent 9aadc71 commit e855035

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,12 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap;
817817
ModelingToolkit.get_tearing_state(sys) !== nothing) ||
818818
!isempty(initialization_equations(sys))) && t !== nothing
819819
if eltype(u0map) <: Number
820-
u0map = unknowns(sys) .=> u0map
820+
u0map = unknowns(sys) .=> vec(u0map)
821821
end
822-
if isempty(u0map)
822+
if u0map === nothing || isempty(u0map)
823823
u0map = Dict()
824824
end
825+
825826
initializeprob = ModelingToolkit.InitializationProblem(
826827
sys, t, u0map, parammap; guesses, warn_initialize_determined,
827828
initialization_eqs, eval_expression, eval_module, fully_determined, check_units)

test/odesystem.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,3 +1387,10 @@ end
13871387

13881388
@test obsfn(ones(2), 2ones(2), 3ones(4), 4.0) == 6ones(2)
13891389
end
1390+
1391+
@testset "Passing `nothing` to `u0`" begin
1392+
@variables x(t) = 1
1393+
@mtkbuild sys = ODEProblem(D(x) ~ t, t)
1394+
prob = @test_nowarn ODEProblem(sys, nothing, (0.0, 1.0))
1395+
@test_nowarn solve(prob)
1396+
end

0 commit comments

Comments
 (0)