Skip to content

Commit 5211e18

Browse files
fix: handle I as mass matrix for CheckInit
1 parent a5ee8e9 commit 5211e18

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, Test
1+
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface,
2+
LinearAlgebra, Test
23

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

3247
@testset "DAEProblem" begin

0 commit comments

Comments
 (0)