Skip to content

Commit d72c7de

Browse files
committed
added utils test
1 parent 065ea8b commit d72c7de

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if GROUP == "All" || GROUP == "MOLFiniteDifference"
1717
@time @safetestset "MOLFiniteDifference Interface: 1D HigherOrder" begin include("pde_systems/MOL_1D_HigherOrder.jl") end
1818
@time @safetestset "MOLFiniteDifference Interface: 1D Partial DAE" begin include("pde_systems/MOL_1D_PDAE.jl") end
1919
@time @safetestset "MOLFiniteDifference Interface: Stationary Nonlinear Problems" begin include("pde_systems/MOL_NonlinearProblem.jl") end
20+
@time @safetestset "MOLFiniteDifference Utils" begin include("utils_test.jl") end
2021
end
2122

2223
end

test/utils_test.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using MethodOfLines, Test, ModelingToolkit
2+
3+
@testset "count differentials 1D" begin
4+
@parameters t x
5+
@variables u(..)
6+
Dt = Differential(t)
7+
8+
Dx = Differential(x)
9+
eq = Dt(u(t,x)) ~ -Dx(u(t,x))
10+
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 1
11+
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
12+
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
13+
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
14+
15+
Dxx = Differential(x)^2
16+
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
17+
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 2
18+
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
19+
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
20+
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
21+
22+
Dxxxx = Differential(x)^4
23+
eq = Dt(u(t,x)) ~ -Dxxxx(u(t,x))
24+
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 4
25+
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
26+
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
27+
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
28+
end
29+
30+
@testset "count differentials 2D" begin
31+
@parameters t x y
32+
@variables u(..)
33+
Dxx = Differential(x)^2
34+
Dyy = Differential(y)^2
35+
Dt = Differential(t)
36+
37+
eq = Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y))
38+
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 2
39+
@test first(DiffEqOperators.differential_order(eq.rhs, y.val)) == 2
40+
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
41+
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
42+
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
43+
@test isempty(DiffEqOperators.differential_order(eq.lhs, y.val))
44+
end
45+
46+
@testset "count with mixed terms" begin
47+
@parameters t x y
48+
@variables u(..)
49+
Dxx = Differential(x)^2
50+
Dyy = Differential(y)^2
51+
Dx = Differential(x)
52+
Dy = Differential(y)
53+
Dt = Differential(t)
54+
55+
eq = Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y)) + Dx(Dy(u(t,x,y)))
56+
@test DiffEqOperators.differential_order(eq.rhs, x.val) == Set([2, 1])
57+
@test DiffEqOperators.differential_order(eq.rhs, y.val) == Set([2, 1])
58+
end
59+
60+
@testset "Kuramoto–Sivashinsky equation" begin
61+
@parameters x, t
62+
@variables u(..)
63+
Dt = Differential(t)
64+
Dx = Differential(x)
65+
Dx2 = Differential(x)^2
66+
Dx3 = Differential(x)^3
67+
Dx4 = Differential(x)^4
68+
69+
α = 1
70+
β = 4
71+
γ = 1
72+
eq = Dt(u(x,t)) + u(x,t)*Dx(u(x,t)) + α*Dx2(u(x,t)) + β*Dx3(u(x,t)) + γ*Dx4(u(x,t)) ~ 0
73+
@test DiffEqOperators.differential_order(eq.lhs, x.val) == Set([4, 3, 2, 1])
74+
end

0 commit comments

Comments
 (0)