comparison test/SbpOperators/volumeops/derivatives/second_derivative_test.jl @ 781:d2f4ac2be47f operator_storage_array_of_table

Fix derivatives tests
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 19 Jul 2021 20:10:31 +0200
parents 6fb556b02f7c
children 2ae62dbaf839
comparison
equal deleted inserted replaced
780:3b29b2ff1f0e 781:d2f4ac2be47f
5 using Sbplib.LazyTensors 5 using Sbplib.LazyTensors
6 6
7 import Sbplib.SbpOperators.VolumeOperator 7 import Sbplib.SbpOperators.VolumeOperator
8 8
9 @testset "SecondDerivative" begin 9 @testset "SecondDerivative" begin
10 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 10 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
11 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
12 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
11 Lx = 3.5 13 Lx = 3.5
12 Ly = 3. 14 Ly = 3.
13 g_1D = EquidistantGrid(121, 0.0, Lx) 15 g_1D = EquidistantGrid(121, 0.0, Lx)
14 g_2D = EquidistantGrid((121,123), (0.0, 0.0), (Lx, Ly)) 16 g_2D = EquidistantGrid((121,123), (0.0, 0.0), (Lx, Ly))
15 17
16 @testset "Constructors" begin 18 @testset "Constructors" begin
17 @testset "1D" begin 19 @testset "1D" begin
18 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) 20 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils)
19 @test Dₓₓ == second_derivative(g_1D,op.innerStencil,op.closureStencils,1) 21 @test Dₓₓ == second_derivative(g_1D,inner_stencil,closure_stencils,1)
20 @test Dₓₓ isa VolumeOperator 22 @test Dₓₓ isa VolumeOperator
21 end 23 end
22 @testset "2D" begin 24 @testset "2D" begin
23 Dₓₓ = second_derivative(g_2D,op.innerStencil,op.closureStencils,1) 25 Dₓₓ = second_derivative(g_2D,inner_stencil,closure_stencils,1)
24 D2 = second_derivative(g_1D,op.innerStencil,op.closureStencils) 26 D2 = second_derivative(g_1D,inner_stencil,closure_stencils)
25 I = IdentityMapping{Float64}(size(g_2D)[2]) 27 I = IdentityMapping{Float64}(size(g_2D)[2])
26 @test Dₓₓ == D2⊗I 28 @test Dₓₓ == D2⊗I
27 @test Dₓₓ isa TensorMapping{T,2,2} where T 29 @test Dₓₓ isa TensorMapping{T,2,2} where T
28 end 30 end
29 end 31 end
43 vₓₓ = evalOn(g_1D,x -> -sin(x)) 45 vₓₓ = evalOn(g_1D,x -> -sin(x))
44 46
45 # 2nd order interior stencil, 1nd order boundary stencil, 47 # 2nd order interior stencil, 1nd order boundary stencil,
46 # 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.
47 @testset "2nd order" begin 49 @testset "2nd order" begin
48 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) 50 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2)
49 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) 51 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
52 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
53 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils)
50 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 54 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
51 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 55 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
52 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 56 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10
53 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2 57 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2
54 end 58 end
55 59
56 # 4th order interior stencil, 2nd order boundary stencil, 60 # 4th order interior stencil, 2nd order boundary stencil,
57 # implies that L*v should be exact for monomials up to order 3. 61 # implies that L*v should be exact for monomials up to order 3.
58 @testset "4th order" begin 62 @testset "4th order" begin
59 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 63 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
60 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) 64 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
65 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
66 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils)
61 # NOTE: high tolerances for checking the "exact" differentiation 67 # NOTE: high tolerances for checking the "exact" differentiation
62 # due to accumulation of round-off errors/cancellation errors? 68 # due to accumulation of round-off errors/cancellation errors?
63 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 69 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
64 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 70 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
65 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 71 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10
80 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) 86 v_yy = evalOn(g_2D,(x,y) -> -cos(y))
81 87
82 # 2nd order interior stencil, 1st order boundary stencil, 88 # 2nd order interior stencil, 1st order boundary stencil,
83 # implies that L*v should be exact for binomials up to order 2. 89 # implies that L*v should be exact for binomials up to order 2.
84 @testset "2nd order" begin 90 @testset "2nd order" begin
85 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) 91 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2)
86 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) 92 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
93 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
94 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2)
87 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 95 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
88 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 96 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
89 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 97 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9
90 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 98 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2
91 end 99 end
92 100
93 # 4th order interior stencil, 2nd order boundary stencil, 101 # 4th order interior stencil, 2nd order boundary stencil,
94 # implies that L*v should be exact for binomials up to order 3. 102 # implies that L*v should be exact for binomials up to order 3.
95 @testset "4th order" begin 103 @testset "4th order" begin
96 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 104 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
97 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) 105 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
106 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
107 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2)
98 # NOTE: high tolerances for checking the "exact" differentiation 108 # NOTE: high tolerances for checking the "exact" differentiation
99 # due to accumulation of round-off errors/cancellation errors? 109 # due to accumulation of round-off errors/cancellation errors?
100 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 110 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
101 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 111 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
102 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 112 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9