Skip to content

Commit e0fad95

Browse files
Merge pull request #81 from JuliaDiffEq/hg/rm/unused
Remove unused Variable information
2 parents 0097578 + 7f64234 commit e0fad95

File tree

8 files changed

+11
-99
lines changed

8 files changed

+11
-99
lines changed

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,12 @@ context-aware single variable of the IR. Its fields are described as follows:
153153
- `name`: the name of the `Variable`. Note that this is not necessarily
154154
the same as the name of the Julia variable. But this symbol itself is considered
155155
the core identifier of the `Variable` in the sense of equality.
156-
- `value_type`: the type that the values have to be. It's disconnected
157-
from the `value` because in many cases the `value` may not be able to be
158-
specified in advance even when we may already know the type. This can be used
159-
to set units or denote a variable as being of higher precision.
160156
- `subtype`: the main denotation of context. Variables within systems
161157
are grouped according to their `subtype`.
162158
- `diff`: the `Differential` object representing the quantity the variable is differentiated with respect to, or `nothing`
163159
- `dependents`: the vector of variables on which the current variable
164160
is dependent. For example, `u(t,x)` has dependents `[t,x]`. Derivatives thus
165161
require this information in order to simplify down.
166-
- `flow`: a boolean that describes the connection behavior between systems,
167-
whether it should connect to have summation to zero or equality.
168-
- `description`: a string description of the variable used for building
169-
printouts and other descriptive outputs.
170-
- `domain`: a type which describes the domain in which the values of the variable
171-
lives.
172-
- `size`: the size of the variable. By default it's `nothing`, denoting that the
173-
variable is a scalar. Otherwise it's a tuple of numbers which describes the
174-
size of the array for the variable.
175-
- `context`: this is an open field for DSLs to carry along more context
176-
in the variables, but is not used in the systems themselves.
177162

178163
### Constants
179164

src/ModelingToolkit.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ abstract type Expression <: Number end
1010
abstract type AbstractOperation <: Expression end
1111
abstract type AbstractComponent <: Expression end
1212
abstract type AbstractSystem end
13-
abstract type AbstractDomain end
1413

15-
include("domains.jl")
1614
include("variables.jl")
1715

1816
Base.promote_rule(::Type{T},::Type{T2}) where {T<:Number,T2<:Expression} = Expression

src/differentials.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ function Derivative end
1212
function (D::Differential)(x::Variable)
1313
D.x === x && return Constant(1)
1414
has_dependent(x, D.x) || return Constant(0)
15-
return Variable(x,D)
15+
16+
x′ = copy(x)
17+
x′.diff = D
18+
return x′
1619
end
1720
Base.:(==)(D1::Differential, D2::Differential) = D1.order == D2.order && D1.x == D2.x
1821

19-
Variable(x::Variable, D::Differential) = Variable(x.name,x.value_type,
20-
x.subtype,D,x.dependents,x.description,x.flow,x.domain,
21-
x.size,x.context)
22-
2322
function expand_derivatives(O::Operation)
2423
@. O.args = expand_derivatives(O.args)
2524

src/domains.jl

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/variables.jl

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
mutable struct Variable <: Expression
22
name::Symbol
3-
value_type::DataType
43
subtype::Symbol
54
diff::Union{Function,Nothing} # FIXME
65
dependents::Vector{Variable}
7-
description::String
8-
flow::Bool
9-
domain::AbstractDomain
10-
size
11-
context
126
end
137

14-
Variable(name,
15-
value_type = Any;
16-
subtype::Symbol=:Variable,
17-
dependents::Vector{Variable} = Variable[],
18-
flow::Bool = false,
19-
description::String = "",
20-
domain = Reals(),
21-
size = nothing,
22-
context = nothing) =
23-
Variable(name,value_type,subtype,nothing,
24-
dependents,description,flow,domain,size,context)
25-
Variable(name,args...;kwargs...) = Variable(name,args...;subtype=:Variable,kwargs...)
26-
27-
Variable(name,x::Variable) = Variable(name,x.value_type,
28-
x.subtype,D,x.dependents,x.description,x.flow,x.domain,
29-
x.size,x.context)
8+
Variable(name; subtype::Symbol=:Variable, dependents::Vector{Variable} = Variable[]) =
9+
Variable(name, subtype, nothing, dependents)
10+
Variable(name, args...; kwargs...) = Variable(name, args...; subtype=:Variable, kwargs...)
3011

