Skip to content

Commit ab2caef

Browse files
committed
Copy sanity-check logic for differentials to inner constructor so that it applies to all ways of forming an ODESystem.
1 parent 387e7e7 commit ab2caef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,26 @@ struct ODESystem <: AbstractODESystem
7373
type: type of the system
7474
"""
7575
connection_type::Any
76+
77+
function ODESystem(deqs, iv, dvs, ps, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, structure, connection_type)
78+
check_differentials(deqs,iv)
79+
new(deqs, iv, dvs, ps, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, structure, connection_type)
80+
end
7681
end
7782

83+
function check_differentials(eqs,iv)
84+
diffvars = OrderedSet()
85+
for eq in eqs
86+
if isdiffeq(eq)
87+
lhs = eq.lhs
88+
diffvar, _ = var_from_nested_derivative(eq.lhs)
89+
isequal(iv, iv_from_nested_derivative(lhs)) || throw(ArgumentError("Differential variable $diffvar is not a function of independent variable $iv."))
90+
diffvar in diffvars && throw(ArgumentError("The differential variable $diffvar is not unique in the system of equations."))
91+
push!(diffvars, diffvar)
92+
end
93+
end
94+
end
95+
7896
function ODESystem(
7997
deqs::AbstractVector{<:Equation}, iv, dvs, ps;
8098
observed = Num[],

0 commit comments

Comments
 (0)