|
172 | 172 |
|
173 | 173 | # Solve ODE problem |
174 | 174 | sol = solve(prob,Tsit5(),saveat=0.1) |
175 | | - x = prob.space[2] |
176 | | - t = sol.t |
177 | 175 |
|
178 | 176 | x = dx[2:end-1] |
179 | 177 | t = sol.t |
@@ -265,159 +263,15 @@ end |
265 | 263 |
|
266 | 264 | # Solve ODE problem |
267 | 265 | sol = solve(prob,Tsit5(),saveat=0.1) |
268 | | - x = dx[2:end-1] |
269 | | - t = sol.t |
270 | | - |
271 | | - # Test against exact solution |
272 | | - for i in 1:length(sol) |
273 | | - exact = u_exact(x, t[i]) |
274 | | - u_approx = sol.u[i] |
275 | | - @test u_approx ≈ exact atol=0.01 |
276 | | - end |
277 | | -end |
278 | | - |
279 | | -@testset "Test 06: Dt(u(t,x)) ~ Dxx(u(t,x)), time-dependent Robin BCs" begin |
280 | | - # Method of Manufactured Solutions |
281 | | - u_exact = (x,t) -> exp.(-t) * sin.(x) |
282 | | - |
283 | | - # Parameters, variables, and derivatives |
284 | | - @parameters t x |
285 | | - @variables u(..) |
286 | | - Dt = Differential(t) |
287 | | - Dx = Differential(x) |
288 | | - Dxx = Differential(x)^2 |
289 | | - |
290 | | - # 1D PDE and boundary conditions |
291 | | - eq = Dt(u(t,x)) ~ Dxx(u(t,x)) |
292 | | - bcs = [u(0,x) ~ sin(x), |
293 | | - t^2 * u(t,-1.0) + 3Dx(u(t,-1.0)) ~ exp(-t) * (t^2 * sin(-1.0) + 3cos(-1.0)), |
294 | | - 4u(t,1.0) + t * Dx(u(t,1.0)) ~ exp(-t) * (4sin(1.0) + t * cos(1.0))] |
295 | | - |
296 | | - # Space and time domains |
297 | | - domains = [t ∈ IntervalDomain(0.0,1.0), |
298 | | - x ∈ IntervalDomain(-1.0,1.0)] |
299 | | - |
300 | | - # PDE system |
301 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
302 | | - |
303 | | - # Method of lines discretization |
304 | | - dx = 0.01 |
305 | | - order = 2 |
306 | | - discretization = MOLFiniteDifference([x=>dx],t) |
307 | | - |
308 | | - # Convert the PDE problem into an ODE problem |
309 | | - prob = discretize(pdesys,discretization) |
310 | | - |
311 | | - # Solve ODE problem |
312 | | - sol = solve(prob,Tsit5(),saveat=0.1) |
313 | | - x = prob.space[2] |
314 | | - t = sol.t |
315 | | - |
316 | | - x = dx[2:end-1] |
| 266 | + x = (-1:dx:1)[2:end-1] |
317 | 267 | t = sol.t |
318 | 268 |
|
319 | 269 | # Test against exact solution |
320 | 270 | for i in 1:length(sol) |
321 | 271 | exact = u_exact(x, t[i]) |
322 | 272 | u_approx = sol.u[i] |
323 | | - @test u_approx ≈ exact atol=0.01 |
| 273 | + @test u_approx ≈ exact atol=0.1 |
324 | 274 | end |
325 | 275 | end |
326 | 276 |
|
327 | | -@testset "Test errors" begin |
328 | | - # Parameters, variables, and derivatives |
329 | | - @parameters t x |
330 | | - @variables u(..) v(..) |
331 | | - Dt = Differential(t) |
332 | | - Dx = Differential(x) |
333 | | - Dxx = Differential(x)^2 |
334 | | - |
335 | | - # 1D PDE and boundary conditions |
336 | | - eq = Dt(u(t,x)) ~ Dxx(u(t,x)) |
337 | | - # Space and time domains |
338 | | - domains = [t ∈ IntervalDomain(0.0,1.0), x ∈ IntervalDomain(0.0,1.0)] |
339 | | - |
340 | | - # Method of lines discretization |
341 | | - dx = 0.1 |
342 | | - order = 2 |
343 | | - discretization = MOLFiniteDifference([x=>dx],t) |
344 | | - |
345 | | - # Missing boundary condition |
346 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
347 | | - Dx(u(t,1)) ~ 0.0] |
348 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
349 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
350 | | - |
351 | | - # Boundary condition not at t=0 |
352 | | - bcs = [u(1,x) ~ 0.5 + sin(2pi*x), |
353 | | - Dx(u(t,0)) ~ 0.0, |
354 | | - Dx(u(t,1)) ~ 0.0] |
355 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
356 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
357 | 277 |
|
358 | | - # Boundary condition not at an edge of the domain |
359 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
360 | | - Dx(u(t,0)) ~ 0.0, |
361 | | - Dx(u(t,0.5)) ~ 0.0] |
362 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
363 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
364 | | - |
365 | | - # Second-order derivative in BC |
366 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
367 | | - Dxx(u(t,0)) ~ 0.0, |
368 | | - Dx(u(t,0.5)) ~ 0.0] |
369 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
370 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
371 | | - |
372 | | - # Wrong format for Robin BCs |
373 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
374 | | - Dx(u(t,0)) ~ 0.0, |
375 | | - u(t,1) * Dx(u(t,1)) ~ 0.0] |
376 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
377 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
378 | | - |
379 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
380 | | - Dx(u(t,0)) ~ 0.0, |
381 | | - u(t,1) + Dxx(u(t,1)) ~ 0.0] |
382 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
383 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
384 | | - |
385 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
386 | | - Dx(u(t,0)) ~ 0.0, |
387 | | - u(t,1) + 2Dxx(u(t,1)) ~ 0.0] |
388 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
389 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
390 | | - |
391 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
392 | | - Dx(u(t,0)) ~ 0.0, |
393 | | - Dx(u(t,1)) + u(t,1) ~ 0.0] |
394 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
395 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
396 | | - |
397 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
398 | | - Dx(u(t,0)) ~ 0.0, |
399 | | - u(t,1) / 2 + Dx(u(t,1)) ~ 0.0] |
400 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
401 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
402 | | - |
403 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
404 | | - Dx(u(t,0)) ~ 0.0, |
405 | | - u(t,1) + Dx(u(t,1)) / 2 ~ 0.0] |
406 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
407 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
408 | | - |
409 | | - # Mismatching arguments |
410 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
411 | | - Dx(u(t,0)) ~ 0.0, |
412 | | - u(t,0) + Dx(u(t,1)) ~ 0.0] |
413 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
414 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
415 | | - |
416 | | - # Mismatching variables |
417 | | - bcs = [u(0,x) ~ 0.5 + sin(2pi*x), |
418 | | - Dx(u(t,0)) ~ 0.0, |
419 | | - u(t,1) + Dx(v(t,1)) ~ 0.0] |
420 | | - pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) |
421 | | - @test_throws BoundaryConditionError discretize(pdesys,discretization) |
422 | | - |
423 | | -end |
0 commit comments