Skip to content

Commit 57a1325

Browse files
authored
Merge pull request #899 from pepijndevos/sanitycheck
Add check to avoid accidental singulatity error after structural_simplify
2 parents 96745ca + ebd8392 commit 57a1325

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ function process_DEProblem(constructor, sys::AbstractODESystem,u0map,parammap;
291291
u0 = varmap_to_vars(u0map,dvs; defaults=defs)
292292
p = varmap_to_vars(parammap,ps; defaults=defs)
293293

294+
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
295+
294296
f = constructor(sys,dvs,ps,u0;tgrad=tgrad,jac=jac,checkbounds=checkbounds,
295297
linenumbers=linenumbers,parallel=parallel,simplify=simplify,
296298
sparse=sparse,eval_expression=eval_expression,kwargs...)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ function process_NonlinearProblem(constructor, sys::NonlinearSystem,u0map,paramm
211211
u0 = varmap_to_vars(u0map,dvs; defaults=defs)
212212
p = varmap_to_vars(parammap,ps; defaults=defs)
213213

214+
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
215+
214216
f = constructor(sys,dvs,ps,u0;jac=jac,checkbounds=checkbounds,
215217
linenumbers=linenumbers,parallel=parallel,simplify=simplify,
216218
sparse=sparse,eval_expression=eval_expression,kwargs...)

test/nonlinearsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ prob = NonlinearProblem(ns,ones(3),ones(3))
7575
sol = solve(prob,NewtonRaphson())
7676
@test sol.u[1] sol.u[2]
7777

78+
@test_throws ArgumentError NonlinearProblem(ns,ones(4),ones(3))
79+
7880
@variables u F s a
7981
eqs1 = [
8082
0 ~ σ*(y-x) + F,

test/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ for (prob, atol) in [(prob1, 1e-12), (prob2, 1e-12), (prob3, 1e-12)]
230230
sol = solve(prob, Rodas5())
231231
@test all(x->(sum(x), 1.0, atol=atol), sol.u)
232232
end
233+
@test_throws ArgumentError ODEProblem(sys,zeros(5),tspan,p)
233234

234235
@parameters t σ β
235236
@variables x(t) y(t) z(t)

0 commit comments

Comments
 (0)