Skip to content

Commit 6379485

Browse files
Make macro naming consistent
1 parent 47b5b00 commit 6379485

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ and parameters. Therefore we label them as follows:
2828
using ModelingToolkit
2929

3030
# Define some variables
31-
@param t σ ρ β
32-
@variable x(t) y(t) z(t)
33-
@deriv D'~t
31+
@parameters t σ ρ β
32+
@variables x(t) y(t) z(t)
33+
@derivatives D'~t
3434
```
3535

3636
Then we build the system:
@@ -81,8 +81,8 @@ state of the previous ODE. This is the nonlinear system defined by where the
8181
derivatives are zero. We use (unknown) variables for our nonlinear system.
8282
8383
```julia
84-
@variable x y z
85-
@param σ ρ β
84+
@variables x y z
85+
@parameters σ ρ β
8686

8787
# Define a nonlinear system
8888
eqs = [0 ~ σ*(y-x),
@@ -243,9 +243,9 @@ is accessible via a function-based interface. This means that all macros are
243243
syntactic sugar in some form. For example, the variable construction:
244244
245245
```julia
246-
@param t σ ρ β
247-
@variable x(t) y(t) z(t)
248-
@deriv D'~t
246+
@parameters t σ ρ β
247+
@variables x(t) y(t) z(t)
248+
@derivatives D'~t
249249
```
250250
251251
is syntactic sugar for:
@@ -266,8 +266,8 @@ D = Differential(t)
266266
The system building functions can handle intermediate calculations. For example,
267267
268268
```julia
269-
@variable x y z
270-
@param σ ρ β
269+
@variables x y z
270+
@parameters σ ρ β
271271
a = y - x
272272
eqs = [0 ~ σ*a,
273273
0 ~ x*-z)-y,

src/differentials.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export Differential, expand_derivatives, @deriv
1+
export Differential, expand_derivatives, @derivatives
22

33

44
struct Differential <: Function
@@ -63,7 +63,7 @@ function _differential_macro(x)
6363
lhss = Symbol[]
6464
x = flatten_expr!(x)
6565
for di in x
66-
@assert di isa Expr && di.args[1] == :~ "@deriv expects a form that looks like `@deriv D''~t E'~t`"
66+
@assert di isa Expr && di.args[1] == :~ "@derivatives expects a form that looks like `@derivatives D''~t E'~t`"
6767
lhs = di.args[2]
6868
rhs = di.args[3]
6969
order, lhs = count_order(lhs)
@@ -75,7 +75,7 @@ function _differential_macro(x)
7575
ex
7676
end
7777

78-
macro deriv(x...)
78+
macro derivatives(x...)
7979
esc(_differential_macro(x))
8080
end
8181

src/variables.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export Variable, @variable, @param
1+
export Variable, @variables, @parameters
22

33

44
struct Variable <: Expression
@@ -70,9 +70,9 @@ function _parse_vars(macroname, known, x)
7070
push!(ex.args, build_expr(:tuple, var_names))
7171
return ex
7272
end
73-
macro variable(xs...)
73+
macro variables(xs...)
7474
esc(_parse_vars(:Variable, false, xs))
7575
end
76-
macro param(xs...)
76+
macro parameters(xs...)
7777
esc(_parse_vars(:Param, true, xs))
7878
end

test/derivatives.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using ModelingToolkit
22
using Test
33

44
# Derivatives
5-
@param t σ ρ β
6-
@variable x(t) y(t) z(t)
7-
@deriv D'~t D2''~t
5+
@parameters t σ ρ β
6+
@variables x(t) y(t) z(t)
7+
@derivatives D'~t D2''~t
88

99
@test isequal(expand_derivatives(D(t)), 1)
1010
@test isequal(expand_derivatives(D(D(t))), 0)
@@ -47,7 +47,7 @@ jac = calculate_jacobian(sys)
4747
@test isequal(jac[3,3], -1*β)
4848

4949
# Variable dependence checking in differentiation
50-
@variable a(t) b(a)
50+
@variables a(t) b(a)
5151
@test !isequal(D(b), 0)
5252

5353
@test isequal(expand_derivatives(D(x * y)), simplify_constants(y*D(x) + x*D(y)))

test/simplify.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using ModelingToolkit
22
using Test
33

4-
@param t
5-
@variable x(t) y(t) z(t)
4+
@parameters t
5+
@variables x(t) y(t) z(t)
66

77
null_op = 0*t
88
@test isequal(simplify_constants(null_op), 0)

test/system_construction.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using ModelingToolkit
22
using Test
33

44
# Define some variables
5-
@param t σ ρ β
6-
@variable x(t) y(t) z(t)
7-
@deriv D'~t
5+
@parameters t σ ρ β
6+
@variables x(t) y(t) z(t)
7+
@derivatives D'~t
88

99
# Define a differential equation
1010
eqs = [D(x) ~ σ*(y-x),
@@ -32,7 +32,7 @@ end
3232
test_vars_extraction(de, de2)
3333

3434
@testset "time-varying parameters" begin
35-
@param σ′(t)
35+
@parameters σ′(t)
3636
eqs = [D(x) ~ σ′*(y-x),
3737
D(y) ~ x*-z)-y,
3838
D(z) ~ x*y - β*z]
@@ -46,9 +46,9 @@ test_vars_extraction(de, de2)
4646
end
4747

4848
# Conversion to first-order ODEs #17
49-
@deriv D3'''~t
50-
@deriv D2''~t
51-
@variable u(t) u_tt(t) u_t(t) x_t(t)
49+
@derivatives D3'''~t
50+
@derivatives D2''~t
51+
@variables u(t) u_tt(t) u_t(t) x_t(t)
5252
eqs = [D3(u) ~ 2(D2(u)) + D(u) + D(x) + 1
5353
D2(x) ~ D(x) + 2]
5454
de = DiffEqSystem(eqs, t)
@@ -84,8 +84,8 @@ end
8484

8585
generate_function(ns)
8686

87-
@deriv D'~t
88-
@param A B C
87+
@derivatives D'~t
88+
@parameters A B C
8989
_x = y / C
9090
eqs = [D(x) ~ -A*x,
9191
D(y) ~ A*x - B*_x]
@@ -100,8 +100,8 @@ test_vars_extraction(de, DiffEqSystem(eqs))
100100
end
101101

102102
# Now nonlinear system with only variables
103-
@variable x y z
104-
@param σ ρ β
103+
@variables x y z
104+
@parameters σ ρ β
105105

106106
# Define a nonlinear system
107107
eqs = [0 ~ σ*(y-x),

test/variable_parsing.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using ModelingToolkit
22
using Test
33

4-
@param t
5-
@variable x(t)
6-
@variable y(t)
7-
@variable z(t)
4+
@parameters t
5+
@variables x(t)
6+
@variables y(t)
7+
@variables z(t)
88
x1 = Variable(:x, [t])
99
y1 = Variable(:y, [t])
1010
z1 = Variable(:z, [t])
@@ -15,7 +15,7 @@ z1 = Variable(:z, [t])
1515
@test convert(Expr, y) == :y
1616
@test convert(Expr, z) == :z
1717

18-
@param begin
18+
@parameters begin
1919
t
2020
s
2121
end
@@ -27,7 +27,7 @@ s1 = Variable(:s; known = true)
2727
@test convert(Expr, s) == :s
2828
@test convert(Expr, cos(t + sin(s))) == :(cos(t + sin(s)))
2929

30-
@deriv D'~t
30+
@derivatives D'~t
3131
D1 = Differential(t)
3232
@test D1 == D
3333
@test convert(Expr, D) == D

0 commit comments

Comments
 (0)