comparison test/SbpOperators/volumeops/derivatives/second_derivative_test.jl @ 1018:5ec49dd2c7c4 feature/stencil_set_type

Reintroduce read_stencil_set
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 22 Mar 2022 09:57:28 +0100
parents b6238afd3bb0
children 7fc8df5157a7
comparison
equal deleted inserted replaced
991:37fd8c1cadb2 1018:5ec49dd2c7c4
6 6
7 import Sbplib.SbpOperators.VolumeOperator 7 import Sbplib.SbpOperators.VolumeOperator
8 8
9 @testset "SecondDerivative" begin 9 @testset "SecondDerivative" begin
10 operator_path = sbp_operators_path()*"standard_diagonal.toml" 10 operator_path = sbp_operators_path()*"standard_diagonal.toml"
11 stencil_set = StencilSet(operator_path; order=4) 11 stencil_set = read_stencil_set(operator_path; order=4)
12 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 12 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
13 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 13 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
14 Lx = 3.5 14 Lx = 3.5
15 Ly = 3. 15 Ly = 3.
16 g_1D = EquidistantGrid(121, 0.0, Lx) 16 g_1D = EquidistantGrid(121, 0.0, Lx)
49 vₓₓ = evalOn(g_1D,x -> -sin(x)) 49 vₓₓ = evalOn(g_1D,x -> -sin(x))
50 50
51 # 2nd order interior stencil, 1nd order boundary stencil, 51 # 2nd order interior stencil, 1nd order boundary stencil,
52 # implies that L*v should be exact for monomials up to order 2. 52 # implies that L*v should be exact for monomials up to order 2.
53 @testset "2nd order" begin 53 @testset "2nd order" begin
54 stencil_set = StencilSet(operator_path; order=2) 54 stencil_set = read_stencil_set(operator_path; order=2)
55 Dₓₓ = second_derivative(g_1D,stencil_set) 55 Dₓₓ = second_derivative(g_1D,stencil_set)
56 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 56 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
57 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 57 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
58 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 58 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10
59 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2 59 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2
60 end 60 end
61 61
62 # 4th order interior stencil, 2nd order boundary stencil, 62 # 4th order interior stencil, 2nd order boundary stencil,
63 # implies that L*v should be exact for monomials up to order 3. 63 # implies that L*v should be exact for monomials up to order 3.
64 @testset "4th order" begin 64 @testset "4th order" begin
65 stencil_set = StencilSet(operator_path; order=4) 65 stencil_set = read_stencil_set(operator_path; order=4)
66 Dₓₓ = second_derivative(g_1D,stencil_set) 66 Dₓₓ = second_derivative(g_1D,stencil_set)
67 # NOTE: high tolerances for checking the "exact" differentiation 67 # NOTE: high tolerances for checking the "exact" differentiation
68 # due to accumulation of round-off errors/cancellation errors? 68 # due to accumulation of round-off errors/cancellation errors?
69 @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
70 @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
86 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) 86 v_yy = evalOn(g_2D,(x,y) -> -cos(y))
87 87
88 # 2nd order interior stencil, 1st order boundary stencil, 88 # 2nd order interior stencil, 1st order boundary stencil,
89 # 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.
90 @testset "2nd order" begin 90 @testset "2nd order" begin
91 stencil_set = StencilSet(operator_path; order=2) 91 stencil_set = read_stencil_set(operator_path; order=2)
92 Dyy = second_derivative(g_2D,stencil_set,2) 92 Dyy = second_derivative(g_2D,stencil_set,2)
93 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 93 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
94 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 94 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
95 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 95 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9
96 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 96 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2
97 end 97 end
98 98
99 # 4th order interior stencil, 2nd order boundary stencil, 99 # 4th order interior stencil, 2nd order boundary stencil,
100 # implies that L*v should be exact for binomials up to order 3. 100 # implies that L*v should be exact for binomials up to order 3.
101 @testset "4th order" begin 101 @testset "4th order" begin
102 stencil_set = StencilSet(operator_path; order=4) 102 stencil_set = read_stencil_set(operator_path; order=4)
103 Dyy = second_derivative(g_2D,stencil_set,2) 103 Dyy = second_derivative(g_2D,stencil_set,2)
104 # NOTE: high tolerances for checking the "exact" differentiation 104 # NOTE: high tolerances for checking the "exact" differentiation
105 # due to accumulation of round-off errors/cancellation errors? 105 # due to accumulation of round-off errors/cancellation errors?
106 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 106 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
107 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 107 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9