comparison test/SbpOperators/boundaryops/normal_derivative_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 bea2feebbeca
comparison
equal deleted inserted replaced
768:7c87a33963c5 769:0158c3fd521c
1 using Test
2
3 using Sbplib.SbpOperators
4 using Sbplib.Grids
5 using Sbplib.RegionIndices
6 using Sbplib.LazyTensors
7
8 import Sbplib.SbpOperators.BoundaryOperator
9
10 @testset "normal_derivative" begin
11 g_1D = EquidistantGrid(11, 0.0, 1.0)
12 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0))
13 @testset "normal_derivative" begin
14 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
15 @testset "1D" begin
16 d_l = normal_derivative(g_1D, op.dClosure, Lower())
17 @test d_l == normal_derivative(g_1D, op.dClosure, CartesianBoundary{1,Lower}())
18 @test d_l isa BoundaryOperator{T,Lower} where T
19 @test d_l isa TensorMapping{T,0,1} where T
20 end
21 @testset "2D" begin
22 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
23 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}())
24 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}())
25 Ix = IdentityMapping{Float64}((size(g_2D)[1],))
26 Iy = IdentityMapping{Float64}((size(g_2D)[2],))
27 d_l = normal_derivative(restrict(g_2D,1),op.dClosure,Lower())
28 d_r = normal_derivative(restrict(g_2D,2),op.dClosure,Upper())
29 @test d_w == d_l⊗Iy
30 @test d_n == Ix⊗d_r
31 @test d_w isa TensorMapping{T,1,2} where T
32 @test d_n isa TensorMapping{T,1,2} where T
33 end
34 end
35 @testset "Accuracy" begin
36 v = evalOn(g_2D, (x,y)-> x^2 + (y-1)^2 + x*y)
37 v∂x = evalOn(g_2D, (x,y)-> 2*x + y)
38 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x)
39 # TODO: Test for higher order polynomials?
40 @testset "2nd order" begin
41 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2)
42 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}())
43 d_e = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}())
44 d_s = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}())
45 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}())
46
47 @test d_w*v ≈ v∂x[1,:] atol = 1e-13
48 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13
49 @test d_s*v ≈ v∂y[:,1] atol = 1e-13
50 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13
51 end
52
53 @testset "4th order" begin
54 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
55 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}())
56 d_e = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}())
57 d_s = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}())
58 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}())
59
60 @test d_w*v ≈ v∂x[1,:] atol = 1e-13
61 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13
62 @test d_s*v ≈ v∂y[:,1] atol = 1e-13
63 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13
64 end
65 end
66 end