Skip to content

Commit 5d0e2ac

Browse files
fix: handle I as mass matrix for CheckInit
1 parent a5ee8e9 commit 5d0e2ac

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/initialization.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ function get_initial_values(
123123
t = current_time(integrator)
124124
M = f.mass_matrix
125125

126+
M == I && return u0, p, true
126127
algebraic_vars = [all(iszero, x) for x in eachcol(M)]
127128
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
128129
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return u0, p, true

test/initialization.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, Test
1+
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, LinearAlgebra, Test
22

33
@testset "CheckInit" begin
44
@testset "ODEProblem" begin
@@ -27,6 +27,20 @@ using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterfac
2727
prob, integ, f, SciMLBase.CheckInit(),
2828
Val(SciMLBase.isinplace(f)); abstol = 1e-10)
2929
end
30+
31+
@testset "With I mass matrix" begin
32+
function rhs(u, p, t)
33+
return u
34+
end
35+
prob = ODEProblem(ODEFunction(rhs; mass_matrix = I), ones(2), (0.0, 1.0))
36+
integ = init(prob)
37+
u0, _, success = SciMLBase.get_initial_values(
38+
prob, integ, prob.f, SciMLBase.CheckInit(),
39+
Val(false); abstol = 1e-10
40+
)
41+
@test success
42+
@test u0 == prob.u0
43+
end
3044
end
3145

3246
@testset "DAEProblem" begin

0 commit comments

Comments
 (0)