comparison test/SbpOperators/readoperator_test.jl @ 769:0158c3fd521c operator_storage_array_of_table

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 15 Jul 2021 00:06:16 +0200
parents 6114274447f5
children 219c9661e700
comparison
equal deleted inserted replaced
768:7c87a33963c5 769:0158c3fd521c
1 using Test
2
3 using TOML
4 using Sbplib.SbpOperators
5
6 import Sbplib.SbpOperators.Stencil
7
8
9 @testset "parse_rational" begin
10 @test SbpOperators.parse_rational("1") isa Rational
11 @test SbpOperators.parse_rational("1") == 1//1
12 @test SbpOperators.parse_rational("1/2") isa Rational
13 @test SbpOperators.parse_rational("1/2") == 1//2
14 @test SbpOperators.parse_rational("37/13") isa Rational
15 @test SbpOperators.parse_rational("37/13") == 37//13
16 end
17
18 @testset "readoperator" begin
19 toml_str = """
20 [meta]
21 authors = "Ken Mattson"
22 description = "Standard operators for equidistant grids"
23 type = "equidistant"
24 cite = "A paper a long time ago in a galaxy far far away."
25
26 [[stencil_set]]
27
28 order = 2
29 test = 2
30
31 H.inner = ["1"]
32 H.closure = ["1/2"]
33
34 D1.inner_stencil = ["-1/2", "0", "1/2"]
35 D1.closure_stencils = [
36 {s = ["-1", "1"], c = 1},
37 ]
38
39 D2.inner_stencil = ["1", "-2", "1"]
40 D2.closure_stencils = [
41 {s = ["1", "-2", "1"], c = 1},
42 ]
43
44 e.closure = ["1"]
45 d1.closure = {s = ["-3/2", "2", "-1/2"], c = 1}
46
47 [[stencil_set]]
48
49 order = 4
50 test = 1
51 H.inner = ["1"]
52 H.closure = ["17/48", "59/48", "43/48", "49/48"]
53
54 D2.inner_stencil = ["-1/12","4/3","-5/2","4/3","-1/12"]
55 D2.closure_stencils = [
56 {s = [ "2", "-5", "4", "-1", "0", "0"], c = 1},
57 {s = [ "1", "-2", "1", "0", "0", "0"], c = 2},
58 {s = [ "-4/43", "59/43", "-110/43", "59/43", "-4/43", "0"], c = 3},
59 {s = [ "-1/49", "0", "59/49", "-118/49", "64/49", "-4/49"], c = 4},
60 ]
61
62 e.closure = ["1"]
63 d1.closure = {s = ["-11/6", "3", "-3/2", "1/3"], c = 1}
64
65 [[stencil_set]]
66 order = 4
67 test = 2
68
69 H.closure = ["-1/49", "0", "59/49", "-118/49", "64/49", "-4/49"]
70 """
71
72 parsed_toml = TOML.parse(toml_str)
73
74 @testset "get_stencil_set" begin
75 @test get_stencil_set(parsed_toml; order = 2) isa Dict
76 @test get_stencil_set(parsed_toml; order = 2) == parsed_toml["stencil_set"][1]
77 @test get_stencil_set(parsed_toml; test = 1) == parsed_toml["stencil_set"][2]
78 @test get_stencil_set(parsed_toml; order = 4, test = 2) == parsed_toml["stencil_set"][3]
79
80 @test_throws ArgumentError get_stencil_set(parsed_toml; test = 2)
81 @test_throws ArgumentError get_stencil_set(parsed_toml; order = 4)
82 end
83
84 @testset "parse_stencil" begin
85 toml = """
86 s1 = ["-1/12","4/3","-5/2","4/3","-1/12"]
87 s2 = {s = ["2", "-5", "4", "-1", "0", "0"], c = 1}
88 s3 = {s = ["1", "-2", "1", "0", "0", "0"], c = 2}
89 s4 = "not a stencil"
90 s5 = [-1, 4, 3]
91 s6 = {k = ["1", "-2", "1", "0", "0", "0"], c = 2}
92 s7 = {s = [-1, 4, 3], c = 2}
93 s8 = {s = ["1", "-2", "1", "0", "0", "0"], c = [2,2]}
94 """
95
96 @test parse_stencil(TOML.parse(toml)["s1"]) == CenteredStencil(-1/12, 4/3, -5/2, 4/3, -1/12)
97 @test parse_stencil(TOML.parse(toml)["s2"]) == Stencil(2., -5., 4., -1., 0., 0.; center=1)
98 @test parse_stencil(TOML.parse(toml)["s3"]) == Stencil(1., -2., 1., 0., 0., 0.; center=2)
99
100 @test_throws ArgumentError parse_stencil(TOML.parse(toml)["s4"])
101 @test_throws ArgumentError parse_stencil(TOML.parse(toml)["s5"])
102 @test_throws ArgumentError parse_stencil(TOML.parse(toml)["s6"])
103 @test_throws ArgumentError parse_stencil(TOML.parse(toml)["s7"])
104 @test_throws ArgumentError parse_stencil(TOML.parse(toml)["s8"])
105
106 stencil_set = get_stencil_set(parsed_toml; order = 4, test = 1)
107
108 @test parse_stencil.(stencil_set["D2"]["closure_stencils"]) == [
109 Stencil( 2., -5., 4., -1., 0., 0.; center=1),
110 Stencil( 1., -2., 1., 0., 0., 0.; center=2),
111 Stencil(-4/43, 59/43, -110/43, 59/43, -4/43, 0.; center=3),
112 Stencil(-1/49, 0., 59/49, -118/49, 64/49, -4/49; center=4),
113 ]
114 end
115 end