Skip to content

Commit

Permalink
Merge pull request #880 from AayushSabharwal/as/checkinit-I-mm
Browse files Browse the repository at this point in the history
fix: handle `I` as mass matrix for `CheckInit`
  • Loading branch information
AayushSabharwal authored Nov 29, 2024
2 parents a5ee8e9 + 211d997 commit 10dd1d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion src/problems/nonlinear_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ and below.
!!! warn
While `explictfuns![i]` could in theory use `sols[i+1]` in its computation,
these values will not be updated. It is thus the contract of the interface
to not use those values except for as caches to be overriden.
to not use those values except for as caches to be overridden.
!!! note
prob.probs[i].p can be aliased with each other as a performance / memory
Expand Down
17 changes: 16 additions & 1 deletion test/initialization.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 +28,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 10dd1d4

Please sign in to comment.