comparison test/testSbpOperators.jl @ 388:5223872485cd refactor/sbp_operators_tests/collect_and_compare

Clean up grid creation
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 01 Oct 2020 08:16:46 +0200
parents 4686c3509b54
children 0433ab553d13
comparison
equal deleted inserted replaced
387:4686c3509b54 388:5223872485cd
30 # end 30 # end
31 31
32 @testset "SecondDerivative" begin 32 @testset "SecondDerivative" begin
33 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 33 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
34 L = 3.5 34 L = 3.5
35 g = EquidistantGrid((101,), (0.0,), (L,)) 35 g = EquidistantGrid(101, 0.0, L)
36 h_inv = inverse_spacing(g)
37 h = 1/h_inv[1];
38 Dₓₓ = SecondDerivative(g,op.innerStencil,op.closureStencils) 36 Dₓₓ = SecondDerivative(g,op.innerStencil,op.closureStencils)
39 37
40 f0(x::Float64) = 1. 38 f0(x::Float64) = 1.
41 f1(x::Float64) = x 39 f1(x::Float64) = x
42 f2(x::Float64) = 1/2*x^2 40 f2(x::Float64) = 1/2*x^2
64 # the error is measured in the l2-norm. 62 # the error is measured in the l2-norm.
65 @test_broken Dₓₓ*v0 ≈ 0.0 atol=5e-11 63 @test_broken Dₓₓ*v0 ≈ 0.0 atol=5e-11
66 @test_broken Dₓₓ*v1 ≈ 0.0 atol=5e-11 64 @test_broken Dₓₓ*v1 ≈ 0.0 atol=5e-11
67 @test Dₓₓ*v2 ≈ v0 atol=5e-11 65 @test Dₓₓ*v2 ≈ v0 atol=5e-11
68 @test Dₓₓ*v3 ≈ v1 atol=5e-11 66 @test Dₓₓ*v3 ≈ v1 atol=5e-11
67
69 e4 = Dₓₓ*v4 - v2 68 e4 = Dₓₓ*v4 - v2
70 e5 = Dₓₓ*v5 + v5 69 e5 = Dₓₓ*v5 + v5
70 h = spacing(g)[1];
71 @test sqrt(h*sum(e4.^2)) ≈ 0 atol=5e-4 71 @test sqrt(h*sum(e4.^2)) ≈ 0 atol=5e-4
72 @test sqrt(h*sum(e5.^2)) ≈ 0 atol=5e-4 72 @test sqrt(h*sum(e5.^2)) ≈ 0 atol=5e-4
73 end 73 end
74 74
75 75
117 end 117 end
118 118
119 @testset "DiagonalInnerProduct" begin 119 @testset "DiagonalInnerProduct" begin
120 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 120 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
121 L = 2.3 121 L = 2.3
122 g = EquidistantGrid((77,), (0.0,), (L,)) 122 g = EquidistantGrid(77, 0.0, L)
123 H = DiagonalInnerProduct(g,op.quadratureClosure) 123 H = DiagonalInnerProduct(g,op.quadratureClosure)
124 v = ones(Float64, size(g)) 124 v = ones(Float64, size(g))
125 125
126 @test H isa TensorMapping{T,1,1} where T 126 @test H isa TensorMapping{T,1,1} where T
127 @test H' isa TensorMapping{T,1,1} where T 127 @test H' isa TensorMapping{T,1,1} where T
150 end 150 end
151 151
152 @testset "InverseDiagonalInnerProduct" begin 152 @testset "InverseDiagonalInnerProduct" begin
153 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 153 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
154 L = 2.3 154 L = 2.3
155 g = EquidistantGrid((77,), (0.0,), (L,)) 155 g = EquidistantGrid(77, 0.0, L)
156 H = DiagonalInnerProduct(g, op.quadratureClosure) 156 H = DiagonalInnerProduct(g, op.quadratureClosure)
157 Hi = InverseDiagonalInnerProduct(g,op.quadratureClosure) 157 Hi = InverseDiagonalInnerProduct(g,op.quadratureClosure)
158 v = evalOn(g, x->sin(x)) 158 v = evalOn(g, x->sin(x))
159 159
160 @test Hi isa TensorMapping{T,1,1} where T 160 @test Hi isa TensorMapping{T,1,1} where T