Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/boundaryops/normal_derivative_test.jl @ 1858:4a9be96f2569 feature/documenter_logo
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 12 Jan 2025 21:18:44 +0100 |
parents | 471a948cd2b2 |
children | f3d7e2d7a43f |
comparison
equal
deleted
inserted
replaced
1857:ffde7dad9da5 | 1858:4a9be96f2569 |
---|---|
1 using Test | 1 using Test |
2 | 2 |
3 using Sbplib.SbpOperators | 3 using Diffinitive.SbpOperators |
4 using Sbplib.Grids | 4 using Diffinitive.Grids |
5 using Sbplib.RegionIndices | 5 using Diffinitive.LazyTensors |
6 using Sbplib.LazyTensors | 6 using Diffinitive.RegionIndices |
7 | 7 import Diffinitive.SbpOperators.BoundaryOperator |
8 import Sbplib.SbpOperators.BoundaryOperator | |
9 | 8 |
10 @testset "normal_derivative" begin | 9 @testset "normal_derivative" begin |
11 g_1D = EquidistantGrid(11, 0.0, 1.0) | 10 g_1D = equidistant_grid(0.0, 1.0, 11) |
12 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0)) | 11 g_2D = equidistant_grid((0.0, 0.0), (1.0,1.0), 11, 12) |
13 @testset "normal_derivative" begin | 12 @testset "normal_derivative" begin |
14 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 13 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
15 d_closure = parse_stencil(stencil_set["d1"]["closure"]) | |
16 @testset "1D" begin | 14 @testset "1D" begin |
17 d_l = normal_derivative(g_1D, d_closure, Lower()) | 15 d_l = normal_derivative(g_1D, stencil_set, LowerBoundary()) |
18 @test d_l == normal_derivative(g_1D, d_closure, CartesianBoundary{1,Lower}()) | 16 @test d_l == normal_derivative(g_1D, stencil_set, LowerBoundary()) |
19 @test d_l isa BoundaryOperator{T,Lower} where T | 17 @test d_l isa BoundaryOperator{T,LowerBoundary} where T |
20 @test d_l isa TensorMapping{T,0,1} where T | 18 @test d_l isa LazyTensor{T,0,1} where T |
21 end | 19 end |
22 @testset "2D" begin | 20 @testset "2D" begin |
23 d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) | 21 d_w = normal_derivative(g_2D, stencil_set, CartesianBoundary{1,LowerBoundary}()) |
24 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) | 22 d_n = normal_derivative(g_2D, stencil_set, CartesianBoundary{2,UpperBoundary}()) |
25 Ix = IdentityMapping{Float64}((size(g_2D)[1],)) | 23 Ix = IdentityTensor{Float64}((size(g_2D)[1],)) |
26 Iy = IdentityMapping{Float64}((size(g_2D)[2],)) | 24 Iy = IdentityTensor{Float64}((size(g_2D)[2],)) |
27 d_l = normal_derivative(restrict(g_2D,1),d_closure,Lower()) | 25 d_l = normal_derivative(g_2D.grids[1], stencil_set, LowerBoundary()) |
28 d_r = normal_derivative(restrict(g_2D,2),d_closure,Upper()) | 26 d_r = normal_derivative(g_2D.grids[2], stencil_set, UpperBoundary()) |
27 @test d_w == normal_derivative(g_2D, stencil_set, CartesianBoundary{1,LowerBoundary}()) | |
29 @test d_w == d_l⊗Iy | 28 @test d_w == d_l⊗Iy |
30 @test d_n == Ix⊗d_r | 29 @test d_n == Ix⊗d_r |
31 @test d_w isa TensorMapping{T,1,2} where T | 30 @test d_w isa LazyTensor{T,1,2} where T |
32 @test d_n isa TensorMapping{T,1,2} where T | 31 @test d_n isa LazyTensor{T,1,2} where T |
33 end | 32 end |
34 end | 33 end |
35 @testset "Accuracy" begin | 34 @testset "Accuracy" begin |
36 v = evalOn(g_2D, (x,y)-> x^2 + (y-1)^2 + x*y) | 35 v = eval_on(g_2D, (x,y)-> x^2 + (y-1)^2 + x*y) |
37 v∂x = evalOn(g_2D, (x,y)-> 2*x + y) | 36 v∂x = eval_on(g_2D, (x,y)-> 2*x + y) |
38 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x) | 37 v∂y = eval_on(g_2D, (x,y)-> 2*(y-1) + x) |
39 # TODO: Test for higher order polynomials? | 38 # TODO: Test for higher order polynomials? |
40 @testset "2nd order" begin | 39 @testset "2nd order" begin |
41 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 40 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) |
42 d_closure = parse_stencil(stencil_set["d1"]["closure"]) | 41 d_w, d_e, d_s, d_n = normal_derivative.(Ref(g_2D), Ref(stencil_set), boundary_identifiers(g_2D)) |
43 d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) | |
44 d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) | |
45 d_s = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Lower}()) | |
46 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) | |
47 | 42 |
48 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | 43 @test d_w*v ≈ -v∂x[1,:] atol = 1e-13 |
49 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | 44 @test d_e*v ≈ v∂x[end,:] atol = 1e-13 |
50 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | 45 @test d_s*v ≈ -v∂y[:,1] atol = 1e-13 |
51 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | 46 @test d_n*v ≈ v∂y[:,end] atol = 1e-13 |
52 end | 47 end |
53 | 48 |
54 @testset "4th order" begin | 49 @testset "4th order" begin |
55 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 50 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
56 d_closure = parse_stencil(stencil_set["d1"]["closure"]) | 51 d_w, d_e, d_s, d_n = normal_derivative.(Ref(g_2D), Ref(stencil_set), boundary_identifiers(g_2D)) |
57 d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) | 52 |
58 d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) | 53 @test d_w*v ≈ -v∂x[1,:] atol = 1e-13 |
59 d_s = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Lower}()) | 54 @test d_e*v ≈ v∂x[end,:] atol = 1e-13 |
60 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) | 55 @test d_s*v ≈ -v∂y[:,1] atol = 1e-13 |
61 | 56 @test d_n*v ≈ v∂y[:,end] atol = 1e-13 |
62 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | |
63 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | |
64 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | |
65 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | |
66 end | 57 end |
67 end | 58 end |
68 end | 59 end |