Skip to content

Commit ea5531f

Browse files
almost v0.7 compatible
1 parent b98f424 commit ea5531f

20 files changed

+36
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ModelingToolkit.generate_ode_function(de)
8080
and get the generated function via:
8181

8282
```julia
83-
f = DiffEqFunction(de)
83+
f = ODEFunction(de)
8484
```
8585

8686
### Example: Nonlinear System

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
julia 0.6
1+
julia 0.7-beta2
22
MacroTools
3-
IterTools
43
DiffEqBase
54
DiffRules
65
SpecialFunctions
76
NaNMath
7+
StaticArrays

src/ModelingToolkit.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module ModelingToolkit
22

33
using DiffEqBase
4-
using StaticArrays
4+
using StaticArrays, LinearAlgebra
55

6+
using MacroTools
67
import MacroTools: splitdef, combinedef
7-
import IterTools: product
88

99
abstract type Expression <: Number end
1010
abstract type AbstractOperation <: Expression end

src/domains.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ struct ProductDomain{T} <: AbstractDomain
1515
domains::T
1616
end
1717

18-
Base.:*(x::AbstractDomain...) = ProductDomain((x...))
18+
Base.:*(x::AbstractDomain...) = ProductDomain((x...,))
1919

2020
export Reals, DiscreteDomain, Interval, ProductDomain

src/function_registration.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro register(sig)
2323
end
2424
# Create all valid combinations of Expression,Number for function signature
2525
function typed_args(args)
26-
cases = product(Tuple((:Expression, :Number) for i = 1:length(args))...)
26+
cases = Iterators.product(Tuple((:Expression, :Number) for i = 1:length(args))...)
2727
typargs = Vector{Any}[]
2828
for case in cases
2929
typarg = [Expr(:(::), args[i], case[i]) for i = 1:length(args)]
@@ -48,4 +48,4 @@ for fun = (:<, :>, :(==), :~, :!, :&, :|, :div, :max, :min)
4848
end
4949

5050
# ifelse
51-
@register Base.ifelse(cond,t,f)
51+
#@register Base.ifelse(cond,t,f)

src/operations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ function Base.:(==)(x::Operation,y::Operation)
1010
end
1111
Base.:(==)(x::Operation,y::Number) = false
1212
Base.:(==)(x::Number,y::Operation) = false
13-
Base.:(==)(x::Operation,y::Void) = false
14-
Base.:(==)(x::Void,y::Operation) = false
13+
Base.:(==)(x::Operation,y::Nothing) = false
14+
Base.:(==)(x::Nothing,y::Operation) = false
1515
Base.:(==)(x::Variable,y::Operation) = false
1616
Base.:(==)(x::Operation,y::Variable) = false
1717

src/simplify.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function _simplify_constants(O,shorten_tree = true)
2020
if Symbol(O.op) == cur_op
2121
# Shrink tree
2222
if any(x->typeof(x)<:Operation && Symbol(x.op) == cur_op ,O.args)
23-
idxs = find(x->typeof(x)<:Operation && Symbol(x.op) == cur_op,O.args)
23+
idxs = findall(x->typeof(x)<:Operation && Symbol(x.op) == cur_op,O.args)
2424
keep_idxs = 1:length(O.args) .∉ (idxs,)
2525
args = Vector{Expression}[O.args[i].args for i in idxs]
2626
push!(args,O.args[keep_idxs])
2727
return Operation(O.op,vcat(args...))
2828
# Collapse constants
29-
elseif length(find(x->typeof(x)<:Variable && x.subtype == :Constant ,O.args)) > 1
30-
idxs = find(x->typeof(x)<:Variable && x.subtype == :Constant ,O.args)
29+
elseif length(findall(x->typeof(x)<:Variable && x.subtype == :Constant ,O.args)) > 1
30+
idxs = findall(x->typeof(x)<:Variable && x.subtype == :Constant ,O.args)
3131
other_idxs = 1:length(O.args) .∉ (idxs,)
3232
if cur_op == :*
3333
new_var = Constant(prod(x->x.value,O.args[idxs]))
@@ -53,7 +53,7 @@ function _simplify_constants(O,shorten_tree = true)
5353
if any(x->typeof(x)<:Variable && (isequal(x,Constant(0)) || isequal(x,Constant(-0))),O.args)
5454
return Constant(0)
5555
elseif any(x->typeof(x)<:Variable && isequal(x,Constant(1)),O.args)
56-
idxs = find(x->typeof(x)<:Variable && isequal(x,Constant(1)),O.args)
56+
idxs = findall(x->typeof(x)<:Variable && isequal(x,Constant(1)),O.args)
5757
_O = Operation(O.op,O.args[1:length(O.args) .∉ (idxs,)])
5858
if isempty(_O.args)
5959
return Constant(1)
@@ -68,7 +68,7 @@ function _simplify_constants(O,shorten_tree = true)
6868
elseif Symbol(O.op) == :+ && any(x->typeof(x)<:Variable &&
6969
(isequal(x,Constant(0)) || isequal(x,Constant(-0))),O.args)
7070
# If there are Constant(0)s in a big `+` expression, get rid of them
71-
idxs = find(x->typeof(x)<:Variable && (isequal(x,Constant(0)) || isequal(x,Constant(-0))),O.args)
71+
idxs = findall(x->typeof(x)<:Variable && (isequal(x,Constant(0)) || isequal(x,Constant(-0))),O.args)
7272
_O = Operation(O.op,O.args[1:length(O.args) .∉ (idxs,)])
7373
if isempty(_O.args)
7474
return Constant(0)

