Mercurial > repos > public > sbplib_julia
comparison test/testSbpOperators.jl @ 705:bf1387f867b8 feature/laplace_opset
Add tests for Laplace field getter functions
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 15 Feb 2021 17:53:13 +0100 |
parents | 988e9cfcd58d |
children | 19301615b340 |
comparison
equal
deleted
inserted
replaced
704:a7efedbdede9 | 705:bf1387f867b8 |
---|---|
334 end | 334 end |
335 | 335 |
336 @testset "Laplace" begin | 336 @testset "Laplace" begin |
337 g_1D = EquidistantGrid(101, 0.0, 1.) | 337 g_1D = EquidistantGrid(101, 0.0, 1.) |
338 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | 338 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) |
339 op2 = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
340 op4 = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
339 @testset "Constructors" begin | 341 @testset "Constructors" begin |
340 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 342 |
341 @testset "1D" begin | 343 @testset "1D" begin |
342 # Create all tensor mappings included in Laplace | 344 # Create all tensor mappings included in Laplace |
343 Δ = laplace(g_1D, op.innerStencil, op.closureStencils) | 345 Δ = laplace(g_1D, op4.innerStencil, op4.closureStencils) |
344 H = inner_product(g_1D, op.quadratureClosure) | 346 H = inner_product(g_1D, op4.quadratureClosure) |
345 Hi = inverse_inner_product(g_1D, op.quadratureClosure) | 347 Hi = inverse_inner_product(g_1D, op4.quadratureClosure) |
346 | 348 |
347 (id_l, id_r) = boundary_identifiers(g_1D) | 349 (id_l, id_r) = boundary_identifiers(g_1D) |
348 | 350 |
349 e_l = boundary_restriction(g_1D,op.eClosure,id_l) | 351 e_l = boundary_restriction(g_1D,op4.eClosure,id_l) |
350 e_r = boundary_restriction(g_1D,op.eClosure,id_r) | 352 e_r = boundary_restriction(g_1D,op4.eClosure,id_r) |
351 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r)) | 353 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r)) |
352 | 354 |
353 d_l = normal_derivative(g_1D,op.dClosure,id_l) | 355 d_l = normal_derivative(g_1D,op4.dClosure,id_l) |
354 d_r = normal_derivative(g_1D,op.dClosure,id_r) | 356 d_r = normal_derivative(g_1D,op4.dClosure,id_r) |
355 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r)) | 357 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r)) |
356 | 358 |
357 H_l = inner_product(boundary_grid(g_1D,id_l),op.quadratureClosure) | 359 H_l = inner_product(boundary_grid(g_1D,id_l),op4.quadratureClosure) |
358 H_r = inner_product(boundary_grid(g_1D,id_r),op.quadratureClosure) | 360 H_r = inner_product(boundary_grid(g_1D,id_r),op4.quadratureClosure) |
359 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r)) | 361 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r)) |
360 | 362 |
361 L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) | 363 L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) |
362 @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) | 364 @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) |
363 @test L isa TensorMapping{T,1,1} where T | 365 @test L isa TensorMapping{T,1,1} where T |
364 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) | 366 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) |
365 end | 367 end |
366 @testset "3D" begin | 368 @testset "3D" begin |
367 # Create all tensor mappings included in Laplace | 369 # Create all tensor mappings included in Laplace |
368 Δ = laplace(g_3D, op.innerStencil, op.closureStencils) | 370 Δ = laplace(g_3D, op4.innerStencil, op4.closureStencils) |
369 H = inner_product(g_3D, op.quadratureClosure) | 371 H = inner_product(g_3D, op4.quadratureClosure) |
370 Hi = inverse_inner_product(g_3D, op.quadratureClosure) | 372 Hi = inverse_inner_product(g_3D, op4.quadratureClosure) |
371 | 373 |
372 (id_l, id_r, id_s, id_n, id_b, id_t) = boundary_identifiers(g_3D) | 374 (id_l, id_r, id_s, id_n, id_b, id_t) = boundary_identifiers(g_3D) |
373 | 375 |
374 e_l = boundary_restriction(g_3D,op.eClosure,id_l) | 376 e_l = boundary_restriction(g_3D,op4.eClosure,id_l) |
375 e_r = boundary_restriction(g_3D,op.eClosure,id_r) | 377 e_r = boundary_restriction(g_3D,op4.eClosure,id_r) |
376 e_s = boundary_restriction(g_3D,op.eClosure,id_s) | 378 e_s = boundary_restriction(g_3D,op4.eClosure,id_s) |
377 e_n = boundary_restriction(g_3D,op.eClosure,id_n) | 379 e_n = boundary_restriction(g_3D,op4.eClosure,id_n) |
378 e_b = boundary_restriction(g_3D,op.eClosure,id_b) | 380 e_b = boundary_restriction(g_3D,op4.eClosure,id_b) |
379 e_t = boundary_restriction(g_3D,op.eClosure,id_t) | 381 e_t = boundary_restriction(g_3D,op4.eClosure,id_t) |
380 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r), | 382 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r), |
381 Pair(id_s,e_s),Pair(id_n,e_n), | 383 Pair(id_s,e_s),Pair(id_n,e_n), |
382 Pair(id_b,e_b),Pair(id_t,e_t)) | 384 Pair(id_b,e_b),Pair(id_t,e_t)) |
383 | 385 |
384 d_l = normal_derivative(g_3D,op.dClosure,id_l) | 386 d_l = normal_derivative(g_3D,op4.dClosure,id_l) |
385 d_r = normal_derivative(g_3D,op.dClosure,id_r) | 387 d_r = normal_derivative(g_3D,op4.dClosure,id_r) |
386 d_s = normal_derivative(g_3D,op.dClosure,id_s) | 388 d_s = normal_derivative(g_3D,op4.dClosure,id_s) |
387 d_n = normal_derivative(g_3D,op.dClosure,id_n) | 389 d_n = normal_derivative(g_3D,op4.dClosure,id_n) |
388 d_b = normal_derivative(g_3D,op.dClosure,id_b) | 390 d_b = normal_derivative(g_3D,op4.dClosure,id_b) |
389 d_t = normal_derivative(g_3D,op.dClosure,id_t) | 391 d_t = normal_derivative(g_3D,op4.dClosure,id_t) |
390 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r), | 392 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r), |
391 Pair(id_s,d_s),Pair(id_n,d_n), | 393 Pair(id_s,d_s),Pair(id_n,d_n), |
392 Pair(id_b,d_b),Pair(id_t,d_t)) | 394 Pair(id_b,d_b),Pair(id_t,d_t)) |
393 | 395 |
394 H_l = inner_product(boundary_grid(g_3D,id_l),op.quadratureClosure) | 396 H_l = inner_product(boundary_grid(g_3D,id_l),op4.quadratureClosure) |
395 H_r = inner_product(boundary_grid(g_3D,id_r),op.quadratureClosure) | 397 H_r = inner_product(boundary_grid(g_3D,id_r),op4.quadratureClosure) |
396 H_s = inner_product(boundary_grid(g_3D,id_s),op.quadratureClosure) | 398 H_s = inner_product(boundary_grid(g_3D,id_s),op4.quadratureClosure) |
397 H_n = inner_product(boundary_grid(g_3D,id_n),op.quadratureClosure) | 399 H_n = inner_product(boundary_grid(g_3D,id_n),op4.quadratureClosure) |
398 H_b = inner_product(boundary_grid(g_3D,id_b),op.quadratureClosure) | 400 H_b = inner_product(boundary_grid(g_3D,id_b),op4.quadratureClosure) |
399 H_t = inner_product(boundary_grid(g_3D,id_t),op.quadratureClosure) | 401 H_t = inner_product(boundary_grid(g_3D,id_t),op4.quadratureClosure) |
400 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r), | 402 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r), |
401 Pair(id_s,H_s),Pair(id_n,H_n), | 403 Pair(id_s,H_s),Pair(id_n,H_n), |
402 Pair(id_b,H_b),Pair(id_t,H_t)) | 404 Pair(id_b,H_b),Pair(id_t,H_t)) |
403 | 405 |
404 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) | 406 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) |
407 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) | 409 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) |
408 end | 410 end |
409 end | 411 end |
410 | 412 |
411 @testset "laplace" begin | 413 @testset "laplace" begin |
412 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 414 @testset "1D" begin |
413 @testset "1D" begin | 415 L = laplace(g_1D, op4.innerStencil, op4.closureStencils) |
414 L = laplace(g_1D, op.innerStencil, op.closureStencils) | 416 @test L == second_derivative(g_1D, op4.innerStencil, op4.closureStencils) |
415 @test L == second_derivative(g_1D, op.innerStencil, op.closureStencils) | |
416 @test L isa TensorMapping{T,1,1} where T | 417 @test L isa TensorMapping{T,1,1} where T |
417 end | 418 end |
418 @testset "3D" begin | 419 @testset "3D" begin |
419 L = laplace(g_3D, op.innerStencil, op.closureStencils) | 420 L = laplace(g_3D, op4.innerStencil, op4.closureStencils) |
420 @test L isa TensorMapping{T,3,3} where T | 421 @test L isa TensorMapping{T,3,3} where T |
421 Dxx = second_derivative(g_3D, op.innerStencil, op.closureStencils,1) | 422 Dxx = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,1) |
422 Dyy = second_derivative(g_3D, op.innerStencil, op.closureStencils,2) | 423 Dyy = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,2) |
423 Dzz = second_derivative(g_3D, op.innerStencil, op.closureStencils,3) | 424 Dzz = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,3) |
424 @test L == Dxx + Dyy + Dzz | 425 @test L == Dxx + Dyy + Dzz |
425 @test L isa TensorMapping{T,3,3} where T | 426 @test L isa TensorMapping{T,3,3} where T |
426 end | 427 end |
427 end | 428 end |
428 | 429 |
429 @testset "quadrature" begin | 430 @testset "inner_product" begin |
430 end | 431 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) |
431 | 432 @test inner_product(L) == inner_product(g_3D,op4.quadratureClosure) |
432 @testset "inverse_quadrature" begin | 433 end |
434 | |
435 @testset "inverse_inner_product" begin | |
436 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
437 @test inverse_inner_product(L) == inverse_inner_product(g_3D,op4.quadratureClosure) | |
433 end | 438 end |
434 | 439 |
435 @testset "boundary_restriction" begin | 440 @testset "boundary_restriction" begin |
436 end | 441 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) |
437 | 442 id_l = CartesianBoundary{1,Lower}() |
438 @testset "normal_restriction" begin | 443 id_r = CartesianBoundary{1,Upper}() |
444 id_s = CartesianBoundary{2,Lower}() | |
445 id_n = CartesianBoundary{2,Upper}() | |
446 id_b = CartesianBoundary{3,Lower}() | |
447 id_t = CartesianBoundary{3,Upper}() | |
448 @test boundary_restriction(L,id_l) == boundary_restriction(g_3D,op4.eClosure,id_l) | |
449 @test boundary_restriction(L,id_r) == boundary_restriction(g_3D,op4.eClosure,id_r) | |
450 @test boundary_restriction(L,id_s) == boundary_restriction(g_3D,op4.eClosure,id_s) | |
451 @test boundary_restriction(L,id_n) == boundary_restriction(g_3D,op4.eClosure,id_n) | |
452 @test boundary_restriction(L,id_b) == boundary_restriction(g_3D,op4.eClosure,id_b) | |
453 @test boundary_restriction(L,id_t) == boundary_restriction(g_3D,op4.eClosure,id_t) | |
454 end | |
455 | |
456 @testset "normal_derivative" begin | |
457 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
458 id_l = CartesianBoundary{1,Lower}() | |
459 id_r = CartesianBoundary{1,Upper}() | |
460 id_s = CartesianBoundary{2,Lower}() | |
461 id_n = CartesianBoundary{2,Upper}() | |
462 id_b = CartesianBoundary{3,Lower}() | |
463 id_t = CartesianBoundary{3,Upper}() | |
464 @test normal_derivative(L,id_l) == normal_derivative(g_3D,op4.dClosure,id_l) | |
465 @test normal_derivative(L,id_r) == normal_derivative(g_3D,op4.dClosure,id_r) | |
466 @test normal_derivative(L,id_s) == normal_derivative(g_3D,op4.dClosure,id_s) | |
467 @test normal_derivative(L,id_n) == normal_derivative(g_3D,op4.dClosure,id_n) | |
468 @test normal_derivative(L,id_b) == normal_derivative(g_3D,op4.dClosure,id_b) | |
469 @test normal_derivative(L,id_t) == normal_derivative(g_3D,op4.dClosure,id_t) | |
439 end | 470 end |
440 | 471 |
441 @testset "boundary_quadrature" begin | 472 @testset "boundary_quadrature" begin |
473 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
474 id_l = CartesianBoundary{1,Lower}() | |
475 id_r = CartesianBoundary{1,Upper}() | |
476 id_s = CartesianBoundary{2,Lower}() | |
477 id_n = CartesianBoundary{2,Upper}() | |
478 id_b = CartesianBoundary{3,Lower}() | |
479 id_t = CartesianBoundary{3,Upper}() | |
480 @test boundary_quadrature(L,id_l) == inner_product(boundary_grid(g_3D,id_l),op4.quadratureClosure) | |
481 @test boundary_quadrature(L,id_r) == inner_product(boundary_grid(g_3D,id_r),op4.quadratureClosure) | |
482 @test boundary_quadrature(L,id_s) == inner_product(boundary_grid(g_3D,id_s),op4.quadratureClosure) | |
483 @test boundary_quadrature(L,id_n) == inner_product(boundary_grid(g_3D,id_n),op4.quadratureClosure) | |
484 @test boundary_quadrature(L,id_b) == inner_product(boundary_grid(g_3D,id_b),op4.quadratureClosure) | |
485 @test boundary_quadrature(L,id_t) == inner_product(boundary_grid(g_3D,id_t),op4.quadratureClosure) | |
442 end | 486 end |
443 | 487 |
444 # Exact differentiation is measured point-wise. In other cases | 488 # Exact differentiation is measured point-wise. In other cases |
445 # the error is measured in the l2-norm. | 489 # the error is measured in the l2-norm. |
446 @testset "Accuracy" begin | 490 @testset "Accuracy" begin |
455 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) | 499 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) |
456 | 500 |
457 # 2nd order interior stencil, 1st order boundary stencil, | 501 # 2nd order interior stencil, 1st order boundary stencil, |
458 # implies that L*v should be exact for binomials up to order 2. | 502 # implies that L*v should be exact for binomials up to order 2. |
459 @testset "2nd order" begin | 503 @testset "2nd order" begin |
460 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 504 L = laplace(g_3D,op2.innerStencil,op2.closureStencils) |
461 L = laplace(g_3D,op.innerStencil,op.closureStencils) | |
462 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 505 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
463 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 506 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
464 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | 507 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 |
465 @test L*v ≈ Δv rtol = 5e-2 norm = l2 | 508 @test L*v ≈ Δv rtol = 5e-2 norm = l2 |
466 end | 509 end |
467 | 510 |
468 # 4th order interior stencil, 2nd order boundary stencil, | 511 # 4th order interior stencil, 2nd order boundary stencil, |
469 # implies that L*v should be exact for binomials up to order 3. | 512 # implies that L*v should be exact for binomials up to order 3. |
470 @testset "4th order" begin | 513 @testset "4th order" begin |
471 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 514 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
472 L = laplace(g_3D,op.innerStencil,op.closureStencils) | 515 L = laplace(g_3D,op4.innerStencil,op4.closureStencils) |
473 # NOTE: high tolerances for checking the "exact" differentiation | 516 # NOTE: high tolerances for checking the "exact" differentiation |
474 # due to accumulation of round-off errors/cancellation errors? | 517 # due to accumulation of round-off errors/cancellation errors? |
475 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 518 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
476 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 519 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
477 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | 520 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 |