Skip to content

Commit 57d65c4

Browse files
add some basic domains
1 parent b36ef70 commit 57d65c4

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/ModelingToolkit.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ abstract type Expression <: Number end
88
abstract type AbstractOperation <: Expression end
99
abstract type AbstractOperator <: Expression end
1010
abstract type AbstractSystem end
11+
abstract type AbstractDomain end
1112

1213
include("variables.jl")
1314

@@ -23,6 +24,7 @@ include("systems/diffeqs/diffeqsystem.jl")
2324
include("systems/diffeqs/first_order_transform.jl")
2425
include("systems/nonlinear/nonlinear_system.jl")
2526
include("function_registration.jl")
27+
include("domains.jl")
2628
include("simplify.jl")
2729
include("utils.jl")
2830

src/domains.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Base.ndims(::AbstractDomain) = error("Domain dimension is undefined")
2+
3+
struct DiscreteDomain <: AbstractDomain
4+
length::Int
5+
end
6+
7+
struct Interval{T} <: AbstractDomain
8+
start::T
9+
stop::T
10+
end
11+
12+
struct ProductDomain{T} <: AbstractDomain
13+
domains::T
14+
end
15+
16+
Base.:*(x::AbstractDomain...) = ProductDomain((x...))
17+
18+
export DiscreteDomain, Interval, ProductDomain

test/domains.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using ModelingToolkit
2+
using Base.Test
3+
4+
d = DiscreteDomain(5) * Interval(0.0,5.0)
5+
typeof(d) <: ProductDomain
6+
typeof(d.domains[1]) <: DiscreteDomain
7+
typeof(d.domains[2]) <: Interval

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ using ModelingToolkit, Base.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
78
@testset "Ambiguity Test" begin include("ambiguity.jl") end
89
@testset "System Construction Test" begin include("system_construction.jl") end

0 commit comments

Comments
 (0)