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

Commit

Permalink
#300 tighter tols in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Dec 10, 2020
1 parent 5cd91bf commit ce1a3f1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/MOL_discretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
# u(t, 0) ~ γ ---> (1, 0, γ)
# Dx(u(t, 0)) ~ γ ---> (0, 1, γ)
# α * u(t, 0)) + β * Dx(u(t, 0)) ~ γ ---> (α, β, γ)
# In general, all of α, β, and γ could be Expr
# In general, all of α, β, and γ could be Expr (i.e. functions of t)
function get_bcs(bcs,tdomain,domain)
lhs_deriv_depvars_bcs = Dict()
num_bcs = size(bcs,1)
Expand Down Expand Up @@ -121,7 +121,7 @@ function get_bcs(bcs,tdomain,domain)
lhs_deriv_depvars_bcs[var][key] = γ
else
# Boundary conditions can be more general
lhs_deriv_depvars_bcs[var][key] = (α, β, γ)
lhs_deriv_depvars_bcs[var][key] = (toexpr(α), toexpr(β), γ)
end
end
# Check each variable got all boundary conditions
Expand Down
61 changes: 57 additions & 4 deletions test/MOL_1D_Linear_Diffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ end
# Test
n = size(sol,1)
t_f = size(sol,3)
@test sol[:,1,t_f] zeros(n) atol = 0.1;
@test sol[:,1,t_f] zeros(n) atol=0.01;
end

@testset "Test 03: Dt(u(t,x)) ~ Dxx(u(t,x)), Neumann BCs" begin
Expand Down Expand Up @@ -284,7 +284,7 @@ end
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
bcs = [u(0,x) ~ sin(x),
u(t,-1.0) + 3Dx(u(t,-1.0)) ~ exp(-t) * (sin(-1.0) + 3cos(-1.0)),
u(t,1.0) + Dx(u(t,1.0)) ~ exp(-t) * (sin(1.0) + cos(1.0))]
4u(t,1.0) + Dx(u(t,1.0)) ~ exp(-t) * (4sin(1.0) + cos(1.0))]

# Space and time domains
domains = [t IntervalDomain(0.0,1.0),
Expand All @@ -294,7 +294,7 @@ end
pdesys = PDESystem(eq,bcs,domains,[t,x],[u])

# Method of lines discretization
dx = 0.1
dx = 0.01
order = 2
discretization = MOLFiniteDifference(dx,order)

Expand All @@ -318,7 +318,60 @@ end
# Test against exact solution
for i in 1:size(t,1)
u_approx = Array(prob.extrapolation[1](t[i])*sol.u[i])
@test u_approx u_exact(x, t[i]) atol=0.1
@test u_approx u_exact(x, t[i]) atol=0.05
end
end

@testset "Test 06: Dt(u(t,x)) ~ Dxx(u(t,x)), time-dependent Robin BCs" begin
# Method of Manufactured Solutions
u_exact = (x,t) -> exp.(-t) * sin.(x)

# Parameters, variables, and derivatives
@parameters t x
@variables u(..)
@derivatives Dt'~t
@derivatives Dx'~x
@derivatives Dxx''~x

# 1D PDE and boundary conditions
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
bcs = [u(0,x) ~ sin(x),
t^2 * u(t,-1.0) + 3Dx(u(t,-1.0)) ~ exp(-t) * (t^2 * sin(-1.0) + 3cos(-1.0)),
4u(t,1.0) + t * Dx(u(t,1.0)) ~ exp(-t) * (4sin(1.0) + t * cos(1.0))]

# Space and time domains
domains = [t IntervalDomain(0.0,1.0),
x IntervalDomain(-1.0,1.0)]

# PDE system
pdesys = PDESystem(eq,bcs,domains,[t,x],[u])

# Method of lines discretization
dx = 0.01
order = 2
discretization = MOLFiniteDifference(dx,order)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys,discretization)

# Solve ODE problem
sol = solve(prob,Tsit5(),saveat=0.1)
x = prob.space[2]
t = sol.t

# Plot and save results
# using Plots
# plot()
# for i in 1:4
# plot!(x,Array(prob.extrapolation[1](t[i])*sol.u[i]))
# scatter!(x, u_exact(x, t[i]))
# end
# savefig("MOL_1D_Linear_Diffusion_Test06.png")

# Test against exact solution
for i in 1:size(t,1)
u_approx = Array(prob.extrapolation[1](t[i])*sol.u[i])
@test u_approx u_exact(x, t[i]) atol=0.05
end
end

Expand Down

0 comments on commit ce1a3f1

Please sign in to comment.