Skip to content

Commit

Permalink
fix: handle I as mass matrix for CheckInit
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 28, 2024
1 parent a5ee8e9 commit 5d0e2ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function get_initial_values(
t = current_time(integrator)
M = f.mass_matrix

M == I && return u0, p, true
algebraic_vars = [all(iszero, x) for x in eachcol(M)]
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return u0, p, true
Expand Down
16 changes: 15 additions & 1 deletion test/initialization.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, Test
using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, LinearAlgebra, Test

@testset "CheckInit" begin
@testset "ODEProblem" begin
Expand Down Expand Up @@ -27,6 +27,20 @@ using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterfac
prob, integ, f, SciMLBase.CheckInit(),
Val(SciMLBase.isinplace(f)); abstol = 1e-10)
end

@testset "With I mass matrix" begin
function rhs(u, p, t)
return u
end
prob = ODEProblem(ODEFunction(rhs; mass_matrix = I), ones(2), (0.0, 1.0))
integ = init(prob)
u0, _, success = SciMLBase.get_initial_values(
prob, integ, prob.f, SciMLBase.CheckInit(),
Val(false); abstol = 1e-10
)
@test success
@test u0 == prob.u0
end
end

@testset "DAEProblem" begin
Expand Down

0 comments on commit 5d0e2ac

Please sign in to comment.