comparison +grid/boundaryOptimizedTest.m @ 1300:196123459178

Merge in feature/boundary_optimized_grids
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 08 Jul 2020 18:22:54 +0200
parents 0ffb5bfa65e4
children
comparison
equal deleted inserted replaced
1250:8ec777fb473e 1300:196123459178
1 function tests = boundaryOptimizedTest()
2 tests = functiontests(localfunctions);
3 end
4
5 function testErrorInvalidParam(testCase)
6 in = {
7 %Invalid order
8 {[10 10],{0,1},{0,2},3},
9 %Invalid grid size
10 {5, {0,1}, 4},
11 {[10 5],{0,1},{0,2},4},
12 {[10 5],{0,1},{0,2},6,'M'},
13 %Invalid limits
14 {10,{1},4},
15 {[10,10],{0,1},{1},4},
16 {[10,10],{1},{1,0},4},
17 {10,{1,0},4},
18 {[10, 5],{1,0},{0,-1},4},
19 };
20
21 for i = 1:length(in)
22 testCase.verifyError(@()grid.boundaryOptimized(in{i}{:}),'grid:boundaryOptimized:InvalidParameter',sprintf('in(%d) = %s',i,toString(in{i})));
23 end
24 end
25
26 function testErrorInvalidOption(testCase)
27 in = {
28 {[8 8],{0,1},{0,2},4,'acrurate'},
29 };
30
31 for i = 1:length(in)
32 testCase.verifyError(@()grid.boundaryOptimized(in{i}{:}),'grid:boundaryOptimized:InvalidOption',sprintf('in(%d) = %s',i,toString(in{i})));
33 end
34 end
35
36 function testErrorNonMatchingParam(testCase)
37 in = {
38 {[],{1},4},
39 {[],{0,1},{0,1},4},
40 {[5,5],{0,1},{0,1},{0,1},4},
41 {[5,5,4],{0,1},{0,1},4,'accurate'}
42 {[5,5,4],{0,1},{0,1},{0,1},4,4},
43 };
44
45 for i = 1:length(in)
46 testCase.verifyError(@()grid.boundaryOptimized(in{i}{:}),'grid:boundaryOptimized:NonMatchingParameters',sprintf('in(%d) = %s',i,toString(in{i})));
47 end
48 end
49
50 % Tests that the expected grid points are obtained for a boundary optimized grid with a 4th order
51 % accurate stencil and 8th order minimal stencil.
52 % The boundary grid point distance weights are taken from the D1Nonequidistant operators and
53 % grid spacing is calculated according to Mattsson et al 2018.
54 function testCompiles(testCase)
55
56 %% 1D 4th order accurate stencil
57 % Boundary weights, number of non-equidistantly spaced points for 4th order accurate stencil
58 bw = [0.0000000000000e+00 6.8764546205559e-01 1.8022115125776e+00];
59 n = length(bw)-1;
60 xi_n = bw(end);
61
62 % Grid points in x-direction.
63 Lx = 1;
64 mx = 8;
65 hx_4 = Lx/(2*xi_n+(mx-2*n-1));
66
67 bp_l = hx_4*bw;
68 bp_r = Lx-flip(hx_4*bw);
69 interior = [hx_4*(xi_n+1) hx_4*(xi_n+2)];
70 x_4 = [bp_l interior bp_r];
71
72 % Boundary weights, number of non-equidistantly spaced points for 8th order minimal stencil
73 bw = [0.0000000000000e+00, 4.9439570885261e-01, 1.4051531374839e+00];
74 n = length(bw)-1;
75 xi_n = bw(end);
76
77 %% 2D 8th order minimal stencil
78 % Grid points in x-direction.
79 hx_8 = Lx/(2*xi_n+(mx-2*n-1));
80
81 bp_l = hx_8*bw;
82 bp_r = Lx-flip(hx_8*bw);
83 interior = [hx_8*(xi_n+1) hx_8*(xi_n+2)];
84 x_8 = [bp_l interior bp_r];
85
86 % Grid points in y-direction.
87 Ly = 2;
88 my = 9;
89 hy = Ly/(2*xi_n+(my-2*n-1));
90
91 bp_l = hy*bw;
92 bp_r = Ly-flip(hy*bw);
93 interior = [hy*(xi_n+1) hy*(xi_n+2) hy*(xi_n+3)];
94 y = [bp_l interior bp_r];
95
96 in = {
97 {mx, {0,Lx},4},
98 {[mx, my],{0,Lx},{0,Ly},8,'M'},
99 };
100
101 out = {
102 {[x_4'],hx_4}
103 {[kr(x_8',ones(size(y'))),kr(ones(size(x_8')),y')],[hx_8, hy]}
104 };
105
106 for i = 1:length(in)
107 g = grid.boundaryOptimized(in{i}{:});
108 testCase.verifyEqual(g.points(),out{i}{1},'AbsTol', 1e-14, 'RelTol', 1e-14);
109 testCase.verifyEqual(g.scaling(),out{i}{2},'AbsTol', 1e-14, 'RelTol', 1e-14);
110 end
111 end