Skip to content

Commit 10dd1d4

Browse files
Merge pull request #880 from AayushSabharwal/as/checkinit-I-mm
fix: handle `I` as mass matrix for `CheckInit`
2 parents a5ee8e9 + 211d997 commit 10dd1d4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
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

src/problems/nonlinear_problems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ and below.
385385
!!! warn
386386
While `explictfuns![i]` could in theory use `sols[i+1]` in its computation,
387387
these values will not be updated. It is thus the contract of the interface
388-
to not use those values except for as caches to be overriden.
388+
to not use those values except for as caches to be overridden.
389389
390390
!!! note
391391
prob.probs[i].p can be aliased with each other as a performance / memory

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)