Mercurial > repos > public > sbplib_julia
comparison test/testSbpOperators.jl @ 383:aaf8e331cb80 refactor/sbp_operators_tests/collect_and_compare
Remove collects around TensorMappingApplications
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 Oct 2020 06:11:40 +0200 |
parents | 5c10cd0ed1fe |
children | 3a779c31e59e |
comparison
equal
deleted
inserted
replaced
382:5c10cd0ed1fe | 383:aaf8e331cb80 |
---|---|
62 accuracytol = 0.5*1e-3 | 62 accuracytol = 0.5*1e-3 |
63 # 4th order interior stencil, 2nd order boundary stencil, | 63 # 4th order interior stencil, 2nd order boundary stencil, |
64 # implies that L*v should be exact for v - monomial up to order 3. | 64 # implies that L*v should be exact for v - monomial up to order 3. |
65 # Exact differentiation is measured point-wise. For other grid functions | 65 # Exact differentiation is measured point-wise. For other grid functions |
66 # the error is measured in the l2-norm. | 66 # the error is measured in the l2-norm. |
67 @test all(abs.(collect(Dₓₓ*v0)) .<= equalitytol) | 67 @test all(abs.(Dₓₓ*v0) .<= equalitytol) |
68 @test all(abs.(collect(Dₓₓ*v1)) .<= equalitytol) | 68 @test all(abs.(Dₓₓ*v1) .<= equalitytol) |
69 @test all(abs.((collect(Dₓₓ*v2) - v0)) .<= equalitytol) | 69 @test all(abs.((Dₓₓ*v2 - v0)) .<= equalitytol) |
70 @test all(abs.((collect(Dₓₓ*v3) - v1)) .<= equalitytol) | 70 @test all(abs.((Dₓₓ*v3 - v1)) .<= equalitytol) |
71 e4 = collect(Dₓₓ*v4) - v2 | 71 e4 = Dₓₓ*v4 - v2 |
72 e5 = collect(Dₓₓ*v5) + v5 | 72 e5 = Dₓₓ*v5 + v5 |
73 @test sqrt(h*sum(collect(e4.^2))) <= accuracytol | 73 @test sqrt(h*sum(e4.^2)) <= accuracytol |
74 @test sqrt(h*sum(collect(e5.^2))) <= accuracytol | 74 @test sqrt(h*sum(e5.^2)) <= accuracytol |
75 end | 75 end |
76 | 76 |
77 @testset "Laplace2D" begin | 77 @testset "Laplace2D" begin |
78 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 78 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
79 Lx = 1.5 | 79 Lx = 1.5 |
108 accuracytol = 0.5*1e-3 | 108 accuracytol = 0.5*1e-3 |
109 # 4th order interior stencil, 2nd order boundary stencil, | 109 # 4th order interior stencil, 2nd order boundary stencil, |
110 # implies that L*v should be exact for v - monomial up to order 3. | 110 # implies that L*v should be exact for v - monomial up to order 3. |
111 # Exact differentiation is measured point-wise. For other grid functions | 111 # Exact differentiation is measured point-wise. For other grid functions |
112 # the error is measured in the H-norm. | 112 # the error is measured in the H-norm. |
113 @test all(abs.(collect(L*v0)) .<= equalitytol) | 113 @test all(abs.(L*v0) .<= equalitytol) |
114 @test all(abs.(collect(L*v1)) .<= equalitytol) | 114 @test all(abs.(L*v1) .<= equalitytol) |
115 @test all(collect(L*v2) .≈ v0) # Seems to be more accurate | 115 @test all(L*v2 .≈ v0) # Seems to be more accurate |
116 @test all(abs.((collect(L*v3) - v1)) .<= equalitytol) | 116 @test all(abs.((L*v3 - v1)) .<= equalitytol) |
117 e4 = collect(L*v4) - v2 | 117 e4 = L*v4 - v2 |
118 e5 = collect(L*v5) - v5ₓₓ | 118 e5 = L*v5 - v5ₓₓ |
119 | 119 |
120 h = spacing(g) | 120 h = spacing(g) |
121 @test sqrt(prod(h)*sum(collect(e4.^2))) <= accuracytol | 121 @test sqrt(prod(h)*sum(e4.^2)) <= accuracytol |
122 @test sqrt(prod(h)*sum(collect(e5.^2))) <= accuracytol | 122 @test sqrt(prod(h)*sum(e5.^2)) <= accuracytol |
123 end | 123 end |
124 | 124 |
125 @testset "DiagonalInnerProduct" begin | 125 @testset "DiagonalInnerProduct" begin |
126 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 126 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
127 L = 2.3 | 127 L = 2.3 |
129 H = DiagonalInnerProduct(g,op.quadratureClosure) | 129 H = DiagonalInnerProduct(g,op.quadratureClosure) |
130 v = ones(Float64, size(g)) | 130 v = ones(Float64, size(g)) |
131 | 131 |
132 @test H isa TensorMapping{T,1,1} where T | 132 @test H isa TensorMapping{T,1,1} where T |
133 @test H' isa TensorMapping{T,1,1} where T | 133 @test H' isa TensorMapping{T,1,1} where T |
134 @test sum(collect(H*v)) ≈ L | 134 @test sum(H*v) ≈ L |
135 @test collect(H*v) == collect(H'*v) | 135 @test H*v == H'*v |
136 end | 136 end |
137 | 137 |
138 @testset "Quadrature" begin | 138 @testset "Quadrature" begin |
139 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 139 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
140 Lx = 2.3 | 140 Lx = 2.3 |
163 Hi = InverseDiagonalInnerProduct(g,op.quadratureClosure) | 163 Hi = InverseDiagonalInnerProduct(g,op.quadratureClosure) |
164 v = evalOn(g, x->sin(x)) | 164 v = evalOn(g, x->sin(x)) |
165 | 165 |
166 @test Hi isa TensorMapping{T,1,1} where T | 166 @test Hi isa TensorMapping{T,1,1} where T |
167 @test Hi' isa TensorMapping{T,1,1} where T | 167 @test Hi' isa TensorMapping{T,1,1} where T |
168 @test collect(Hi*H*v) ≈ v | 168 @test Hi*H*v ≈ v |
169 @test collect(Hi*v) == collect(Hi'*v) | 169 @test Hi*v == Hi'*v |
170 end | 170 end |
171 | 171 |
172 @testset "InverseQuadrature" begin | 172 @testset "InverseQuadrature" begin |
173 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 173 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
174 Lx = 7.3 | 174 Lx = 7.3 |
179 Qinv = InverseQuadrature(g, op.quadratureClosure) | 179 Qinv = InverseQuadrature(g, op.quadratureClosure) |
180 v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y) | 180 v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y) |
181 | 181 |
182 @test Qinv isa TensorMapping{T,2,2} where T | 182 @test Qinv isa TensorMapping{T,2,2} where T |
183 @test Qinv' isa TensorMapping{T,2,2} where T | 183 @test Qinv' isa TensorMapping{T,2,2} where T |
184 @test_broken collect(Qinv*(Q*v)) ≈ v | 184 @test_broken Qinv*(Q*v) ≈ v |
185 @test collect(Qinv*v) == collect(Qinv'*v) | 185 @test Qinv*v == Qinv'*v |
186 end | 186 end |
187 # | 187 # |
188 # @testset "BoundaryValue" begin | 188 # @testset "BoundaryValue" begin |
189 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 189 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
190 # g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0)) | 190 # g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0)) |
212 # @test size(e_w'*v) == (5,) | 212 # @test size(e_w'*v) == (5,) |
213 # @test size(e_e'*v) == (5,) | 213 # @test size(e_e'*v) == (5,) |
214 # @test size(e_s'*v) == (4,) | 214 # @test size(e_s'*v) == (4,) |
215 # @test size(e_n'*v) == (4,) | 215 # @test size(e_n'*v) == (4,) |
216 # | 216 # |
217 # @test collect(e_w'*v) == [10,7,4,1.0,1] | 217 # @test e_w'*v == [10,7,4,1.0,1] |
218 # @test collect(e_e'*v) == [13,10,7,4,4.0] | 218 # @test e_e'*v == [13,10,7,4,4.0] |
219 # @test collect(e_s'*v) == [10,11,12,13.0] | 219 # @test e_s'*v == [10,11,12,13.0] |
220 # @test collect(e_n'*v) == [1,2,3,4.0] | 220 # @test e_n'*v == [1,2,3,4.0] |
221 # | 221 # |
222 # g_x = [1,2,3,4.0] | 222 # g_x = [1,2,3,4.0] |
223 # g_y = [5,4,3,2,1.0] | 223 # g_y = [5,4,3,2,1.0] |
224 # | 224 # |
225 # G_w = zeros(Float64, (4,5)) | 225 # G_w = zeros(Float64, (4,5)) |
238 # @test size(e_e*g_y) == (UnknownDim,5) | 238 # @test size(e_e*g_y) == (UnknownDim,5) |
239 # @test size(e_s*g_x) == (4,UnknownDim) | 239 # @test size(e_s*g_x) == (4,UnknownDim) |
240 # @test size(e_n*g_x) == (4,UnknownDim) | 240 # @test size(e_n*g_x) == (4,UnknownDim) |
241 # | 241 # |
242 # # These tests should be moved to where they are possible (i.e we know what the grid should be) | 242 # # These tests should be moved to where they are possible (i.e we know what the grid should be) |
243 # @test_broken collect(e_w*g_y) == G_w | 243 # @test_broken e_w*g_y == G_w |
244 # @test_broken collect(e_e*g_y) == G_e | 244 # @test_broken e_e*g_y == G_e |
245 # @test_broken collect(e_s*g_x) == G_s | 245 # @test_broken e_s*g_x == G_s |
246 # @test_broken collect(e_n*g_x) == G_n | 246 # @test_broken e_n*g_x == G_n |
247 # end | 247 # end |
248 # | 248 # |
249 # @testset "NormalDerivative" begin | 249 # @testset "NormalDerivative" begin |
250 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 250 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
251 # g = EquidistantGrid((5,6), (0.0, 0.0), (4.0,5.0)) | 251 # g = EquidistantGrid((5,6), (0.0, 0.0), (4.0,5.0)) |
271 # @test size(d_w'*v) == (6,) | 271 # @test size(d_w'*v) == (6,) |
272 # @test size(d_e'*v) == (6,) | 272 # @test size(d_e'*v) == (6,) |
273 # @test size(d_s'*v) == (5,) | 273 # @test size(d_s'*v) == (5,) |
274 # @test size(d_n'*v) == (5,) | 274 # @test size(d_n'*v) == (5,) |
275 # | 275 # |
276 # @test collect(d_w'*v) ≈ v∂x[1,:] | 276 # @test d_w'*v ≈ v∂x[1,:] |
277 # @test collect(d_e'*v) ≈ v∂x[5,:] | 277 # @test d_e'*v ≈ v∂x[5,:] |
278 # @test collect(d_s'*v) ≈ v∂y[:,1] | 278 # @test d_s'*v ≈ v∂y[:,1] |
279 # @test collect(d_n'*v) ≈ v∂y[:,6] | 279 # @test d_n'*v ≈ v∂y[:,6] |
280 # | 280 # |
281 # | 281 # |
282 # d_x_l = zeros(Float64, 5) | 282 # d_x_l = zeros(Float64, 5) |
283 # d_x_u = zeros(Float64, 5) | 283 # d_x_u = zeros(Float64, 5) |
284 # for i ∈ eachindex(d_x_l) | 284 # for i ∈ eachindex(d_x_l) |
315 # @test size(d_e*g_y) == (UnknownDim,6) | 315 # @test size(d_e*g_y) == (UnknownDim,6) |
316 # @test size(d_s*g_x) == (5,UnknownDim) | 316 # @test size(d_s*g_x) == (5,UnknownDim) |
317 # @test size(d_n*g_x) == (5,UnknownDim) | 317 # @test size(d_n*g_x) == (5,UnknownDim) |
318 # | 318 # |
319 # # These tests should be moved to where they are possible (i.e we know what the grid should be) | 319 # # These tests should be moved to where they are possible (i.e we know what the grid should be) |
320 # @test_broken collect(d_w*g_y) ≈ G_w | 320 # @test_broken d_w*g_y ≈ G_w |
321 # @test_broken collect(d_e*g_y) ≈ G_e | 321 # @test_broken d_e*g_y ≈ G_e |
322 # @test_broken collect(d_s*g_x) ≈ G_s | 322 # @test_broken d_s*g_x ≈ G_s |
323 # @test_broken collect(d_n*g_x) ≈ G_n | 323 # @test_broken d_n*g_x ≈ G_n |
324 # end | 324 # end |
325 # | 325 # |
326 # @testset "BoundaryQuadrature" begin | 326 # @testset "BoundaryQuadrature" begin |
327 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") | 327 # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") |
328 # g = EquidistantGrid((10,11), (0.0, 0.0), (1.0,1.0)) | 328 # g = EquidistantGrid((10,11), (0.0, 0.0), (1.0,1.0)) |
360 # @test size(H_w*v_w) == (11,) | 360 # @test size(H_w*v_w) == (11,) |
361 # @test size(H_e*v_e) == (11,) | 361 # @test size(H_e*v_e) == (11,) |
362 # @test size(H_s*v_s) == (10,) | 362 # @test size(H_s*v_s) == (10,) |
363 # @test size(H_n*v_n) == (10,) | 363 # @test size(H_n*v_n) == (10,) |
364 # | 364 # |
365 # @test collect(H_w*v_w) ≈ q_y.*v_w | 365 # @test H_w*v_w ≈ q_y.*v_w |
366 # @test collect(H_e*v_e) ≈ q_y.*v_e | 366 # @test H_e*v_e ≈ q_y.*v_e |
367 # @test collect(H_s*v_s) ≈ q_x.*v_s | 367 # @test H_s*v_s ≈ q_x.*v_s |
368 # @test collect(H_n*v_n) ≈ q_x.*v_n | 368 # @test H_n*v_n ≈ q_x.*v_n |
369 # | 369 # |
370 # @test collect(H_w'*v_w) == collect(H_w'*v_w) | 370 # @test H_w'*v_w == H_w'*v_w |
371 # @test collect(H_e'*v_e) == collect(H_e'*v_e) | 371 # @test H_e'*v_e == H_e'*v_e |
372 # @test collect(H_s'*v_s) == collect(H_s'*v_s) | 372 # @test H_s'*v_s == H_s'*v_s |
373 # @test collect(H_n'*v_n) == collect(H_n'*v_n) | 373 # @test H_n'*v_n == H_n'*v_n |
374 # end | 374 # end |
375 | 375 |
376 end | 376 end |