Mercurial > repos > public > sbplib
comparison +grid/boundaryoptimizedTest.m @ 1289:2fd2e2337b77 feature/boundary_optimized_grids
Add utility function for constructing a (possibly multidimensional) grid based on the grid points used by the boundary optimized SBP operators
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 01 Jul 2020 15:15:30 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1288:e059a43bb675 | 1289:2fd2e2337b77 |
---|---|
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. The test uses minimal number of grid | |
54 % points required by the operators. | |
55 function testCompiles(testCase) | |
56 | |
57 %% 1D 4th order accurate stencil | |
58 % Boundary weights, number of non-equidistantly spaced points for 4th order accurate stencil | |
59 bw = [0.0000000000000e+00 6.8764546205559e-01 1.8022115125776e+00]; | |
60 n = length(bw)-1; | |
61 xi_n = bw(end); | |
62 | |
63 % Grid points in x-direction. | |
64 Lx = 1; | |
65 mx = 8; | |
66 hx_4 = Lx/(2*xi_n+(mx-2*n-1)); | |
67 | |
68 bp_l = hx_4*bw; | |
69 bp_r = Lx-flip(hx_4*bw); | |
70 interior = [hx_4*(xi_n+1) hx_4*(xi_n+2)]; | |
71 x_4 = [bp_l interior bp_r]; | |
72 | |
73 % Boundary weights, number of non-equidistantly spaced points for 8th order minimal stencil | |
74 bw = [0.0000000000000e+00, 4.9439570885261e-01, 1.4051531374839e+00]; | |
75 n = length(bw)-1; | |
76 xi_n = bw(end); | |
77 | |
78 %% 2D 8th order minimal stencil | |
79 % Grid points in x-direction. | |
80 hx_8 = Lx/(2*xi_n+(mx-2*n-1)); | |
81 | |
82 bp_l = hx_8*bw; | |
83 bp_r = Lx-flip(hx_8*bw); | |
84 interior = [hx_8*(xi_n+1) hx_8*(xi_n+2)]; | |
85 x_8 = [bp_l interior bp_r]; | |
86 | |
87 % Grid points in y-direction. | |
88 Ly = 2; | |
89 my = 9; | |
90 hy = Ly/(2*xi_n+(my-2*n-1)); | |
91 | |
92 bp_l = hy*bw; | |
93 bp_r = Ly-flip(hy*bw); | |
94 interior = [hy*(xi_n+1) hy*(xi_n+2) hy*(xi_n+3)]; | |
95 y = [bp_l interior bp_r]; | |
96 | |
97 in = { | |
98 {mx, {0,Lx},4}, | |
99 {[mx, my],{0,Lx},{0,Ly},8,'M'}, | |
100 }; | |
101 | |
102 out = { | |
103 {[x_4'],hx_4} | |
104 {[kr(x_8',ones(size(y'))),kr(ones(size(x_8')),y')],[hx_8, hy]} | |
105 }; | |
106 | |
107 for i = 1:length(in) | |
108 g = grid.boundaryoptimized(in{i}{:}); | |
109 testCase.verifyEqual(g.points(),out{i}{1},'AbsTol', 1e-14, 'RelTol', 1e-14); | |
110 testCase.verifyEqual(g.scaling(),out{i}{2},'AbsTol', 1e-14, 'RelTol', 1e-14); | |
111 end | |
112 end |