comparison test/SbpOperators/volumeops/derivatives/second_derivative_test.jl @ 989:7bf3121c6864 feature/stencil_set_type

Add type StencilSet
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Mar 2022 21:31:20 +0100
parents 2ae62dbaf839
children b6238afd3bb0
comparison
equal deleted inserted replaced
988:83046af6143a 989:7bf3121c6864
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 = read_stencil_set(operator_path; order=4) 11 stencil_set = StencilSet(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)
48 vₓₓ = evalOn(g_1D,x -> -sin(x)) 48 vₓₓ = evalOn(g_1D,x -> -sin(x))
49 49
50 # 2nd order interior stencil, 1nd order boundary stencil, 50 # 2nd order interior stencil, 1nd order boundary stencil,
51 # implies that L*v should be exact for monomials up to order 2. 51 # implies that L*v should be exact for monomials up to order 2.
52 @testset "2nd order" begin 52 @testset "2nd order" begin
53 stencil_set = read_stencil_set(operator_path; order=2) 53 stencil_set = StencilSet(operator_path; order=2)
54 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 54 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
55 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 55 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
56 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils) 56 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils)
57 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 57 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
58 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 58 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10
61 end 61 end
62 62
63 # 4th order interior stencil, 2nd order boundary stencil, 63 # 4th order interior stencil, 2nd order boundary stencil,
64 # implies that L*v should be exact for monomials up to order 3. 64 # implies that L*v should be exact for monomials up to order 3.
65 @testset "4th order" begin 65 @testset "4th order" begin
66 stencil_set = read_stencil_set(operator_path; order=4) 66 stencil_set = StencilSet(operator_path; order=4)
67 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 67 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
68 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 68 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
69 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils) 69 Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils)
70 # NOTE: high tolerances for checking the "exact" differentiation 70 # NOTE: high tolerances for checking the "exact" differentiation
71 # due to accumulation of round-off errors/cancellation errors? 71 # due to accumulation of round-off errors/cancellation errors?
89 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) 89 v_yy = evalOn(g_2D,(x,y) -> -cos(y))
90 90
91 # 2nd order interior stencil, 1st order boundary stencil, 91 # 2nd order interior stencil, 1st order boundary stencil,
92 # implies that L*v should be exact for binomials up to order 2. 92 # implies that L*v should be exact for binomials up to order 2.
93 @testset "2nd order" begin 93 @testset "2nd order" begin
94 stencil_set = read_stencil_set(operator_path; order=2) 94 stencil_set = StencilSet(operator_path; order=2)
95 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 95 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
96 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 96 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
97 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2) 97 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2)
98 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 98 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
99 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 99 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9
102 end 102 end
103 103
104 # 4th order interior stencil, 2nd order boundary stencil, 104 # 4th order interior stencil, 2nd order boundary stencil,
105 # implies that L*v should be exact for binomials up to order 3. 105 # implies that L*v should be exact for binomials up to order 3.
106 @testset "4th order" begin 106 @testset "4th order" begin
107 stencil_set = read_stencil_set(operator_path; order=4) 107 stencil_set = StencilSet(operator_path; order=4)
108 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 108 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
109 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 109 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
110 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2) 110 Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2)
111 # NOTE: high tolerances for checking the "exact" differentiation 111 # NOTE: high tolerances for checking the "exact" differentiation
112 # due to accumulation of round-off errors/cancellation errors? 112 # due to accumulation of round-off errors/cancellation errors?