Skip to content

Commit b2e33c5

Browse files
Merge pull request #540 from SciML/myb/fix
Convert user supplied independent variable to Variable and better err…
2 parents fa3914e + b454c32 commit b2e33c5

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ end
188188
namespace_operation(O::Constant,name,ivname) = O
189189

190190
independent_variable(sys::AbstractSystem) = sys.iv
191-
states(sys::AbstractSystem) = isempty(sys.systems) ? setdiff(sys.states, convert.(Variable,sys.pins)) : [sys.states;reduce(vcat,namespace_variables.(sys.systems))]
191+
states(sys::AbstractSystem) = unique(isempty(sys.systems) ? setdiff(sys.states, convert.(Variable,sys.pins)) : [sys.states;reduce(vcat,namespace_variables.(sys.systems))])
192192
parameters(sys::AbstractSystem) = isempty(sys.systems) ? sys.ps : [sys.ps;reduce(vcat,namespace_parameters.(sys.systems))]
193193
pins(sys::AbstractSystem) = isempty(sys.systems) ? sys.pins : [sys.pins;reduce(vcat,namespace_pins.(sys.systems))]
194194
function observed(sys::AbstractSystem)

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function calculate_massmatrix(sys::AbstractODESystem; simplify=true)
7979
j = findfirst(x->isequal(x.name,var_from_nested_derivative(eq.lhs)[1].name),dvs)
8080
M[i,j] = 1
8181
else
82-
error("Only semi-explicit constant mass matrices are currently supported")
82+
error("Only semi-explicit constant mass matrices are currently supported. Faulty equation: $eq.")
8383
end
8484
end
8585
M = simplify ? ModelingToolkit.simplify.(M) : M

src/systems/diffeqs/odesystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ function ODESystem(eqs, iv=nothing; kwargs...)
100100
break
101101
end
102102
end
103+
else
104+
iv = convert(Variable, iv)
103105
end
104106
iv === nothing && throw(ArgumentError("Please pass in independent variables."))
105107
for eq in eqs

test/mass_matrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ eqs = [D(y[1]) ~ -k[1]*y[1] + k[3]*y[2]*y[3],
99
0 ~ y[1] + y[2] + y[3] - 1]
1010

1111
sys = ODESystem(eqs,t,y,k)
12-
@test_throws ArgumentError ODESystem(eqs,y)
12+
@test_throws ArgumentError ODESystem(eqs,y[1])
1313
M = calculate_massmatrix(sys)
1414
@test M == [1 0 0
1515
0 1 0

0 commit comments

Comments
 (0)