comparison test/testSbpOperators.jl @ 385:6ef73611f4d9 refactor/sbp_operators_tests/collect_and_compare

Replace tolerance variables with actual values. I think this reads clearer and also allows tweaking the tolerances per test.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 01 Oct 2020 06:20:30 +0200
parents 3a779c31e59e
children 4686c3509b54
comparison
equal deleted inserted replaced
384:3a779c31e59e 385:6ef73611f4d9
56 @test Dₓₓ' isa TensorMapping{T,1,1} where T 56 @test Dₓₓ' isa TensorMapping{T,1,1} where T
57 57
58 # TODO: Should perhaps set tolerance level for isapporx instead? 58 # TODO: Should perhaps set tolerance level for isapporx instead?
59 # Are these tolerance levels resonable or should tests be constructed 59 # Are these tolerance levels resonable or should tests be constructed
60 # differently? 60 # differently?
61 equalitytol = 0.5*1e-10
62 accuracytol = 0.5*1e-3
63 # 4th order interior stencil, 2nd order boundary stencil, 61 # 4th order interior stencil, 2nd order boundary stencil,
64 # implies that L*v should be exact for v - monomial up to order 3. 62 # 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 63 # Exact differentiation is measured point-wise. For other grid functions
66 # the error is measured in the l2-norm. 64 # the error is measured in the l2-norm.
67 @test all(abs.(Dₓₓ*v0) .<= equalitytol) 65 @test all(abs.(Dₓₓ*v0) .<= 5e-11)
68 @test all(abs.(Dₓₓ*v1) .<= equalitytol) 66 @test all(abs.(Dₓₓ*v1) .<= 5e-11)
69 @test all(abs.((Dₓₓ*v2 - v0)) .<= equalitytol) 67 @test all(abs.((Dₓₓ*v2 - v0)) .<= 5e-11)
70 @test all(abs.((Dₓₓ*v3 - v1)) .<= equalitytol) 68 @test all(abs.((Dₓₓ*v3 - v1)) .<= 5e-11)
71 e4 = Dₓₓ*v4 - v2 69 e4 = Dₓₓ*v4 - v2
72 e5 = Dₓₓ*v5 + v5 70 e5 = Dₓₓ*v5 + v5
73 @test sqrt(h*sum(e4.^2)) <= accuracytol 71 @test sqrt(h*sum(e4.^2)) <= 5e-4
74 @test sqrt(h*sum(e5.^2)) <= accuracytol 72 @test sqrt(h*sum(e5.^2)) <= 5e-4
75 end 73 end
76 74
77 @testset "Laplace2D" begin 75 @testset "Laplace2D" begin
78 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 76 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
79 Lx = 1.5 77 Lx = 1.5
102 @test L' isa TensorMapping{T,2,2} where T 100 @test L' isa TensorMapping{T,2,2} where T
103 101
104 # TODO: Should perhaps set tolerance level for isapporx instead? 102 # TODO: Should perhaps set tolerance level for isapporx instead?
105 # Are these tolerance levels resonable or should tests be constructed 103 # Are these tolerance levels resonable or should tests be constructed
106 # differently? 104 # differently?
107 equalitytol = 5e-11
108 accuracytol = 5e-4
109 # 4th order interior stencil, 2nd order boundary stencil, 105 # 4th order interior stencil, 2nd order boundary stencil,
110 # implies that L*v should be exact for v - monomial up to order 3. 106 # 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 107 # Exact differentiation is measured point-wise. For other grid functions
112 # the error is measured in the H-norm. 108 # the error is measured in the H-norm.
113 @test all(abs.(L*v0) .<= equalitytol) 109 @test all(abs.(L*v0) .<= 5e-11)
114 @test all(abs.(L*v1) .<= equalitytol) 110 @test all(abs.(L*v1) .<= 5e-11)
115 @test all(L*v2 .≈ v0) # Seems to be more accurate 111 @test all(L*v2 .≈ v0) # Seems to be more accurate
116 @test all(abs.((L*v3 - v1)) .<= equalitytol) 112 @test all(abs.((L*v3 - v1)) .<= 5e-11)
117 e4 = L*v4 - v2 113 e4 = L*v4 - v2
118 e5 = L*v5 - v5ₓₓ 114 e5 = L*v5 - v5ₓₓ
119 115
120 h = spacing(g) 116 h = spacing(g)
121 @test sqrt(prod(h)*sum(e4.^2)) <= accuracytol 117 @test sqrt(prod(h)*sum(e4.^2)) <= 5e-4
122 @test sqrt(prod(h)*sum(e5.^2)) <= accuracytol 118 @test sqrt(prod(h)*sum(e5.^2)) <= 5e-4
123 end 119 end
124 120
125 @testset "DiagonalInnerProduct" begin 121 @testset "DiagonalInnerProduct" begin
126 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 122 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
127 L = 2.3 123 L = 2.3