src/systems/diffeqs/diffeqsystem.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function DiffEqSystem(eqs, ivs, dvs, vs, ps)
1414
iv_name = ivs[1].subtype
1515
dv_name = dvs[1].subtype
1616
p_name = isempty(ps) ? :Parameter : ps[1].subtype
17-
DiffEqSystem(eqs, ivs, dvs, vs, ps, iv_name, dv_name, p_name, Matrix{Expression}(0,0))
17+
DiffEqSystem(eqs, ivs, dvs, vs, ps, iv_name, dv_name, p_name, Matrix{Expression}(undef,0,0))
1818
end
1919

2020
function DiffEqSystem(eqs; iv_name = :IndependentVariable,
@@ -98,15 +98,15 @@ function generate_ode_iW(sys::DiffEqSystem,simplify=true)
9898

9999
gam = Variable(:gam)
100100

101-
W = I - gam*jac
101+
W = LinearAlgebra.I - gam*jac
102102
W = SMatrix{size(W,1),size(W,2)}(W)
103103
iW = inv(W)
104104

105105
if simplify
106106
iW = simplify_constants.(iW)
107107
end
108108

109-
W = inv(I/gam - jac)
109+
W = inv(LinearAlgebra.I/gam - jac)
110110
W = SMatrix{size(W,1),size(W,2)}(W)
111111
iW_t = inv(W)
112112
if simplify
@@ -123,10 +123,10 @@ function generate_ode_iW(sys::DiffEqSystem,simplify=true)
123123
:((iW,u,p,gam,t)->$(block)),:((iW,u,p,gam,t)->$(block2))
124124
end
125125

126-
function DiffEqBase.DiffEqFunction(sys::DiffEqSystem)
126+
function DiffEqBase.ODEFunction(sys::DiffEqSystem)
127127
expr = generate_ode_function(sys)
128-
DiffEqFunction{true}(eval(expr))
128+
ODEFunction{true}(eval(expr))
129129
end
130130

131-
export DiffEqSystem, DiffEqFunction
131+
export DiffEqSystem, ODEFunction
132132
export generate_ode_function

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ isblock(x) = length(x) == 1 && x[1] isa Expr && x[1].head == :block
99
function flatten_expr!(x)
1010
isb = isblock(x)
1111
if isb
12-
x = x[1]
12+
x = MacroTools.striplines(x[1])
1313
filter!(z->z isa Symbol || z.head != :line, x.args)
14-
x = (x.args...)
14+
x = (x.args...,)
1515
end
1616
x
1717
end

src/variables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mutable struct Variable <: Expression
33
value
44
value_type::DataType
55
subtype::Symbol
6-
diff::Union{AbstractOperator,Void}
6+
diff::Union{AbstractOperator,Nothing}
77
dependents::Vector{Variable}
88
description::String
99
flow::Bool

0 commit comments

Comments
 (0)