Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1291:356ec6a72974 refactor/grids
Implement changes in SbpOperators
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 07 Mar 2023 09:48:00 +0100 |
parents | 7d52c4835d15 |
children | e96ee7d7ac9c 43aaf710463e |
comparison
equal
deleted
inserted
replaced
1290:31d0b7638304 | 1291:356ec6a72974 |
---|---|
2 | 2 |
3 using Sbplib.SbpOperators | 3 using Sbplib.SbpOperators |
4 using Sbplib.Grids | 4 using Sbplib.Grids |
5 using Sbplib.LazyTensors | 5 using Sbplib.LazyTensors |
6 | 6 |
7 @test_skip @testset "Laplace" begin | 7 @testset "Laplace" begin |
8 # Default stencils (4th order) | 8 # Default stencils (4th order) |
9 operator_path = sbp_operators_path()*"standard_diagonal.toml" | 9 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
10 stencil_set = read_stencil_set(operator_path; order=4) | 10 stencil_set = read_stencil_set(operator_path; order=4) |
11 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 11 g_1D = equidistant_grid(101, 0.0, 1.) |
12 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | 12 g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) |
13 g_1D = EquidistantGrid(101, 0.0, 1.) | |
14 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | |
15 | 13 |
16 @testset "Constructors" begin | 14 @testset "Constructors" begin |
17 @testset "1D" begin | 15 @testset "1D" begin |
18 Δ = laplace(g_1D, inner_stencil, closure_stencils) | 16 @test Laplace(g_1D, stencil_set) == Laplace(laplace(g_1D, stencil_set), stencil_set) |
19 @test Laplace(g_1D, stencil_set) == Laplace(Δ, stencil_set) | 17 @test Laplace(g_1D, stencil_set) isa LazyTensor{Float64,1,1} |
20 @test Laplace(g_1D, stencil_set) isa LazyTensor{T,1,1} where T | |
21 end | 18 end |
22 @testset "3D" begin | 19 @testset "3D" begin |
23 Δ = laplace(g_3D, inner_stencil, closure_stencils) | 20 @test Laplace(g_3D, stencil_set) == Laplace(laplace(g_3D, stencil_set),stencil_set) |
24 @test Laplace(g_3D, stencil_set) == Laplace(Δ,stencil_set) | 21 @test Laplace(g_3D, stencil_set) isa LazyTensor{Float64,3,3} |
25 @test Laplace(g_3D, stencil_set) isa LazyTensor{T,3,3} where T | |
26 end | 22 end |
27 end | 23 end |
28 | 24 |
29 # Exact differentiation is measured point-wise. In other cases | 25 # Exact differentiation is measured point-wise. In other cases |
30 # the error is measured in the l2-norm. | 26 # the error is measured in the l2-norm. |
31 @testset "Accuracy" begin | 27 @testset "Accuracy" begin |
32 l2(v) = sqrt(prod(spacing(g_3D))*sum(v.^2)); | 28 l2(v) = sqrt(prod(spacing.(g_3D.grids))*sum(v.^2)); |
33 polynomials = () | 29 polynomials = () |
34 maxOrder = 4; | 30 maxOrder = 4; |
35 for i = 0:maxOrder-1 | 31 for i = 0:maxOrder-1 |
36 f_i(x,y,z) = 1/factorial(i)*(y^i + x^i + z^i) | 32 f_i(x,y,z) = 1/factorial(i)*(y^i + x^i + z^i) |
37 polynomials = (polynomials...,evalOn(g_3D,f_i)) | 33 polynomials = (polynomials...,eval_on(g_3D,f_i)) |
38 end | 34 end |
39 v = evalOn(g_3D, (x,y,z) -> sin(x) + cos(y) + exp(z)) | 35 # v = eval_on(g_3D, (x,y,z) -> sin(x) + cos(y) + exp(z)) |
40 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) | 36 # Δv = eval_on(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) |
37 | |
38 v = eval_on(g_3D, x̄ -> sin(x̄[1]) + cos(x̄[2]) + exp(x̄[3])) | |
39 Δv = eval_on(g_3D, x̄ -> -sin(x̄[1]) - cos(x̄[2]) + exp(x̄[3])) | |
40 @inferred v[1,2,3] | |
41 | 41 |
42 # 2nd order interior stencil, 1st order boundary stencil, | 42 # 2nd order interior stencil, 1st order boundary stencil, |
43 # implies that L*v should be exact for binomials up to order 2. | 43 # implies that L*v should be exact for binomials up to order 2. |
44 @testset "2nd order" begin | 44 @testset "2nd order" begin |
45 stencil_set = read_stencil_set(operator_path; order=2) | 45 stencil_set = read_stencil_set(operator_path; order=2) |
64 @test Δ*v ≈ Δv rtol = 5e-4 norm = l2 | 64 @test Δ*v ≈ Δv rtol = 5e-4 norm = l2 |
65 end | 65 end |
66 end | 66 end |
67 end | 67 end |
68 | 68 |
69 @test_skip @testset "laplace" begin | 69 @testset "laplace" begin |
70 operator_path = sbp_operators_path()*"standard_diagonal.toml" | 70 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
71 stencil_set = read_stencil_set(operator_path; order=4) | 71 stencil_set = read_stencil_set(operator_path; order=4) |
72 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) | 72 g_1D = equidistant_grid(101, 0.0, 1.) |
73 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) | 73 g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) |
74 g_1D = EquidistantGrid(101, 0.0, 1.) | |
75 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | |
76 | 74 |
77 @testset "1D" begin | 75 @testset "1D" begin |
78 Δ = laplace(g_1D, inner_stencil, closure_stencils) | 76 Δ = laplace(g_1D, stencil_set) |
79 @test Δ == second_derivative(g_1D, inner_stencil, closure_stencils, 1) | 77 @test Δ == second_derivative(g_1D, stencil_set) |
80 @test Δ isa LazyTensor{T,1,1} where T | 78 @test Δ isa LazyTensor{Float64,1,1} |
81 end | 79 end |
82 @testset "3D" begin | 80 @testset "3D" begin |
83 Δ = laplace(g_3D, inner_stencil, closure_stencils) | 81 Δ = laplace(g_3D, stencil_set) |
84 @test Δ isa LazyTensor{T,3,3} where T | 82 @test Δ isa LazyTensor{Float64,3,3} |
85 Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1) | 83 Dxx = second_derivative(g_3D, stencil_set, 1) |
86 Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2) | 84 Dyy = second_derivative(g_3D, stencil_set, 2) |
87 Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3) | 85 Dzz = second_derivative(g_3D, stencil_set, 3) |
88 @test Δ == Dxx + Dyy + Dzz | 86 @test Δ == Dxx + Dyy + Dzz |
89 @test Δ isa LazyTensor{T,3,3} where T | 87 @test Δ isa LazyTensor{Float64,3,3} |
90 end | 88 end |
91 end | 89 end |
92 | 90 |