Skip to content

Commit b00e96b

Browse files
Merge pull request #180 from JuliaDiffEq/pde
Add PDE Systems and their associated pieces
2 parents 8af8d98 + 15c9c81 commit b00e96b

File tree

10 files changed

+113
-28
lines changed

10 files changed

+113
-28
lines changed

Project.toml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
name = "ModelingToolkit"
2-
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
3-
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "0.7.2"
5-
6-
[deps]
7-
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8-
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
9-
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
10-
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
11-
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
12-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
13-
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
14-
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
15-
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
16-
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
17-
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
18-
19-
[compat]
20-
julia = "1"
21-
22-
[extras]
23-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
24-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
25-
26-
[targets]
27-
test = ["OrdinaryDiffEq", "Test"]
1+
name = "ModelingToolkit"
2+
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
3+
authors = ["Chris Rackauckas <[email protected]>"]
4+
version = "0.7.2"
5+
6+
[deps]
7+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8+
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
9+
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
10+
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
11+
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
12+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
13+
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
14+
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
15+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
16+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
17+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
18+
19+
[compat]
20+
julia = "1"
21+
22+
[extras]
23+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
24+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
25+
26+
[targets]
27+
test = ["OrdinaryDiffEq", "Test"]

src/ModelingToolkit.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ include("function_registration.jl")
8989
include("simplify.jl")
9090
include("utils.jl")
9191
include("direct.jl")
92+
include("domains.jl")
9293
include("systems/diffeqs/diffeqsystem.jl")
9394
include("systems/diffeqs/first_order_transform.jl")
9495
include("systems/nonlinear/nonlinear_system.jl")
96+
include("systems/pde/pdesystem.jl")
9597

9698
end # module

src/domains.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export IntervalDomain, ProductDomain, , CircleDomain
2+
3+
abstract type AbstractDomain{T,N} end
4+
5+
struct VarDomainPairing
6+
variables
7+
domain::AbstractDomain
8+
end
9+
Base.:(variable::ModelingToolkit.Operation,domain::AbstractDomain) = VarDomainPairing(variable,domain)
10+
Base.:(variables::NTuple{N,ModelingToolkit.Operation},domain::AbstractDomain) where N = VarDomainPairing(variables,domain)
11+
12+
## Specific Domains
13+
14+
struct IntervalDomain{T} <: AbstractDomain{T,1}
15+
lower::T
16+
upper::T
17+
end
18+
19+
20+
struct ProductDomain{D,T,N} <: AbstractDomain{T,N}
21+
domains::D
22+
end
23+
(args::AbstractDomain{T}...) where T = ProductDomain{typeof(args),T,length(args)}(args)
24+
25+
struct CircleDomain <: AbstractDomain{Float64,2}
26+
polar::Bool
27+
CircleDomain(polar=false) = new(polar)
28+
end

src/equations.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export Equation
1+
export Equation, ConstrainedEquation
22

33

44
"""
@@ -40,3 +40,8 @@ Equation(x() - y(), ModelingToolkit.Constant(0))
4040
Base.:~(lhs::Expression, rhs::Expression) = Equation(lhs, rhs)
4141
Base.:~(lhs::Expression, rhs::Number ) = Equation(lhs, rhs)
4242
Base.:~(lhs::Number , rhs::Expression) = Equation(lhs, rhs)
43+
44+
struct ConstrainedEquation
45+
constraints
46+
eq
47+
end

src/function_registration.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ end
5454

5555
# special cases
5656
Base.:^(x::Expression,y::T) where T <: Integer = Operation(Base.:^, Expression[x, y])
57+
58+
@register Base.getindex(x,i)
59+
Base.getindex(x::Operation,i::Int64) = Operation(getindex,[x,i])

src/systems/pde/pdesystem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export PDESystem
2+
3+
struct PDESystem <: ModelingToolkit.AbstractSystem
4+
eq
5+
bcs
6+
domain
7+
indvars
8+
depvars
9+
end

test/constraints.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using ModelingToolkit, DiffEqBase, LinearAlgebra
2+
3+
# Define some variables
4+
@parameters t x y
5+
@variables u(..)
6+
7+
ConstrainedEquation([x ~ 0,y < 1/2], u(t,x,y) ~ x + y^2)

test/domains.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ModelingToolkit
2+
3+
@parameters t x
4+
domains = [t IntervalDomain(0.0,1.0),
5+
x IntervalDomain(0.0,1.0)]
6+
7+
@parameters z
8+
z (IntervalDomain(0.0,1.0) IntervalDomain(0.0,1.0))
9+
10+
@parameters y
11+
(x,y) CircleDomain()
12+
@parameters r θ
13+
(r,θ) CircleDomain(true)

test/pde.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ModelingToolkit, DiffEqBase, LinearAlgebra
2+
3+
# Define some variables
4+
@parameters t x
5+
@variables u(..)
6+
@derivatives Dt'~t
7+
@derivatives Dxx''~x
8+
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
9+
bcs = [u(0,x) ~ - x * (x-1) * sin(x),
10+
u(t,0) ~ 0, u(t,1) ~ 0]
11+
12+
domains = [t IntervalDomain(0.0,1.0),
13+
x IntervalDomain(0.0,1.0)]
14+
15+
pdesys = PDESystem(eq,bcs,domains,[t,x],[u])

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ using ModelingToolkit, Test
55
@testset "Simplify Test" begin include("simplify.jl") end
66
@testset "Direct Usage Test" begin include("direct.jl") end
77
@testset "System Construction Test" begin include("system_construction.jl") end
8+
@testset "Domain Test" begin include("domains.jl") end
9+
@testset "Constraints Test" begin include("constraints.jl") end
10+
@testset "PDE Construction Test" begin include("pde.jl") end
811
@testset "Distributed Test" begin include("distributed.jl") end

0 commit comments

Comments
 (0)