Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1207:f1c2a4fa0ee1 performance/get_region_type_inference
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 03 Feb 2023 22:14:47 +0100 |
parents | 7fc8df5157a7 |
children | 7d52c4835d15 |
comparison
equal
deleted
inserted
replaced
919:b41180efb6c2 | 1207:f1c2a4fa0ee1 |
---|---|
2 | 2 |
3 using Sbplib.SbpOperators | 3 using Sbplib.SbpOperators |
4 using Sbplib.Grids | 4 using Sbplib.Grids |
5 using Sbplib.LazyTensors | 5 using Sbplib.LazyTensors |
6 | 6 |
7 # Default stencils (4th order) | |
8 operator_path = sbp_operators_path()*"standard_diagonal.toml" | |
9 stencil_set = read_stencil_set(operator_path; order=4) | |
10 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | |
11 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | |
12 g_1D = EquidistantGrid(101, 0.0, 1.) | |
13 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | |
14 | |
7 @testset "Laplace" begin | 15 @testset "Laplace" begin |
8 g_1D = EquidistantGrid(101, 0.0, 1.) | |
9 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | |
10 @testset "Constructors" begin | 16 @testset "Constructors" begin |
11 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
12 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | |
13 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | |
14 @testset "1D" begin | 17 @testset "1D" begin |
15 L = laplace(g_1D, inner_stencil, closure_stencils) | 18 Δ = laplace(g_1D, inner_stencil, closure_stencils) |
16 @test L == second_derivative(g_1D, inner_stencil, closure_stencils) | 19 @test Laplace(g_1D, stencil_set) == Laplace(Δ, stencil_set) |
17 @test L isa TensorMapping{T,1,1} where T | 20 @test Laplace(g_1D, stencil_set) isa LazyTensor{T,1,1} where T |
18 end | 21 end |
19 @testset "3D" begin | 22 @testset "3D" begin |
20 L = laplace(g_3D, inner_stencil, closure_stencils) | 23 Δ = laplace(g_3D, inner_stencil, closure_stencils) |
21 @test L isa TensorMapping{T,3,3} where T | 24 @test Laplace(g_3D, stencil_set) == Laplace(Δ,stencil_set) |
22 Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1) | 25 @test Laplace(g_3D, stencil_set) isa LazyTensor{T,3,3} where T |
23 Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2) | |
24 Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3) | |
25 @test L == Dxx + Dyy + Dzz | |
26 end | 26 end |
27 end | 27 end |
28 | 28 |
29 # Exact differentiation is measured point-wise. In other cases | 29 # Exact differentiation is measured point-wise. In other cases |
30 # the error is measured in the l2-norm. | 30 # the error is measured in the l2-norm. |
40 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) | 40 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) |
41 | 41 |
42 # 2nd order interior stencil, 1st order boundary stencil, | 42 # 2nd order interior stencil, 1st order boundary stencil, |
43 # implies that L*v should be exact for binomials up to order 2. | 43 # implies that L*v should be exact for binomials up to order 2. |
44 @testset "2nd order" begin | 44 @testset "2nd order" begin |
45 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 45 stencil_set = read_stencil_set(operator_path; order=2) |
46 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 46 Δ = Laplace(g_3D, stencil_set) |
47 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | 47 @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
48 L = laplace(g_3D, inner_stencil, closure_stencils) | 48 @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
49 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 49 @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9 |
50 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 50 @test Δ*v ≈ Δv rtol = 5e-2 norm = l2 |
51 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | |
52 @test L*v ≈ Δv rtol = 5e-2 norm = l2 | |
53 end | 51 end |
54 | 52 |
55 # 4th order interior stencil, 2nd order boundary stencil, | 53 # 4th order interior stencil, 2nd order boundary stencil, |
56 # implies that L*v should be exact for binomials up to order 3. | 54 # implies that L*v should be exact for binomials up to order 3. |
57 @testset "4th order" begin | 55 @testset "4th order" begin |
58 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 56 stencil_set = read_stencil_set(operator_path; order=4) |
59 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 57 Δ = Laplace(g_3D, stencil_set) |
60 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | |
61 L = laplace(g_3D, inner_stencil, closure_stencils) | |
62 # NOTE: high tolerances for checking the "exact" differentiation | 58 # NOTE: high tolerances for checking the "exact" differentiation |
63 # due to accumulation of round-off errors/cancellation errors? | 59 # due to accumulation of round-off errors/cancellation errors? |
64 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 60 @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
65 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | 61 @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
66 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | 62 @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9 |
67 @test L*polynomials[4] ≈ polynomials[2] atol = 5e-9 | 63 @test Δ*polynomials[4] ≈ polynomials[2] atol = 5e-9 |
68 @test L*v ≈ Δv rtol = 5e-4 norm = l2 | 64 @test Δ*v ≈ Δv rtol = 5e-4 norm = l2 |
69 end | 65 end |
70 end | 66 end |
71 end | 67 end |
68 | |
69 @testset "laplace" begin | |
70 @testset "1D" begin | |
71 Δ = laplace(g_1D, inner_stencil, closure_stencils) | |
72 @test Δ == second_derivative(g_1D, inner_stencil, closure_stencils, 1) | |
73 @test Δ isa LazyTensor{T,1,1} where T | |
74 end | |
75 @testset "3D" begin | |
76 Δ = laplace(g_3D, inner_stencil, closure_stencils) | |
77 @test Δ isa LazyTensor{T,3,3} where T | |
78 Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1) | |
79 Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2) | |
80 Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3) | |
81 @test Δ == Dxx + Dyy + Dzz | |
82 @test Δ isa LazyTensor{T,3,3} where T | |
83 end | |
84 end | |
85 |