From 5211e189aa0c6b13c069da614a28cbc324e1423b Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 28 Nov 2024 12:18:14 +0530 Subject: [PATCH 1/2] fix: handle `I` as mass matrix for `CheckInit` --- src/initialization.jl | 1 + test/initialization.jl | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/initialization.jl b/src/initialization.jl index 993d10686..4e976e168 100644 --- a/src/initialization.jl +++ b/src/initialization.jl @@ -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 diff --git a/test/initialization.jl b/test/initialization.jl index e6211e59c..1ea1da694 100644 --- a/test/initialization.jl +++ b/test/initialization.jl @@ -1,4 +1,5 @@ -using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, Test +using StochasticDiffEq, OrdinaryDiffEq, NonlinearSolve, SymbolicIndexingInterface, + LinearAlgebra, Test @testset "CheckInit" begin @testset "ODEProblem" begin @@ -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 From 211d997a6eb8ce77eac2e2c648c06f90fe1ded0f Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 29 Nov 2024 16:10:16 +0530 Subject: [PATCH 2/2] refactor: make spellcheck happy --- src/problems/nonlinear_problems.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/problems/nonlinear_problems.jl b/src/problems/nonlinear_problems.jl index b2a9989c4..b61b19ff1 100644 --- a/src/problems/nonlinear_problems.jl +++ b/src/problems/nonlinear_problems.jl @@ -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