Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a full list of vars in ode_order_lowering #309

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelingToolkit"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
version = "3.0.0"
version = "3.0.1"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
15 changes: 9 additions & 6 deletions src/systems/diffeqs/first_order_transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ Takes a Nth order ODESystem and returns a new ODESystem written in first order
form by defining new variables which represent the N-1 derivatives.
"""
function ode_order_lowering(sys::ODESystem)
eqs_lowered, new_vars = ode_order_lowering(sys.eqs, sys.iv)
ODESystem(eqs_lowered, sys.iv, vcat(new_vars, states(sys)), sys.ps)
eqs_lowered, new_vars = ode_order_lowering(equations(sys), sys.iv, states(sys))
return ODESystem(eqs_lowered, sys.iv, new_vars, sys.ps)
end

function ode_order_lowering(eqs, iv)
function ode_order_lowering(eqs, iv, states)
var_order = Dict{Variable,Int}()
vars = Variable[]
new_eqs = Equation[]
new_vars = Variable[]
D = Differential(iv())

for (i, eq) ∈ enumerate(eqs)
for (i, (eq, ss)) ∈ enumerate(zip(eqs, states))
if isequal(eq.lhs, Constant(0))
push!(new_vars, ss)
push!(new_eqs, eq)
else
var, maxorder = var_from_nested_derivative(eq.lhs)
Expand All @@ -40,7 +42,8 @@ function ode_order_lowering(eqs, iv)
end
var′ = lower_varname(var, iv, maxorder - 1)
rhs′ = rename_lower_order(eq.rhs)
push!(new_eqs,Differential(iv())(var′(iv())) ~ rhs′)
push!(new_vars, var′)
push!(new_eqs, D(var′(iv())) ~ rhs′)
end
end

Expand All @@ -49,7 +52,7 @@ function ode_order_lowering(eqs, iv)
for o in (order-1):-1:1
lvar = lower_varname(var, iv, o-1)
rvar = lower_varname(var, iv, o)
push!(new_vars, rvar)
push!(new_vars, lvar)

rhs = rvar(iv())
eq = Differential(iv())(lvar(iv())) ~ rhs
Expand Down