comparison test/testSbpOperators.jl @ 604:6901d5375311 refactor/toml_operator_format

Add tests for get_stencil, get_stencils and get_tuple
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 05 Dec 2020 13:51:11 +0100
parents 03ef4d4740ab
children 8fcf9c9afb30
comparison
equal deleted inserted replaced
602:c2239c7cd71e 604:6901d5375311
2 using Sbplib.SbpOperators 2 using Sbplib.SbpOperators
3 using Sbplib.Grids 3 using Sbplib.Grids
4 using Sbplib.RegionIndices 4 using Sbplib.RegionIndices
5 using Sbplib.LazyTensors 5 using Sbplib.LazyTensors
6 using LinearAlgebra 6 using LinearAlgebra
7 using TOML
7 8
8 @testset "SbpOperators" begin 9 @testset "SbpOperators" begin
9 10
10 @testset "Stencil" begin 11 @testset "Stencil" begin
11 s = SbpOperators.Stencil((-2,2), (1.,2.,2.,3.,4.)) 12 s = SbpOperators.Stencil((-2,2), (1.,2.,2.,3.,4.))
15 @test SbpOperators.scale(s, 2) == SbpOperators.Stencil((-2,2), (2.,4.,4.,6.,8.)) 16 @test SbpOperators.scale(s, 2) == SbpOperators.Stencil((-2,2), (2.,4.,4.,6.,8.))
16 17
17 @test SbpOperators.Stencil((1,2,3,4), center=1) == SbpOperators.Stencil((0, 3),(1,2,3,4)) 18 @test SbpOperators.Stencil((1,2,3,4), center=1) == SbpOperators.Stencil((0, 3),(1,2,3,4))
18 @test SbpOperators.Stencil((1,2,3,4), center=2) == SbpOperators.Stencil((-1, 2),(1,2,3,4)) 19 @test SbpOperators.Stencil((1,2,3,4), center=2) == SbpOperators.Stencil((-1, 2),(1,2,3,4))
19 @test SbpOperators.Stencil((1,2,3,4), center=4) == SbpOperators.Stencil((-3, 0),(1,2,3,4)) 20 @test SbpOperators.Stencil((1,2,3,4), center=4) == SbpOperators.Stencil((-3, 0),(1,2,3,4))
21 end
22
23 @testset "readoperator" begin
24 toml_str = """
25 [meta]
26 type = "equidistant"
27
28 [order2]
29 H.inner = ["1"]
30
31 D1.inner_stencil = ["-1/2", "0", "1/2"]
32 D1.closure_stencils = [
33 ["-1", "1"],
34 ]
35
36 d1.closure = ["-3/2", "2", "-1/2"]
37
38 [order4]
39 H.closure = ["17/48", "59/48", "43/48", "49/48"]
40
41 D2.inner_stencil = ["-1/12","4/3","-5/2","4/3","-1/12"]
42 D2.closure_stencils = [
43 [ "2", "-5", "4", "-1", "0", "0"],
44 [ "1", "-2", "1", "0", "0", "0"],
45 [ "-4/43", "59/43", "-110/43", "59/43", "-4/43", "0"],
46 [ "-1/49", "0", "59/49", "-118/49", "64/49", "-4/49"],
47 ]
48 """
49
50 parsed_toml = TOML.parse(toml_str)
51 @testset "get_stencil" begin
52 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == SbpOperators.Stencil((-1/2, 0., 1/2), center=2)
53 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == SbpOperators.Stencil((-1/2, 0., 1/2); center=1)
54 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == SbpOperators.Stencil((-1/2, 0., 1/2); center=3)
55
56 @test get_stencil(parsed_toml, "order2", "H", "inner") == SbpOperators.Stencil((1.,), center=1)
57
58 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type")
59 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils")
60 end
61
62 @testset "get_stencils" begin
63 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (SbpOperators.Stencil((-1., 1.), center=1),)
64 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (SbpOperators.Stencil((-1., 1.), center=2),)
65 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (SbpOperators.Stencil((-1., 1.), center=2),)
66
67 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == (
68 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=1),
69 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=1),
70 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=1),
71 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1),
72 )
73
74 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == (
75 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=4),
76 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=2),
77 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3),
78 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=1),
79 )
80
81 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == (
82 SbpOperators.Stencil(( 2., -5., 4., -1., 0., 0.), center=1),
83 SbpOperators.Stencil(( 1., -2., 1., 0., 0., 0.), center=2),
84 SbpOperators.Stencil(( -4/43, 59/43, -110/43, 59/43, -4/43, 0.), center=3),
85 SbpOperators.Stencil(( -1/49, 0., 59/49, -118/49, 64/49, -4/49), center=4),
86 )
87
88 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3))
89 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4))
90 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2))
91 end
92
93 @testset "get_tuple" begin
94 @test get_tuple(parsed_toml, "order2", "d1", "closure") == (-3/2, 2, -1/2)
95
96 @test_throws AssertionError get_tuple(parsed_toml, "meta", "type")
97 end
20 end 98 end
21 99
22 # @testset "apply_quadrature" begin 100 # @testset "apply_quadrature" begin
23 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) 101 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4)
24 # h = 0.5 102 # h = 0.5