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

Commit ce1a3f1

Browse files
#300 tighter tols in tests
1 parent 5cd91bf commit ce1a3f1

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

src/MOL_discretization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
# u(t, 0) ~ γ ---> (1, 0, γ)
2020
# Dx(u(t, 0)) ~ γ ---> (0, 1, γ)
2121
# α * u(t, 0)) + β * Dx(u(t, 0)) ~ γ ---> (α, β, γ)
22-
# In general, all of α, β, and γ could be Expr
22+
# In general, all of α, β, and γ could be Expr (i.e. functions of t)
2323
function get_bcs(bcs,tdomain,domain)
2424
lhs_deriv_depvars_bcs = Dict()
2525
num_bcs = size(bcs,1)
@@ -121,7 +121,7 @@ function get_bcs(bcs,tdomain,domain)
121121
lhs_deriv_depvars_bcs[var][key] = γ
122122
else
123123
# Boundary conditions can be more general
124-
lhs_deriv_depvars_bcs[var][key] = (α, β, γ)
124+
lhs_deriv_depvars_bcs[var][key] = (toexpr(α), toexpr(β), γ)
125125
end
126126
end
127127
# Check each variable got all boundary conditions

test/MOL_1D_Linear_Diffusion.jl

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ end
160160
# Test
161161
n = size(sol,1)
162162
t_f = size(sol,3)
163-
@test sol[:,1,t_f] zeros(n) atol = 0.1;
163+
@test sol[:,1,t_f] zeros(n) atol=0.01;
164164
end
165165

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

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

296296
# Method of lines discretization
297-
dx = 0.1
297+
dx = 0.01
298298
order = 2
299299
discretization = MOLFiniteDifference(dx,order)
300300

@@ -318,7 +318,60 @@ end
318318
# Test against exact solution
319319
for i in 1:size(t,1)
320320
u_approx = Array(prob.extrapolation[1](t[i])*sol.u[i])
321-
@test u_approx u_exact(x, t[i]) atol=0.1
321+
@test u_approx u_exact(x, t[i]) atol=0.05
322+
end
323+
end
324+
325+
@testset "Test 06: Dt(u(t,x)) ~ Dxx(u(t,x)), time-dependent Robin BCs" begin
326+
# Method of Manufactured Solutions
327+
u_exact = (x,t) -> exp.(-t) * sin.(x)
328+
329+
# Parameters, variables, and derivatives
330+
@parameters t x
331+
@variables u(..)
332+
@derivatives Dt'~t
333+
@derivatives Dx'~x
334+
@derivatives Dxx''~x
335+
336+
# 1D PDE and boundary conditions
337+
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
338+
bcs = [u(0,x) ~ sin(x),
339+
t^2 * u(t,-1.0) + 3Dx(u(t,-1.0)) ~ exp(-t) * (t^2 * sin(-1.0) + 3cos(-1.0)),
340+
4u(t,1.0) + t * Dx(u(t,1.0)) ~ exp(-t) * (4sin(1.0) + t * cos(1.0))]
341+
342+
# Space and time domains
343+
domains = [t IntervalDomain(0.0,1.0),
344+
x IntervalDomain(-1.0,1.0)]
345+
346+
# PDE system
347+
pdesys = PDESystem(eq,bcs,domains,[t,x],[u])
348+
349+
# Method of lines discretization
350+
dx = 0.01
351+
order = 2
352+
discretization = MOLFiniteDifference(dx,order)
353+
354+
# Convert the PDE problem into an ODE problem
355+
prob = discretize(pdesys,discretization)
356+
357+
# Solve ODE problem
358+
sol = solve(prob,Tsit5(),saveat=0.1)
359+
x = prob.space[2]
360+
t = sol.t
361+
362+
# Plot and save results
363+
# using Plots
364+
# plot()
365+
# for i in 1:4
366+
# plot!(x,Array(prob.extrapolation[1](t[i])*sol.u[i]))
367+
# scatter!(x, u_exact(x, t[i]))
368+
# end
369+
# savefig("MOL_1D_Linear_Diffusion_Test06.png")
370+
371+
# Test against exact solution
372+
for i in 1:size(t,1)
373+
u_approx = Array(prob.extrapolation[1](t[i])*sol.u[i])
374+
@test u_approx u_exact(x, t[i]) atol=0.05
322375
end
323376
end
324377

0 commit comments

Comments
 (0)