Skip to content

Commit

Permalink
Merge pull request #309 from SciML/myb/first_order
Browse files Browse the repository at this point in the history
Generate a full list of vars in `ode_order_lowering`
  • Loading branch information
YingboMa committed Apr 15, 2020
2 parents a13d70d + 15e6c27 commit 6cb4f23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

2 comments on commit 6cb4f23

@YingboMa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/13051

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.0.1 -m "<description of version>" 6cb4f2354b3a75a41527fde7443de9f2b3fe1576
git push origin v3.0.1

Please sign in to comment.