Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/boundaryops/normal_derivative_test.jl @ 926:47425442bbc5 feature/laplace_opset
Fix tests after refactoring
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 21 Feb 2022 23:33:29 +0100 |
parents | bea2feebbeca |
children | d360fc2d9620 |
comparison
equal
deleted
inserted
replaced
925:6b47a9ee1632 | 926:47425442bbc5 |
---|---|
1 using Test | 1 using Test |
2 | 2 |
3 using Sbplib.SbpOperators | 3 using Sbplib.SbpOperators |
4 using Sbplib.Grids | 4 using Sbplib.Grids |
5 using Sbplib.RegionIndices | |
6 using Sbplib.LazyTensors | 5 using Sbplib.LazyTensors |
7 | 6 |
8 import Sbplib.SbpOperators.BoundaryOperator | 7 import Sbplib.SbpOperators.BoundaryOperator |
9 | 8 |
10 @testset "normal_derivative" begin | 9 @testset "normal_derivative" begin |
12 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0)) | 11 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0)) |
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"]) | 14 d_closure = parse_stencil(stencil_set["d1"]["closure"]) |
16 @testset "1D" begin | 15 @testset "1D" begin |
17 d_l = normal_derivative(g_1D, d_closure, Lower()) | 16 d_l = normal_derivative(g_1D, d_closure, CartesianBoundary{1,Lower}()) |
18 @test d_l == normal_derivative(g_1D, d_closure, CartesianBoundary{1,Lower}()) | |
19 @test d_l isa BoundaryOperator{T,Lower} where T | 17 @test d_l isa BoundaryOperator{T,Lower} where T |
20 @test d_l isa TensorMapping{T,0,1} where T | 18 @test d_l isa TensorMapping{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, d_closure, CartesianBoundary{1,Lower}()) |
24 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) | 22 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) |
25 Ix = IdentityMapping{Float64}((size(g_2D)[1],)) | 23 Ix = IdentityMapping{Float64}((size(g_2D)[1],)) |
26 Iy = IdentityMapping{Float64}((size(g_2D)[2],)) | 24 Iy = IdentityMapping{Float64}((size(g_2D)[2],)) |
27 d_l = normal_derivative(restrict(g_2D,1),d_closure,Lower()) | 25 d_l = normal_derivative(restrict(g_2D,1),d_closure,CartesianBoundary{1,Lower}()) |
28 d_r = normal_derivative(restrict(g_2D,2),d_closure,Upper()) | 26 d_r = normal_derivative(restrict(g_2D,2),d_closure,CartesianBoundary{1,Upper}()) |
29 @test d_w == d_l⊗Iy | 27 @test d_w == d_l⊗Iy |
30 @test d_n == Ix⊗d_r | 28 @test d_n == Ix⊗d_r |
31 @test d_w isa TensorMapping{T,1,2} where T | 29 @test d_w isa TensorMapping{T,1,2} where T |
32 @test d_n isa TensorMapping{T,1,2} where T | 30 @test d_n isa TensorMapping{T,1,2} where T |
33 end | 31 end |
38 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x) | 36 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x) |
39 # TODO: Test for higher order polynomials? | 37 # TODO: Test for higher order polynomials? |
40 @testset "2nd order" begin | 38 @testset "2nd order" begin |
41 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 39 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) |
42 d_closure = parse_stencil(stencil_set["d1"]["closure"]) | 40 d_closure = parse_stencil(stencil_set["d1"]["closure"]) |
43 d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) | 41 (d_w, d_e, d_s, d_n) = |
44 d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) | 42 map(id -> normal_derivative(g_2D, d_closure, id), boundary_identifiers(g_2D)) |
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 | 43 |
48 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | 44 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 |
49 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | 45 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 |
50 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | 46 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 |
51 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | 47 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 |
52 end | 48 end |
53 | 49 |
54 @testset "4th order" begin | 50 @testset "4th order" begin |
55 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 51 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
56 d_closure = parse_stencil(stencil_set["d1"]["closure"]) | 52 d_closure = parse_stencil(stencil_set["d1"]["closure"]) |
57 d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) | 53 (d_w, d_e, d_s, d_n) = |
58 d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) | 54 map(id -> normal_derivative(g_2D, d_closure, id), boundary_identifiers(g_2D)) |
59 d_s = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Lower}()) | |
60 d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) | |
61 | 55 |
62 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | 56 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 |
63 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | 57 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 |
64 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | 58 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 |
65 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | 59 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 |