3112
Parameter(name,args...;kwargs...) = Variable(name,args...;subtype=:Parameter,kwargs...)
3213
IndependentVariable(name,args...;kwargs...) = Variable(name,args...;subtype=:IndependentVariable,kwargs...)
@@ -36,28 +17,11 @@ function DependentVariable(name,args...;dependents = [],kwargs...)
3617
Variable(name,args...;subtype=:DependentVariable,dependents=dependents,kwargs...)
3718
end
3819

39-
function StateVariable(name,args...;dependents = [],kwargs...)
40-
@assert !isempty(dependents)
41-
Variable(name,args...;subtype=:StateVariable,dependents=dependents,kwargs...)
42-
end
20+
export Variable,Parameter,Constant,DependentVariable,IndependentVariable,
21+
@Var, @Param, @Const, @DVar, @IVar
4322

44-
function ControlVariable(name,args...;dependents = [],kwargs...)
45-
@assert !isempty(dependents)
46-
Variable(name,args...;subtype=:ControlVariable,dependents=dependents,kwargs...)
47-
end
4823

49-
function JumpVariable(name,args...;dependents = [],kwargs...)
50-
@assert !isempty(dependents)
51-
Variable(name,args...;subtype=:JumpVariable,dependents=dependents,kwargs...)
52-
end
53-
54-
function NoiseVariable(name,args...;dependents = [],kwargs...)
55-
@assert !isempty(dependents)
56-
Variable(name,args...;subtype=:NoiseVariable,dependents=dependents,kwargs...)
57-
end
58-
59-
export Variable,Parameter,Constant,DependentVariable,IndependentVariable,JumpVariable,NoiseVariable,
60-
@Var, @DVar, @IVar, @Param, @Const
24+
Base.copy(x::Variable) = Variable(x.name, x.subtype, x.diff, x.dependents)
6125

6226

6327
struct Constant <: Expression
@@ -71,10 +35,7 @@ Base.isone(ex::Expression) = isa(ex, Constant) && isone(ex.value)
7135

7236

7337
# Variables use isequal for equality since == is an Operation
74-
function Base.:(==)(x::Variable, y::Variable)
75-
x.name == y.name && x.subtype == y.subtype &&
76-
x.value_type == y.value_type && x.diff == y.diff
77-
end
38+
Base.:(==)(x::Variable, y::Variable) = (x.name, x.subtype, x.diff) == (y.name, y.subtype, y.diff)
7839
Base.:(==)(::Variable, ::Number) = false
7940
Base.:(==)(::Number, ::Variable) = false
8041
Base.:(==)(::Variable, ::Constant) = false

test/basic_variables_and_operations.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ using Test
1313
p = Parameter(:p)
1414
u = DependentVariable(:u, dependents = [t])
1515

16-
s = JumpVariable(:s, dependents=[t])
17-
n = NoiseVariable(:n, dependents=[t])
18-
1916
σ*(y-x)
2017
D(x)
2118
D(x) ~ -σ*(y-x)

test/domains.jl

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ using ModelingToolkit, Test
44
@testset "Basic Variables and Operations" begin include("basic_variables_and_operations.jl") end
55
@testset "Differentiation Test" begin include("derivatives.jl") end
66
@testset "Internal Test" begin include("internal.jl") end
7-
@testset "Domain Test" begin include("domains.jl") end
87
@testset "Simplify Test" begin include("simplify.jl") end
98
@testset "Ambiguity Test" begin include("ambiguity.jl") end
109
@testset "Components Test" begin include("components.jl") end

0 commit comments

Comments
 (0)