comparison test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1351:d7f29359b822

Merge refactor/grids
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 19 May 2023 23:53:36 +0200
parents 356ec6a72974
children e96ee7d7ac9c 43aaf710463e
comparison
equal deleted inserted replaced
1323:95cac1ee8476 1351:d7f29359b822
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 # Default stencils (4th order) 7 @testset "Laplace" begin
8 operator_path = sbp_operators_path()*"standard_diagonal.toml" 8 # Default stencils (4th order)
9 stencil_set = read_stencil_set(operator_path; order=4) 9 operator_path = sbp_operators_path()*"standard_diagonal.toml"
10 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) 10 stencil_set = read_stencil_set(operator_path; order=4)
11 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) 11 g_1D = equidistant_grid(101, 0.0, 1.)
12 g_1D = EquidistantGrid(101, 0.0, 1.) 12 g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
13 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
14 13
15 @testset "Laplace" begin
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)
65 end 65 end
66 end 66 end
67 end 67 end
68 68
69 @testset "laplace" begin 69 @testset "laplace" begin
70 operator_path = sbp_operators_path()*"standard_diagonal.toml"
71 stencil_set = read_stencil_set(operator_path; order=4)
72 g_1D = equidistant_grid(101, 0.0, 1.)
73 g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
74
70 @testset "1D" begin 75 @testset "1D" begin
71 Δ = laplace(g_1D, inner_stencil, closure_stencils) 76 Δ = laplace(g_1D, stencil_set)
72 @test Δ == second_derivative(g_1D, inner_stencil, closure_stencils, 1) 77 @test Δ == second_derivative(g_1D, stencil_set)
73 @test Δ isa LazyTensor{T,1,1} where T 78 @test Δ isa LazyTensor{Float64,1,1}
74 end 79 end
75 @testset "3D" begin 80 @testset "3D" begin
76 Δ = laplace(g_3D, inner_stencil, closure_stencils) 81 Δ = laplace(g_3D, stencil_set)
77 @test Δ isa LazyTensor{T,3,3} where T 82 @test Δ isa LazyTensor{Float64,3,3}
78 Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1) 83 Dxx = second_derivative(g_3D, stencil_set, 1)
79 Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2) 84 Dyy = second_derivative(g_3D, stencil_set, 2)
80 Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3) 85 Dzz = second_derivative(g_3D, stencil_set, 3)
81 @test Δ == Dxx + Dyy + Dzz 86 @test Δ == Dxx + Dyy + Dzz
82 @test Δ isa LazyTensor{T,3,3} where T 87 @test Δ isa LazyTensor{Float64,3,3}
83 end 88 end
84 end 89 end
85 90