Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/derivatives/second_derivative_test.jl @ 1360:f59228534d3a tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 20 May 2023 15:15:22 +0200 |
parents | 356ec6a72974 |
children | 43aaf710463e |
comparison
equal
deleted
inserted
replaced
1321:42738616422e | 1360:f59228534d3a |
---|---|
13 stencil_set = read_stencil_set(operator_path; order=4) | 13 stencil_set = read_stencil_set(operator_path; order=4) |
14 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 14 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) |
15 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | 15 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) |
16 Lx = 3.5 | 16 Lx = 3.5 |
17 Ly = 3. | 17 Ly = 3. |
18 g_1D = EquidistantGrid(121, 0.0, Lx) | 18 g_1D = equidistant_grid(121, 0.0, Lx) |
19 g_2D = EquidistantGrid((121,123), (0.0, 0.0), (Lx, Ly)) | 19 g_2D = equidistant_grid((121,123), (0.0, 0.0), (Lx, Ly)) |
20 | 20 |
21 @testset "Constructors" begin | 21 @testset "Constructors" begin |
22 @testset "1D" begin | 22 @testset "1D" begin |
23 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils,1) | 23 Dₓₓ = second_derivative(g_1D, stencil_set) |
24 @test Dₓₓ == second_derivative(g_1D,inner_stencil,closure_stencils) | 24 @test Dₓₓ == second_derivative(g_1D, inner_stencil, closure_stencils) |
25 @test Dₓₓ == second_derivative(g_1D,stencil_set,1) | 25 @test Dₓₓ isa LazyTensor{Float64,1,1} |
26 @test Dₓₓ == second_derivative(g_1D,stencil_set) | |
27 @test Dₓₓ isa VolumeOperator | |
28 end | 26 end |
29 @testset "2D" begin | 27 @testset "2D" begin |
30 Dₓₓ = second_derivative(g_2D,inner_stencil,closure_stencils,1) | 28 Dₓₓ = second_derivative(g_2D,stencil_set,1) |
31 D2 = second_derivative(g_1D,inner_stencil,closure_stencils,1) | 29 @test Dₓₓ isa LazyTensor{Float64,2,2} |
32 I = IdentityTensor{Float64}(size(g_2D)[2]) | |
33 @test Dₓₓ == D2⊗I | |
34 @test Dₓₓ == second_derivative(g_2D,stencil_set,1) | |
35 @test Dₓₓ isa LazyTensor{T,2,2} where T | |
36 end | 30 end |
37 end | 31 end |
38 | 32 |
39 # Exact differentiation is measured point-wise. In other cases | 33 # Exact differentiation is measured point-wise. In other cases |
40 # the error is measured in the l2-norm. | 34 # the error is measured in the l2-norm. |
43 l2(v) = sqrt(spacing(g_1D)[1]*sum(v.^2)); | 37 l2(v) = sqrt(spacing(g_1D)[1]*sum(v.^2)); |
44 monomials = () | 38 monomials = () |
45 maxOrder = 4; | 39 maxOrder = 4; |
46 for i = 0:maxOrder-1 | 40 for i = 0:maxOrder-1 |
47 f_i(x) = 1/factorial(i)*x^i | 41 f_i(x) = 1/factorial(i)*x^i |
48 monomials = (monomials...,evalOn(g_1D,f_i)) | 42 monomials = (monomials...,eval_on(g_1D,f_i)) |
49 end | 43 end |
50 v = evalOn(g_1D,x -> sin(x)) | 44 v = eval_on(g_1D,x -> sin(x)) |
51 vₓₓ = evalOn(g_1D,x -> -sin(x)) | 45 vₓₓ = eval_on(g_1D,x -> -sin(x)) |
52 | 46 |
53 # 2nd order interior stencil, 1nd order boundary stencil, | 47 # 2nd order interior stencil, 1nd order boundary stencil, |
54 # implies that L*v should be exact for monomials up to order 2. | 48 # implies that L*v should be exact for monomials up to order 2. |
55 @testset "2nd order" begin | 49 @testset "2nd order" begin |
56 stencil_set = read_stencil_set(operator_path; order=2) | 50 stencil_set = read_stencil_set(operator_path; order=2) |
75 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-4 norm = l2 | 69 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-4 norm = l2 |
76 end | 70 end |
77 end | 71 end |
78 | 72 |
79 @testset "2D" begin | 73 @testset "2D" begin |
80 l2(v) = sqrt(prod(spacing(g_2D))*sum(v.^2)); | 74 l2(v) = sqrt(prod(spacing.(g_2D.grids))*sum(v.^2)); |
81 binomials = () | 75 binomials = () |
82 maxOrder = 4; | 76 maxOrder = 4; |
83 for i = 0:maxOrder-1 | 77 for i = 0:maxOrder-1 |
84 f_i(x,y) = 1/factorial(i)*y^i + x^i | 78 f_i(x,y) = 1/factorial(i)*y^i + x^i |
85 binomials = (binomials...,evalOn(g_2D,f_i)) | 79 binomials = (binomials...,eval_on(g_2D,f_i)) |
86 end | 80 end |
87 v = evalOn(g_2D, (x,y) -> sin(x)+cos(y)) | 81 v = eval_on(g_2D, (x,y) -> sin(x)+cos(y)) |
88 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) | 82 v_yy = eval_on(g_2D,(x,y) -> -cos(y)) |
89 | 83 |
90 # 2nd order interior stencil, 1st order boundary stencil, | 84 # 2nd order interior stencil, 1st order boundary stencil, |
91 # implies that L*v should be exact for binomials up to order 2. | 85 # implies that L*v should be exact for binomials up to order 2. |
92 @testset "2nd order" begin | 86 @testset "2nd order" begin |
93 stencil_set = read_stencil_set(operator_path; order=2) | 87 stencil_set = read_stencil_set(operator_path; order=2) |
94 Dyy = second_derivative(g_2D,stencil_set,2) | 88 Dyy = second_derivative(g_2D,stencil_set,2) |
95 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | 89 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 |
96 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | 90 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 |
97 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | 91 @test Dyy*binomials[3] ≈ eval_on(g_2D,(x,y)->1.) atol = 5e-9 |
98 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 | 92 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 |
99 end | 93 end |
100 | 94 |
101 # 4th order interior stencil, 2nd order boundary stencil, | 95 # 4th order interior stencil, 2nd order boundary stencil, |
102 # implies that L*v should be exact for binomials up to order 3. | 96 # implies that L*v should be exact for binomials up to order 3. |
105 Dyy = second_derivative(g_2D,stencil_set,2) | 99 Dyy = second_derivative(g_2D,stencil_set,2) |
106 # NOTE: high tolerances for checking the "exact" differentiation | 100 # NOTE: high tolerances for checking the "exact" differentiation |
107 # due to accumulation of round-off errors/cancellation errors? | 101 # due to accumulation of round-off errors/cancellation errors? |
108 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | 102 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 |
109 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | 103 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 |
110 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | 104 @test Dyy*binomials[3] ≈ eval_on(g_2D,(x,y)->1.) atol = 5e-9 |
111 @test Dyy*binomials[4] ≈ evalOn(g_2D,(x,y)->y) atol = 5e-9 | 105 @test Dyy*binomials[4] ≈ eval_on(g_2D,(x,y)->y) atol = 5e-9 |
112 @test Dyy*v ≈ v_yy rtol = 5e-4 norm = l2 | 106 @test Dyy*v ≈ v_yy rtol = 5e-4 norm = l2 |
113 end | 107 end |
114 end | 108 end |
115 end | 109 end |
116 end | 110 end |