Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsheikh committed Aug 15, 2021
1 parent 888a36a commit e00fee9
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions test/MOL/MOL_1D_HigherOrder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,6 @@ end
prob = discretize(pdesys,discretization)
end

@testset "Kuramoto–Sivashinsky equation" begin
@parameters x, t
@variables u(..)
Dt = Differential(t)
Dx = Differential(x)
Dx2 = Differential(x)^2
Dx3 = Differential(x)^3
Dx4 = Differential(x)^4

α = 1
β = 4
γ = 1
eq = Dt(u(x,t)) ~ -u(x,t)*Dx(u(x,t)) - α*Dx2(u(x,t)) - β*Dx3(u(x,t)) - γ*Dx4(u(x,t))

u_analytic(x,t;z = -x/2+t) = 11 + 15*tanh(z) -15*tanh(z)^2 - 15*tanh(z)^3
du(x,t;z = -x/2+t) = 15/2*(tanh(z) + 1)*(3*tanh(z) - 1)*sech(z)^2

bcs = [u(x,0) ~ u_analytic(x,0),
u(-10,t) ~ u_analytic(-10,t),
u(10,t) ~ u_analytic(10,t),
Dx(u(-10,t)) ~ du(-10,t),
Dx(u(10,t)) ~ du(10,t)]

# Space and time domains
domains = [x Interval(-10.0,10.0),
t Interval(0.0,1.0)]
# Discretization
dx = 0.4; dt = 0.2

discretization = MOLFiniteDifference([x=>dx],t;centered_order=4,grid_align=center_align)
pdesys = PDESystem(eq,bcs,domains,[x,t],[u(x,t)])
prob = discretize(pdesys,discretization)

sol = solve(prob,Tsit5(),saveat=0.1,dt=dt)

@test sol.retcode == :Success

xs = domains[1].domain.lower+dx+dx:dx:domains[1].domain.upper-dx-dx
ts = sol.t

u_predict = sol.u
u_real = [[u_analytic(x, t) for x in xs] for t in ts]
u_diff = u_real - u_predict
@test_broken u_diff[:] zeros(length(u_diff)) atol=0.01;
#plot(xs, u_diff)
end

@testset "KdV Single Soliton equation" begin
@parameters x, t
@variables u(..)
Expand Down Expand Up @@ -163,8 +116,5 @@ end

u_predict = sol.u
u_real = [[u_analytic(x, t) for x in xs] for t in ts]
u_diff = u_real - u_predict
for i in 1:length(u_diff)
@test u_diff[i] zeros(length(u_diff[i])) atol=0.05;
end
@test all(isapprox.(u_predict, u_real, rtol = 0.03))
end

0 comments on commit e00fee9

Please sign in to comment.