Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/derivatives/secondderivative_test.jl @ 769:0158c3fd521c operator_storage_array_of_table
Merge in default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 15 Jul 2021 00:06:16 +0200 |
parents | 6114274447f5 |
children |
comparison
equal
deleted
inserted
replaced
768:7c87a33963c5 | 769:0158c3fd521c |
---|---|
1 using Test | |
2 | |
3 using Sbplib.SbpOperators | |
4 using Sbplib.Grids | |
5 using Sbplib.LazyTensors | |
6 | |
7 import Sbplib.SbpOperators.VolumeOperator | |
8 | |
9 @testset "SecondDerivative" begin | |
10 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
11 Lx = 3.5 | |
12 Ly = 3. | |
13 g_1D = EquidistantGrid(121, 0.0, Lx) | |
14 g_2D = EquidistantGrid((121,123), (0.0, 0.0), (Lx, Ly)) | |
15 | |
16 @testset "Constructors" begin | |
17 @testset "1D" begin | |
18 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
19 @test Dₓₓ == second_derivative(g_1D,op.innerStencil,op.closureStencils,1) | |
20 @test Dₓₓ isa VolumeOperator | |
21 end | |
22 @testset "2D" begin | |
23 Dₓₓ = second_derivative(g_2D,op.innerStencil,op.closureStencils,1) | |
24 D2 = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
25 I = IdentityMapping{Float64}(size(g_2D)[2]) | |
26 @test Dₓₓ == D2⊗I | |
27 @test Dₓₓ isa TensorMapping{T,2,2} where T | |
28 end | |
29 end | |
30 | |
31 # Exact differentiation is measured point-wise. In other cases | |
32 # the error is measured in the l2-norm. | |
33 @testset "Accuracy" begin | |
34 @testset "1D" begin | |
35 l2(v) = sqrt(spacing(g_1D)[1]*sum(v.^2)); | |
36 monomials = () | |
37 maxOrder = 4; | |
38 for i = 0:maxOrder-1 | |
39 f_i(x) = 1/factorial(i)*x^i | |
40 monomials = (monomials...,evalOn(g_1D,f_i)) | |
41 end | |
42 v = evalOn(g_1D,x -> sin(x)) | |
43 vₓₓ = evalOn(g_1D,x -> -sin(x)) | |
44 | |
45 # 2nd order interior stencil, 1nd order boundary stencil, | |
46 # implies that L*v should be exact for monomials up to order 2. | |
47 @testset "2nd order" begin | |
48 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
49 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
50 @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 | |
52 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 | |
53 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2 | |
54 end | |
55 | |
56 # 4th order interior stencil, 2nd order boundary stencil, | |
57 # implies that L*v should be exact for monomials up to order 3. | |
58 @testset "4th order" begin | |
59 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
60 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
61 # NOTE: high tolerances for checking the "exact" differentiation | |
62 # due to accumulation of round-off errors/cancellation errors? | |
63 @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 | |
65 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 | |
66 @test Dₓₓ*monomials[4] ≈ monomials[2] atol = 5e-10 | |
67 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-4 norm = l2 | |
68 end | |
69 end | |
70 | |
71 @testset "2D" begin | |
72 l2(v) = sqrt(prod(spacing(g_2D))*sum(v.^2)); | |
73 binomials = () | |
74 maxOrder = 4; | |
75 for i = 0:maxOrder-1 | |
76 f_i(x,y) = 1/factorial(i)*y^i + x^i | |
77 binomials = (binomials...,evalOn(g_2D,f_i)) | |
78 end | |
79 v = evalOn(g_2D, (x,y) -> sin(x)+cos(y)) | |
80 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) | |
81 | |
82 # 2nd order interior stencil, 1st order boundary stencil, | |
83 # implies that L*v should be exact for binomials up to order 2. | |
84 @testset "2nd order" begin | |
85 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
86 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) | |
87 @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 | |
89 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | |
90 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 | |
91 end | |
92 | |
93 # 4th order interior stencil, 2nd order boundary stencil, | |
94 # implies that L*v should be exact for binomials up to order 3. | |
95 @testset "4th order" begin | |
96 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
97 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) | |
98 # NOTE: high tolerances for checking the "exact" differentiation | |
99 # due to accumulation of round-off errors/cancellation errors? | |
100 @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 | |
102 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | |
103 @test Dyy*binomials[4] ≈ evalOn(g_2D,(x,y)->y) atol = 5e-9 | |
104 @test Dyy*v ≈ v_yy rtol = 5e-4 norm = l2 | |
105 end | |
106 end | |
107 end | |
108 end |