|
160 | 160 | # Test |
161 | 161 | n = size(sol,1) |
162 | 162 | 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; |
164 | 164 | end |
165 | 165 |
|
166 | 166 | @testset "Test 03: Dt(u(t,x)) ~ Dxx(u(t,x)), Neumann BCs" begin |
|
284 | 284 | eq = Dt(u(t,x)) ~ Dxx(u(t,x)) |
285 | 285 | bcs = [u(0,x) ~ sin(x), |
286 | 286 | 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))] |
288 | 288 |
|
289 | 289 | # Space and time domains |
290 | 290 | domains = [t ∈ IntervalDomain(0.0,1.0), |
|
294 | 294 | pdesys = PDESystem(eq,bcs,domains,[t,x],[u]) |
295 | 295 |
|
296 | 296 | # Method of lines discretization |
297 | | - dx = 0.1 |
| 297 | + dx = 0.01 |
298 | 298 | order = 2 |
299 | 299 | discretization = MOLFiniteDifference(dx,order) |
300 | 300 |
|
|
318 | 318 | # Test against exact solution |
319 | 319 | for i in 1:size(t,1) |
320 | 320 | 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 |
322 | 375 | end |
323 | 376 | end |
324 | 377 |
|
|
0 commit comments