Skip to content

Commit 5f72c30

Browse files
Rename DependentVariable to Unknown
1 parent 3685d82 commit 5f72c30

13 files changed

+38
-38
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ to manipulate.
2121
### Example: ODE
2222

2323
Let's build an ODE. First we define some variables. In a differential equation
24-
system, we need to differentiate between our dependent variables, independent
24+
system, we need to differentiate between our unknown variables, independent
2525
variables, and parameters. Therefore we label them as follows:
2626

2727
```julia
2828
using ModelingToolkit
2929

3030
# Define some variables
3131
@IVar t
32-
@DVar x(t) y(t) z(t)
32+
@Unknown x(t) y(t) z(t)
3333
@Deriv D'~t
3434
@Param σ ρ β
3535
```
@@ -87,12 +87,12 @@ f = ODEFunction(de)
8787

8888
We can also build nonlinear systems. Let's say we wanted to solve for the steady
8989
state of the previous ODE. This is the nonlinear system defined by where the
90-
derivatives are zero. We could use dependent variables for our nonlinear system
90+
derivatives are zero. We could use unknown variables for our nonlinear system
9191
(for direct compatibility with the above ODE code), or we can use non-tagged
9292
variables. Here we will show the latter. We write:
9393

9494
```julia
95-
@DVar x y z
95+
@Unknown x y z
9696
@Param σ ρ β
9797

9898
# Define a nonlinear system
@@ -191,7 +191,7 @@ structure is as follows:
191191
the system of equations.
192192
- Name to subtype mappings: these describe how variable `subtype`s are mapped
193193
to the contexts of the system. For example, for a differential equation,
194-
the dependent variable corresponds to given subtypes and then the `eqs` can
194+
the unknown variable corresponds to given subtypes and then the `eqs` can
195195
be analyzed knowing what the state variables are.
196196
- Variable names which do not fall into one of the system's core subtypes are
197197
treated as intermediates which can be used for holding subcalculations and
@@ -262,7 +262,7 @@ syntactic sugar in some form. For example, the variable construction:
262262

263263
```julia
264264
@IVar t
265-
@DVar x(t) y(t) z(t)
265+
@Unknown x(t) y(t) z(t)
266266
@Deriv D'~t
267267
@Param σ ρ β
268268
```
@@ -271,9 +271,9 @@ is syntactic sugar for:
271271

272272
```julia
273273
t = IndependentVariable(:t)
274-
x = DependentVariable(:x,dependents = [t])
275-
y = DependentVariable(:y,dependents = [t])
276-
z = DependentVariable(:z,dependents = [t])
274+
x = Unknown(:x, dependents = [t])
275+
y = Unknown(:y, dependents = [t])
276+
z = Unknown(:z, dependents = [t])
277277
D = Differential(t) # Default of first derivative, Derivative(t,1)
278278
σ = Parameter()
279279
ρ = Parameter()
@@ -285,7 +285,7 @@ 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-
@DVar a x y z
288+
@Unknown a x y z
289289
@Param σ ρ β
290290
eqs = [a ~ y-x,
291291
0 ~ σ*a,

src/equations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Base.:~(lhs::Number , rhs::Expression) = Equation(lhs, rhs)
1313

1414

1515
_is_derivative(x::Variable) = x.diff !== nothing
16-
_is_dependent(x::Variable) = x.subtype === :DependentVariable && !isempty(x.dependents)
16+
_is_dependent(x::Variable) = x.subtype === :Unknown && !isempty(x.dependents)
1717
_subtype(subtype::Symbol) = x -> x.subtype === subtype
1818

1919
function extract_elements(eqs, predicates)

src/systems/diffeqs/diffeqsystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ function DiffEqSystem(eqs, ivs, dvs, vs, ps)
1818
end
1919

2020
function DiffEqSystem(eqs; iv_name = :IndependentVariable,
21-
dv_name = :DependentVariable,
21+
dv_name = :Unknown,
2222
p_name = :Parameter)
2323
predicates = [_is_derivative, _subtype(iv_name), _is_dependent, _subtype(dv_name), _subtype(p_name)]
2424
_, ivs, dvs, vs, ps = extract_elements(eqs, predicates)
2525
DiffEqSystem(eqs, ivs, dvs, vs, ps, iv_name, dv_name, p_name, Matrix{Expression}(undef,0,0))
2626
end
2727

2828
function DiffEqSystem(eqs, ivs;
29-
dv_name = :DependentVariable,
29+
dv_name = :Unknown,
3030
p_name = :Parameter)
3131
predicates = [_is_derivative, _is_dependent, _subtype(dv_name), _subtype(p_name)]
3232
_, dvs, vs, ps = extract_elements(eqs, predicates)
@@ -98,7 +98,7 @@ function generate_ode_iW(sys::DiffEqSystem, simplify=true)
9898
diff_exprs = filter(!isintermediate, sys.eqs)
9999
jac = sys.jac
100100

101-
gam = DependentVariable(:gam)
101+
gam = Unknown(:gam)
102102

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

src/systems/nonlinear/nonlinear_system.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ struct NonlinearSystem <: AbstractSystem
77
end
88

99
function NonlinearSystem(eqs, vs, ps;
10-
v_name = :DependentVariable,
10+
v_name = :Unknown,
1111
p_name = :Parameter)
1212
NonlinearSystem(eqs, vs, ps, [v_name], p_name)
1313
end
1414

1515
function NonlinearSystem(eqs;
16-
v_name = :DependentVariable,
16+
v_name = :Unknown,
1717
p_name = :Parameter)
1818
vs, ps = extract_elements(eqs, [_subtype(v_name), _subtype(p_name)])
1919
NonlinearSystem(eqs, vs, ps, [v_name], p_name)

src/variables.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Variable(name; subtype::Symbol, dependents::Vector{Variable} = Variable[]) =
1010

1111
Parameter(name,args...;kwargs...) = Variable(name,args...;subtype=:Parameter,kwargs...)
1212
IndependentVariable(name,args...;kwargs...) = Variable(name,args...;subtype=:IndependentVariable,kwargs...)
13-
DependentVariable(name,args...;kwargs...) = Variable(name,args...;subtype=:DependentVariable,kwargs...)
13+
Unknown(name,args...;kwargs...) = Variable(name,args...;subtype=:Unknown,kwargs...)
1414

15-
export Variable,Parameter,Constant,DependentVariable,IndependentVariable,
16-
@Param, @Const, @DVar, @IVar
15+
export Variable,Parameter,Constant,Unknown,IndependentVariable,
16+
@Param, @Const, @Unknown, @IVar
1717

1818

1919
Base.copy(x::Variable) = Variable(x.name, x.subtype, x.diff, x.dependents)
@@ -83,7 +83,7 @@ function _parse_vars(macroname, fun, x)
8383
return ex
8484
end
8585

86-
for funs in [(:DVar, :DependentVariable), (:IVar, :IndependentVariable), (:Param, :Parameter)]
86+
for funs in [(:Unknown, :Unknown), (:IVar, :IndependentVariable), (:Param, :Parameter)]
8787
@eval begin
8888
macro ($(funs[1]))(x...)
8989
esc(_parse_vars(String($funs[1]), $funs[2], x))

test/ambiguity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using ModelingToolkit
22
using Test
33

44
@IVar t
5-
@DVar x(t) y(t) z(t)
5+
@Unknown x(t) y(t) z(t)
66

77
struct __MyType__ end
88
Base.:~(::__MyType__,::Number) = 2

test/basic_variables_and_operations.jl

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

44
@IVar t
5-
@DVar x(t) y(t) z(t)
5+
@Unknown x(t) y(t) z(t)
66

77
@Deriv D'~t # Default of first derivative, Derivative(t,1)
88
@Param σ ρ β
99
@Const c=0
1010

1111
# Default values
1212
p = Parameter(:p)
13-
u = DependentVariable(:u, dependents = [t])
13+
u = Unknown(:u, dependents = [t])
1414

1515
σ*(y-x)
1616
D(x)

test/components.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function generate_lorenz_eqs(t,x,y,z,σ,ρ,β)
1717
D(z) ~ x*y - β*z]
1818
end
1919
function Lorenz(t)
20-
@DVar x(t) y(t) z(t)
20+
@Unknown x(t) y(t) z(t)
2121
@Param σ ρ β
2222
Lorenz(x, y, z, σ, ρ, β, generate_lorenz_eqs(t, x, y, z, σ, ρ, β))
2323
end

test/derivatives.jl

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

44
# Derivatives
55
@IVar t
6-
@DVar x(t) y(t) z(t)
6+
@Unknown x(t) y(t) z(t)
77
@Param σ ρ β
88
@Deriv D'~t
99
dsin = D(sin(t))
@@ -43,5 +43,5 @@ jac = ModelingToolkit.calculate_jacobian(sys)
4343
@test jac[3,3] == -1*β
4444

4545
# Variable dependence checking in differentiation
46-
@DVar a(t) b(a)
46+
@Unknown a(t) b(a)
4747
@test D(b) Constant(0)

test/internal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Test
44
# `Expr`, `Number` -> `Operation`
55
@IVar a
66
@Param b
7-
@DVar x(t) y()
7+
@Unknown x(t) y()
88
@test convert(Expression, 2) == 2
99
expr = :(-inv(2sqrt(+($a, $b))))
1010
op = Operation(-, [Operation(inv,

0 commit comments

Comments
 (0)