comparison test/testSbpOperators.jl @ 675:1ce3a104afc8 feature/boundary_quads

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 07 Feb 2021 21:28:53 +0100
parents 538ccbaeb1f8 e14627e79a54
children 43cf58c69f91
comparison
equal deleted inserted replaced
670:538ccbaeb1f8 675:1ce3a104afc8
22 @test s isa Stencil{Float64, 5} 22 @test s isa Stencil{Float64, 5}
23 23
24 @test eltype(s) == Float64 24 @test eltype(s) == Float64
25 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.)) 25 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.))
26 26
27 @test Stencil((1,2,3,4), center=1) == Stencil((0, 3),(1,2,3,4)) 27 @test Stencil(1,2,3,4; center=1) == Stencil((0, 3),(1,2,3,4))
28 @test Stencil((1,2,3,4), center=2) == Stencil((-1, 2),(1,2,3,4)) 28 @test Stencil(1,2,3,4; center=2) == Stencil((-1, 2),(1,2,3,4))
29 @test Stencil((1,2,3,4), center=4) == Stencil((-3, 0),(1,2,3,4)) 29 @test Stencil(1,2,3,4; center=4) == Stencil((-3, 0),(1,2,3,4))
30
31 @test CenteredStencil(1,2,3,4,5) == Stencil((-2, 2), (1,2,3,4,5))
32 @test_throws ArgumentError CenteredStencil(1,2,3,4)
30 end 33 end
31 34
32 @testset "parse_rational" begin 35 @testset "parse_rational" begin
33 @test SbpOperators.parse_rational("1") isa Rational 36 @test SbpOperators.parse_rational("1") isa Rational
34 @test SbpOperators.parse_rational("1") == 1//1 37 @test SbpOperators.parse_rational("1") == 1//1
65 ] 68 ]
66 """ 69 """
67 70
68 parsed_toml = TOML.parse(toml_str) 71 parsed_toml = TOML.parse(toml_str)
69 @testset "get_stencil" begin 72 @testset "get_stencil" begin
70 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == Stencil((-1/2, 0., 1/2), center=2) 73 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == Stencil(-1/2, 0., 1/2, center=2)
71 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == Stencil((-1/2, 0., 1/2); center=1) 74 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == Stencil(-1/2, 0., 1/2; center=1)
72 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == Stencil((-1/2, 0., 1/2); center=3) 75 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == Stencil(-1/2, 0., 1/2; center=3)
73 76
74 @test get_stencil(parsed_toml, "order2", "H", "inner") == Stencil((1.,), center=1) 77 @test get_stencil(parsed_toml, "order2", "H", "inner") == Stencil(1.; center=1)
75 78
76 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type") 79 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type")
77 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils") 80 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils")
78 end 81 end
79 82
80 @testset "get_stencils" begin 83 @testset "get_stencils" begin
81 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (Stencil((-1., 1.), center=1),) 84 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (Stencil(-1., 1., center=1),)
82 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (Stencil((-1., 1.), center=2),) 85 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (Stencil(-1., 1., center=2),)
83 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (Stencil((-1., 1.), center=2),) 86 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (Stencil(-1., 1., center=2),)
84 87
85 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == ( 88 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == (
86 Stencil(( 2., -5., 4., -1., 0., 0.), center=1), 89 Stencil( 2., -5., 4., -1., 0., 0., center=1),
87 Stencil(( 1., -2., 1., 0., 0., 0.), center=1), 90 Stencil( 1., -2., 1., 0., 0., 0., center=1),
88 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=1), 91 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=1),
89 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1), 92 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1),
90 ) 93 )
91 94
92 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == ( 95 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == (
93 Stencil(( 2., -5., 4., -1., 0., 0.), center=4), 96 Stencil( 2., -5., 4., -1., 0., 0., center=4),
94 Stencil(( 1., -2., 1., 0., 0., 0.), center=2), 97 Stencil( 1., -2., 1., 0., 0., 0., center=2),
95 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3), 98 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3),
96 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1), 99 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1),
97 ) 100 )
98 101
99 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == ( 102 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == (
100 Stencil(( 2., -5., 4., -1., 0., 0.), center=1), 103 Stencil( 2., -5., 4., -1., 0., 0., center=1),
101 Stencil(( 1., -2., 1., 0., 0., 0.), center=2), 104 Stencil( 1., -2., 1., 0., 0., 0., center=2),
102 Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3), 105 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3),
103 Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=4), 106 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=4),
104 ) 107 )
105 108
106 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3)) 109 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3))
107 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4)) 110 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4))
108 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2)) 111 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2))
114 @test_throws AssertionError get_tuple(parsed_toml, "meta", "type") 117 @test_throws AssertionError get_tuple(parsed_toml, "meta", "type")
115 end 118 end
116 end 119 end
117 120
118 @testset "VolumeOperator" begin 121 @testset "VolumeOperator" begin
119 inner_stencil = Stencil(1/4 .* (1.,2.,1.),center=2) 122 inner_stencil = CenteredStencil(1/4, 2/4, 1/4)
120 closure_stencils = (Stencil(1/2 .* (1.,1.),center=1),Stencil((0.,1.),center=2)) 123 closure_stencils = (Stencil(1/2, 1/2; center=1), Stencil(0.,1.; center=2))
121 g_1D = EquidistantGrid(11,0.,1.) 124 g_1D = EquidistantGrid(11,0.,1.)
122 g_2D = EquidistantGrid((11,12),(0.,0.),(1.,1.)) 125 g_2D = EquidistantGrid((11,12),(0.,0.),(1.,1.))
123 g_3D = EquidistantGrid((11,12,10),(0.,0.,0.),(1.,1.,1.)) 126 g_3D = EquidistantGrid((11,12,10),(0.,0.,0.),(1.,1.,1.))
124 @testset "Constructors" begin 127 @testset "Constructors" begin
125 @testset "1D" begin 128 @testset "1D" begin
400 integral(H,v) = sum(H*v) 403 integral(H,v) = sum(H*v)
401 @testset "quadrature" begin 404 @testset "quadrature" begin
402 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 405 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
403 @testset "1D" begin 406 @testset "1D" begin
404 H = quadrature(g_1D,op.quadratureClosure) 407 H = quadrature(g_1D,op.quadratureClosure)
405 inner_stencil = Stencil((1.,),center=1) 408 inner_stencil = CenteredStencil(1.)
406 @test H == quadrature(g_1D,inner_stencil,op.quadratureClosure) 409 @test H == quadrature(g_1D,inner_stencil,op.quadratureClosure)
407 @test H isa TensorMapping{T,1,1} where T 410 @test H isa TensorMapping{T,1,1} where T
408 end 411 end
409 @testset "2D" begin 412 @testset "2D" begin
410 H = quadrature(g_2D,op.quadratureClosure) 413 H = quadrature(g_2D,op.quadratureClosure)
517 g_2D = EquidistantGrid((77,66), (0.0, 0.0), (Lx,Ly)) 520 g_2D = EquidistantGrid((77,66), (0.0, 0.0), (Lx,Ly))
518 @testset "Constructors" begin 521 @testset "Constructors" begin
519 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 522 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
520 @testset "1D" begin 523 @testset "1D" begin
521 Hi = InverseDiagonalQuadrature(g_1D, op.quadratureClosure); 524 Hi = InverseDiagonalQuadrature(g_1D, op.quadratureClosure);
522 inner_stencil = Stencil((1.,),center=1) 525 inner_stencil = CenteredStencil(1.)
523 closures = () 526 closures = ()
524 for i = 1:length(op.quadratureClosure) 527 for i = 1:length(op.quadratureClosure)
525 closures = (closures...,Stencil(op.quadratureClosure[i].range,1.0./op.quadratureClosure[i].weights)) 528 closures = (closures...,Stencil(op.quadratureClosure[i].range,1.0./op.quadratureClosure[i].weights))
526 end 529 end
527 @test Hi == InverseQuadrature(g_1D,inner_stencil,closures) 530 @test Hi == InverseQuadrature(g_1D,inner_stencil,closures)