comparison test/SbpOperators/volumeops/laplace/laplace_test.jl @ 751:f94feb005e7d feature/laplace_opset

Change from Dict to StaticDict in Laplace
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 19 Mar 2021 16:56:58 +0100
parents f88b2117dc69
children fc83d672be36
comparison
equal deleted inserted replaced
750:f88b2117dc69 751:f94feb005e7d
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 using Sbplib.RegionIndices 6 using Sbplib.RegionIndices
7 7 using Sbplib.StaticDicts
8 """
9 cmp_fields(s1,s2)
10
11 Compares the fields of two structs s1, s2, using the == operator.
12 """
13 function cmp_fields(s1::T,s2::T) where T
14 f = fieldnames(T)
15 return getfield.(Ref(s1),f) == getfield.(Ref(s2),f)
16 end
17 8
18 @testset "Laplace" begin 9 @testset "Laplace" begin
19 g_1D = EquidistantGrid(101, 0.0, 1.) 10 g_1D = EquidistantGrid(101, 0.0, 1.)
20 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) 11 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
21 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 12 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
29 20
30 (id_l, id_r) = boundary_identifiers(g_1D) 21 (id_l, id_r) = boundary_identifiers(g_1D)
31 22
32 e_l = boundary_restriction(g_1D,op.eClosure,id_l) 23 e_l = boundary_restriction(g_1D,op.eClosure,id_l)
33 e_r = boundary_restriction(g_1D,op.eClosure,id_r) 24 e_r = boundary_restriction(g_1D,op.eClosure,id_r)
34 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r)) 25 e_dict = StaticDict(Pair(id_l,e_l),Pair(id_r,e_r))
35 26
36 d_l = normal_derivative(g_1D,op.dClosure,id_l) 27 d_l = normal_derivative(g_1D,op.dClosure,id_l)
37 d_r = normal_derivative(g_1D,op.dClosure,id_r) 28 d_r = normal_derivative(g_1D,op.dClosure,id_r)
38 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r)) 29 d_dict = StaticDict(Pair(id_l,d_l),Pair(id_r,d_r))
39 30
40 H_l = inner_product(boundary_grid(g_1D,id_l),op.quadratureClosure) 31 H_l = inner_product(boundary_grid(g_1D,id_l),op.quadratureClosure)
41 H_r = inner_product(boundary_grid(g_1D,id_r),op.quadratureClosure) 32 H_r = inner_product(boundary_grid(g_1D,id_r),op.quadratureClosure)
42 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r)) 33 Hb_dict = StaticDict(Pair(id_l,H_l),Pair(id_r,H_r))
43 34
44 L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) 35 L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4)
45 @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) 36 @test L == Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)
46 @test L isa TensorMapping{T,1,1} where T 37 @test L isa TensorMapping{T,1,1} where T
47 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) 38 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)
48 end 39 end
49 @testset "3D" begin 40 @testset "3D" begin
50 # Create all tensor mappings included in Laplace 41 # Create all tensor mappings included in Laplace
58 e_r = boundary_restriction(g_3D,op.eClosure,id_r) 49 e_r = boundary_restriction(g_3D,op.eClosure,id_r)
59 e_s = boundary_restriction(g_3D,op.eClosure,id_s) 50 e_s = boundary_restriction(g_3D,op.eClosure,id_s)
60 e_n = boundary_restriction(g_3D,op.eClosure,id_n) 51 e_n = boundary_restriction(g_3D,op.eClosure,id_n)
61 e_b = boundary_restriction(g_3D,op.eClosure,id_b) 52 e_b = boundary_restriction(g_3D,op.eClosure,id_b)
62 e_t = boundary_restriction(g_3D,op.eClosure,id_t) 53 e_t = boundary_restriction(g_3D,op.eClosure,id_t)
63 e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r), 54 e_dict = StaticDict(Pair(id_l,e_l),Pair(id_r,e_r),
64 Pair(id_s,e_s),Pair(id_n,e_n), 55 Pair(id_s,e_s),Pair(id_n,e_n),
65 Pair(id_b,e_b),Pair(id_t,e_t)) 56 Pair(id_b,e_b),Pair(id_t,e_t))
66 57
67 d_l = normal_derivative(g_3D,op.dClosure,id_l) 58 d_l = normal_derivative(g_3D,op.dClosure,id_l)
68 d_r = normal_derivative(g_3D,op.dClosure,id_r) 59 d_r = normal_derivative(g_3D,op.dClosure,id_r)
69 d_s = normal_derivative(g_3D,op.dClosure,id_s) 60 d_s = normal_derivative(g_3D,op.dClosure,id_s)
70 d_n = normal_derivative(g_3D,op.dClosure,id_n) 61 d_n = normal_derivative(g_3D,op.dClosure,id_n)
71 d_b = normal_derivative(g_3D,op.dClosure,id_b) 62 d_b = normal_derivative(g_3D,op.dClosure,id_b)
72 d_t = normal_derivative(g_3D,op.dClosure,id_t) 63 d_t = normal_derivative(g_3D,op.dClosure,id_t)
73 d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r), 64 d_dict = StaticDict(Pair(id_l,d_l),Pair(id_r,d_r),
74 Pair(id_s,d_s),Pair(id_n,d_n), 65 Pair(id_s,d_s),Pair(id_n,d_n),
75 Pair(id_b,d_b),Pair(id_t,d_t)) 66 Pair(id_b,d_b),Pair(id_t,d_t))
76 67
77 H_l = inner_product(boundary_grid(g_3D,id_l),op.quadratureClosure) 68 H_l = inner_product(boundary_grid(g_3D,id_l),op.quadratureClosure)
78 H_r = inner_product(boundary_grid(g_3D,id_r),op.quadratureClosure) 69 H_r = inner_product(boundary_grid(g_3D,id_r),op.quadratureClosure)
79 H_s = inner_product(boundary_grid(g_3D,id_s),op.quadratureClosure) 70 H_s = inner_product(boundary_grid(g_3D,id_s),op.quadratureClosure)
80 H_n = inner_product(boundary_grid(g_3D,id_n),op.quadratureClosure) 71 H_n = inner_product(boundary_grid(g_3D,id_n),op.quadratureClosure)
81 H_b = inner_product(boundary_grid(g_3D,id_b),op.quadratureClosure) 72 H_b = inner_product(boundary_grid(g_3D,id_b),op.quadratureClosure)
82 H_t = inner_product(boundary_grid(g_3D,id_t),op.quadratureClosure) 73 H_t = inner_product(boundary_grid(g_3D,id_t),op.quadratureClosure)
83 Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r), 74 Hb_dict = StaticDict(Pair(id_l,H_l),Pair(id_r,H_r),
84 Pair(id_s,H_s),Pair(id_n,H_n), 75 Pair(id_s,H_s),Pair(id_n,H_n),
85 Pair(id_b,H_b),Pair(id_t,H_t)) 76 Pair(id_b,H_b),Pair(id_t,H_t))
86 77
87 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) 78 L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4)
88 @test cmp_fields(L,Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)) 79 @test L == Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)
89 @test L isa TensorMapping{T,3,3} where T 80 @test L isa TensorMapping{T,3,3} where T
90 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict) 81 @inferred Laplace(Δ,H,Hi,e_dict,d_dict,Hb_dict)
91 end 82 end
92 end 83 end
93 84