Skip to content

Commit 5210eef

Browse files
committed
get odesystem tests to pass
1 parent 49edc23 commit 5210eef

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

src/build_function.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ end
455455
function term_to_symbol(t::Term)
456456
if operation(t) isa Sym
457457
s = nameof(operation(t))
458-
@show s
459458
else
460459
error("really?")
461460
end

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,11 @@ function calculate_massmatrix(sys::AbstractODESystem; simplify=true)
9090
dvs = states(sys)
9191
M = zeros(length(eqs),length(eqs))
9292
for (i,eq) in enumerate(eqs)
93-
if eq.lhs isa Constant
94-
@assert eq.lhs.value == 0
95-
elseif eq.lhs.op isa Differential
93+
if eq.lhs isa Term && eq.lhs.op isa Differential
9694
j = findfirst(x->isequal(term_to_symbol(x),term_to_symbol(var_from_nested_derivative(eq.lhs)[1])),dvs)
9795
M[i,j] = 1
9896
else
99-
error("Only semi-explicit constant mass matrices are currently supported. Faulty equation: $eq.")
97+
eq.lhs == 0 || error("Only semi-explicit constant mass matrices are currently supported. Faulty equation: $eq.")
10098
end
10199
end
102100
M = simplify ? ModelingToolkit.simplify.(M) : M
@@ -107,7 +105,7 @@ end
107105

108106
jacobian_sparsity(sys::AbstractODESystem) =
109107
jacobian_sparsity([eq.rhs for eq equations(sys)],
110-
[dv(sys.iv()) for dv in states(sys)])
108+
[dv for dv in states(sys)])
111109

112110
function DiffEqBase.ODEFunction(sys::AbstractODESystem, args...; kwargs...)
113111
ODEFunction{true}(sys, args...; kwargs...)

src/systems/diffeqs/modelingtoolkitize.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ function modelingtoolkitize(prob::DiffEqBase.ODEProblem)
77
prob.f isa DiffEqBase.AbstractParameterizedFunction &&
88
return (prob.f.sys, prob.f.sys.states, prob.f.sys.ps)
99
@parameters t
10-
vars = reshape([Variable(:x, i)(t) for i in eachindex(prob.u0)],size(prob.u0))
10+
var(x, i) = Sym{FnType{Tuple{symtype(t)}, Number}}(nameof(Variable(:x, i)))
11+
vars = reshape([var(:x, i)(t) for i in eachindex(prob.u0)],size(prob.u0))
1112
params = prob.p isa DiffEqBase.NullParameters ? [] :
12-
reshape([Variable(,i)() for i in eachindex(prob.p)],size(prob.p))
13+
reshape([Variable(,i) for i in eachindex(prob.p)],size(prob.p))
1314
@derivatives D'~t
1415

1516
rhs = [D(var) for var in vars]

src/variables.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ creates the array of values in the correct order
241241
function varmap_to_vars(varmap::AbstractArray{<:Pair},varlist)
242242
out = similar(varmap,typeof(last(first(varmap))))
243243
for i in 1:length(varmap)
244-
ivar = convert(Variable,varmap[i][1])
245-
j = findfirst(x->ivar.name == convert(Variable,x).name,varlist)
244+
ivar = varmap[i][1]
245+
j = findfirst(isequal(ivar),varlist)
246246
out[j] = varmap[i][2]
247247
end
248248

test/odesystem.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ u = SVector(1:3...)
5050
p = SVector(4:6...)
5151
@test f(u, p, 0.1) === @SArray [4, 0, -16]
5252

53-
@show y
5453
eqs = [D(x) ~ σ*(y-x),
5554
D(y) ~ x*-z)-y*t,
5655
D(z) ~ x*y - β*z]

0 commit comments

Comments
 (0)