Skip to content

Commit 517c8d1

Browse files
Replace prior :Variable with Julia variable assignment
1 parent c215a8d commit 517c8d1

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Each operation builds an `Operation` type, and thus `eqs` is an array of
4747
analyzed by other programs. We can turn this into a `DiffEqSystem` via:
4848

4949
```julia
50-
de = DiffEqSystem(eqs,[t],[x,y,z],Variable[],[σ,ρ,β])
50+
de = DiffEqSystem(eqs,[t],[x,y,z],[σ,ρ,β])
5151
de = DiffEqSystem(eqs)
5252
```
5353

@@ -285,10 +285,10 @@ D = Differential(t) # Default of first derivative, Derivative(t,1)
285285
The system building functions can handle intermediate calculations. For example,
286286

287287
```julia
288-
@Unknown a x y z
288+
@Unknown x y z
289289
@Param σ ρ β
290-
eqs = [a ~ y-x,
291-
0 ~ σ*a,
290+
a = y - x
291+
eqs = [0 ~ σ*a,
292292
0 ~ x*-z)-y,
293293
0 ~ x*y - β*z]
294294
ns = NonlinearSystem(eqs,[x,y,z],[σ,ρ,β])

src/systems/diffeqs/diffeqsystem.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ mutable struct DiffEqSystem <: AbstractSystem
22
eqs::Vector{Equation}
33
ivs::Vector{Variable}
44
dvs::Vector{Variable}
5-
vs::Vector{Variable}
65
ps::Vector{Variable}
76
jac::Matrix{Expression}
87
end
98

10-
DiffEqSystem(eqs, ivs, dvs, vs, ps) = DiffEqSystem(eqs, ivs, dvs, vs, ps, Matrix{Expression}(undef,0,0))
9+
DiffEqSystem(eqs, ivs, dvs, ps) = DiffEqSystem(eqs, ivs, dvs, ps, Matrix{Expression}(undef,0,0))
1110

1211
function DiffEqSystem(eqs)
13-
predicates = [_is_derivative, _subtype(:IndependentVariable), _is_dependent, _subtype(:Unknown), _subtype(:Parameter)]
14-
_, ivs, dvs, vs, ps = extract_elements(eqs, predicates)
15-
DiffEqSystem(eqs, ivs, dvs, vs, ps, Matrix{Expression}(undef,0,0))
12+
predicates = [_is_derivative, _subtype(:IndependentVariable), _is_dependent, _subtype(:Parameter)]
13+
_, ivs, dvs, ps = extract_elements(eqs, predicates)
14+
DiffEqSystem(eqs, ivs, dvs, ps, Matrix{Expression}(undef,0,0))
1615
end
1716

1817
function DiffEqSystem(eqs, ivs)
19-
predicates = [_is_derivative, _is_dependent, _subtype(:Unknown), _subtype(:Parameter)]
20-
_, dvs, vs, ps = extract_elements(eqs, predicates)
21-
DiffEqSystem(eqs, ivs, dvs, vs, ps, Matrix{Expression}(undef,0,0))
18+
predicates = [_is_derivative, _is_dependent, _subtype(:Parameter)]
19+
_, dvs, ps = extract_elements(eqs, predicates)
20+
DiffEqSystem(eqs, ivs, dvs, ps, Matrix{Expression}(undef,0,0))
2221
end
2322

2423
function generate_ode_function(sys::DiffEqSystem;version = ArrayFunction)

test/system_construction.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Test
33

44
# Define some variables
55
@IVar t
6-
@Unknown x(t) y(t) z(t) a()
6+
@Unknown x(t) y(t) z(t)
77
@Deriv D'~t # Default of first derivative, Derivative(t,1)
88
@Param σ ρ β
99
@Const c=0
@@ -12,7 +12,7 @@ using Test
1212
eqs = [D(x) ~ σ*(y-x),
1313
D(y) ~ x*-z)-y,
1414
D(z) ~ x*y - β*z]
15-
de = DiffEqSystem(eqs,[t],[x,y,z],Variable[],[σ,ρ,β])
15+
de = DiffEqSystem(eqs,[t],[x,y,z],[σ,ρ,β])
1616
ModelingToolkit.generate_ode_function(de)
1717
ModelingToolkit.generate_ode_function(de;version=ModelingToolkit.SArrayFunction)
1818
jac_expr = ModelingToolkit.generate_ode_jacobian(de)
@@ -24,7 +24,7 @@ ModelingToolkit.generate_ode_iW(de)
2424
de2 = DiffEqSystem(eqs, [t])
2525

2626
function test_vars_extraction(de, de2)
27-
for el in (:ivs, :dvs, :vs, :ps)
27+
for el in (:ivs, :dvs, :ps)
2828
names2 = sort(collect(var.name for var in getfield(de2,el)))
2929
names = sort(collect(var.name for var in getfield(de,el)))
3030
@test names2 == names
@@ -61,11 +61,11 @@ end
6161
@test_broken test_eqs(de1.eqs, lowered_eqs)
6262

6363
# Internal calculations
64-
eqs = [a ~ y-x,
65-
D(x) ~ σ*a,
64+
a = y - x
65+
eqs = [D(x) ~ σ*a,
6666
D(y) ~ x*-z)-y,
6767
D(z) ~ x*y - β*z]
68-
de = DiffEqSystem(eqs,[t],[x,y,z],[a],[σ,ρ,β])
68+
de = DiffEqSystem(eqs,[t],[x,y,z],[σ,ρ,β])
6969
ModelingToolkit.generate_ode_function(de)
7070
jac = ModelingToolkit.calculate_jacobian(de)
7171
f = ODEFunction(de)
@@ -84,13 +84,12 @@ end
8484

8585
ModelingToolkit.generate_nlsys_function(ns)
8686

87-
@Unknown _x
8887
@Deriv D'~t
8988
@Param A B C
90-
eqs = [_x ~ y/C,
91-
D(x) ~ -A*x,
89+
_x = y / C
90+
eqs = [D(x) ~ -A*x,
9291
D(y) ~ A*x - B*_x]
93-
de = DiffEqSystem(eqs,[t],[x,y],Variable[_x],[A,B,C])
92+
de = DiffEqSystem(eqs,[t],[x,y],[A,B,C])
9493
test_vars_extraction(de, DiffEqSystem(eqs,[t]))
9594
test_vars_extraction(de, DiffEqSystem(eqs))
9695
@test eval(ModelingToolkit.generate_ode_function(de))([0.0,0.0],[1.0,2.0],[1,2,3],0.0) -1/3

0 commit comments

Comments
 (0)