comparison test/DiffOps/DiffOps_test.jl @ 745:6dd9f97fc2be

Merge in feature/selectable_tests.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 17 Mar 2021 22:21:01 +0100
parents 11a444d6fc93
children 1ba8a398af9c
comparison
equal deleted inserted replaced
718:05d8ea88c690 745:6dd9f97fc2be
1 using Test
2 using Sbplib.DiffOps
3 using Sbplib.Grids
4 using Sbplib.SbpOperators
5 using Sbplib.RegionIndices
6 using Sbplib.LazyTensors
7
8 #
9 # @testset "BoundaryValue" begin
10 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
11 # g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0))
12 #
13 # e_w = BoundaryValue(op, g, CartesianBoundary{1,Lower}())
14 # e_e = BoundaryValue(op, g, CartesianBoundary{1,Upper}())
15 # e_s = BoundaryValue(op, g, CartesianBoundary{2,Lower}())
16 # e_n = BoundaryValue(op, g, CartesianBoundary{2,Upper}())
17 #
18 # v = zeros(Float64, 4, 5)
19 # v[:,5] = [1, 2, 3,4]
20 # v[:,4] = [1, 2, 3,4]
21 # v[:,3] = [4, 5, 6, 7]
22 # v[:,2] = [7, 8, 9, 10]
23 # v[:,1] = [10, 11, 12, 13]
24 #
25 # @test e_w isa TensorMapping{T,2,1} where T
26 # @test e_w' isa TensorMapping{T,1,2} where T
27 #
28 # @test domain_size(e_w, (3,2)) == (2,)
29 # @test domain_size(e_e, (3,2)) == (2,)
30 # @test domain_size(e_s, (3,2)) == (3,)
31 # @test domain_size(e_n, (3,2)) == (3,)
32 #
33 # @test size(e_w'*v) == (5,)
34 # @test size(e_e'*v) == (5,)
35 # @test size(e_s'*v) == (4,)
36 # @test size(e_n'*v) == (4,)
37 #
38 # @test collect(e_w'*v) == [10,7,4,1.0,1]
39 # @test collect(e_e'*v) == [13,10,7,4,4.0]
40 # @test collect(e_s'*v) == [10,11,12,13.0]
41 # @test collect(e_n'*v) == [1,2,3,4.0]
42 #
43 # g_x = [1,2,3,4.0]
44 # g_y = [5,4,3,2,1.0]
45 #
46 # G_w = zeros(Float64, (4,5))
47 # G_w[1,:] = g_y
48 #
49 # G_e = zeros(Float64, (4,5))
50 # G_e[4,:] = g_y
51 #
52 # G_s = zeros(Float64, (4,5))
53 # G_s[:,1] = g_x
54 #
55 # G_n = zeros(Float64, (4,5))
56 # G_n[:,5] = g_x
57 #
58 # @test size(e_w*g_y) == (UnknownDim,5)
59 # @test size(e_e*g_y) == (UnknownDim,5)
60 # @test size(e_s*g_x) == (4,UnknownDim)
61 # @test size(e_n*g_x) == (4,UnknownDim)
62 #
63 # # These tests should be moved to where they are possible (i.e we know what the grid should be)
64 # @test_broken collect(e_w*g_y) == G_w
65 # @test_broken collect(e_e*g_y) == G_e
66 # @test_broken collect(e_s*g_x) == G_s
67 # @test_broken collect(e_n*g_x) == G_n
68 # end
69 #
70 # @testset "NormalDerivative" begin
71 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
72 # g = EquidistantGrid((5,6), (0.0, 0.0), (4.0,5.0))
73 #
74 # d_w = NormalDerivative(op, g, CartesianBoundary{1,Lower}())
75 # d_e = NormalDerivative(op, g, CartesianBoundary{1,Upper}())
76 # d_s = NormalDerivative(op, g, CartesianBoundary{2,Lower}())
77 # d_n = NormalDerivative(op, g, CartesianBoundary{2,Upper}())
78 #
79 #
80 # v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y)
81 # v∂x = evalOn(g, (x,y)-> 2*x + y)
82 # v∂y = evalOn(g, (x,y)-> 2*(y-1) + x)
83 #
84 # @test d_w isa TensorMapping{T,2,1} where T
85 # @test d_w' isa TensorMapping{T,1,2} where T
86 #
87 # @test domain_size(d_w, (3,2)) == (2,)
88 # @test domain_size(d_e, (3,2)) == (2,)
89 # @test domain_size(d_s, (3,2)) == (3,)
90 # @test domain_size(d_n, (3,2)) == (3,)
91 #
92 # @test size(d_w'*v) == (6,)
93 # @test size(d_e'*v) == (6,)
94 # @test size(d_s'*v) == (5,)
95 # @test size(d_n'*v) == (5,)
96 #
97 # @test collect(d_w'*v) ≈ v∂x[1,:]
98 # @test collect(d_e'*v) ≈ v∂x[5,:]
99 # @test collect(d_s'*v) ≈ v∂y[:,1]
100 # @test collect(d_n'*v) ≈ v∂y[:,6]
101 #
102 #
103 # d_x_l = zeros(Float64, 5)
104 # d_x_u = zeros(Float64, 5)
105 # for i ∈ eachindex(d_x_l)
106 # d_x_l[i] = op.dClosure[i-1]
107 # d_x_u[i] = -op.dClosure[length(d_x_u)-i]
108 # end
109 #
110 # d_y_l = zeros(Float64, 6)
111 # d_y_u = zeros(Float64, 6)
112 # for i ∈ eachindex(d_y_l)
113 # d_y_l[i] = op.dClosure[i-1]
114 # d_y_u[i] = -op.dClosure[length(d_y_u)-i]
115 # end
116 #
117 # function prod_matrix(x,y)
118 # G = zeros(Float64, length(x), length(y))
119 # for I ∈ CartesianIndices(G)
120 # G[I] = x[I[1]]*y[I[2]]
121 # end
122 #
123 # return G
124 # end
125 #
126 # g_x = [1,2,3,4.0,5]
127 # g_y = [5,4,3,2,1.0,11]
128 #
129 # G_w = prod_matrix(d_x_l, g_y)
130 # G_e = prod_matrix(d_x_u, g_y)
131 # G_s = prod_matrix(g_x, d_y_l)
132 # G_n = prod_matrix(g_x, d_y_u)
133 #
134 #
135 # @test size(d_w*g_y) == (UnknownDim,6)
136 # @test size(d_e*g_y) == (UnknownDim,6)
137 # @test size(d_s*g_x) == (5,UnknownDim)
138 # @test size(d_n*g_x) == (5,UnknownDim)
139 #
140 # # These tests should be moved to where they are possible (i.e we know what the grid should be)
141 # @test_broken collect(d_w*g_y) ≈ G_w
142 # @test_broken collect(d_e*g_y) ≈ G_e
143 # @test_broken collect(d_s*g_x) ≈ G_s
144 # @test_broken collect(d_n*g_x) ≈ G_n
145 # end
146 #
147 # @testset "BoundaryQuadrature" begin
148 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
149 # g = EquidistantGrid((10,11), (0.0, 0.0), (1.0,1.0))
150 #
151 # H_w = BoundaryQuadrature(op, g, CartesianBoundary{1,Lower}())
152 # H_e = BoundaryQuadrature(op, g, CartesianBoundary{1,Upper}())
153 # H_s = BoundaryQuadrature(op, g, CartesianBoundary{2,Lower}())
154 # H_n = BoundaryQuadrature(op, g, CartesianBoundary{2,Upper}())
155 #
156 # v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y)
157 #
158 # function get_quadrature(N)
159 # qc = op.quadratureClosure
160 # q = (qc..., ones(N-2*closuresize(op))..., reverse(qc)...)
161 # @assert length(q) == N
162 # return q
163 # end
164 #
165 # v_w = v[1,:]
166 # v_e = v[10,:]
167 # v_s = v[:,1]
168 # v_n = v[:,11]
169 #
170 # q_x = spacing(g)[1].*get_quadrature(10)
171 # q_y = spacing(g)[2].*get_quadrature(11)
172 #
173 # @test H_w isa TensorOperator{T,1} where T
174 #
175 # @test domain_size(H_w, (3,)) == (3,)
176 # @test domain_size(H_n, (3,)) == (3,)
177 #
178 # @test range_size(H_w, (3,)) == (3,)
179 # @test range_size(H_n, (3,)) == (3,)
180 #
181 # @test size(H_w*v_w) == (11,)
182 # @test size(H_e*v_e) == (11,)
183 # @test size(H_s*v_s) == (10,)
184 # @test size(H_n*v_n) == (10,)
185 #
186 # @test collect(H_w*v_w) ≈ q_y.*v_w
187 # @test collect(H_e*v_e) ≈ q_y.*v_e
188 # @test collect(H_s*v_s) ≈ q_x.*v_s
189 # @test collect(H_n*v_n) ≈ q_x.*v_n
190 #
191 # @test collect(H_w'*v_w) == collect(H_w'*v_w)
192 # @test collect(H_e'*v_e) == collect(H_e'*v_e)
193 # @test collect(H_s'*v_s) == collect(H_s'*v_s)
194 # @test collect(H_n'*v_n) == collect(H_n'*v_n)
195 # end