comparison +grid/CurvilinearTest.m @ 820:501750fbbfdb

Merge with feature/grids
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Sep 2018 14:40:58 +0200
parents 7c1d3fc33f90
children
comparison
equal deleted inserted replaced
819:fdf0ef9150f4 820:501750fbbfdb
1 function tests = CurvilinearTest()
2 tests = functiontests(localfunctions);
3 end
4
5 function testMappingInputGridFunction(testCase)
6 in = {
7 {{1:10}, @(x) exp(x)},
8 {{1:10,1:6}, @(x,y) [exp(x+y); exp(x-y)]},
9 {{1:10,1:5,1:7}, @(x,y,z)[exp(x+y+z); exp(x-y-z); 2+x+y-z]},
10 };
11
12 out = {
13 [10, 1];
14 [10*6, 2];
15 [10*5*7, 3];
16 };
17
18
19 % How to test this? Just make sure it runs without errors.
20
21 for i = 1:length(in)
22 g = grid.Curvilinear(in{i}{2},in{i}{1}{:});
23 testCase.verifyEqual(size(g.coords),out{i});
24 end
25 end
26
27 function testMappingInputComponentMatrix(testCase)
28 in = {
29 {{1:3}, [1 2 3]'},
30 {{1:2, 1:3}, [1 2 3 4 5 6; 7 8 9 10 11 12]'},
31 };
32
33 for i = 1:length(in)
34 g = grid.Curvilinear(in{i}{2},in{i}{1}{:});
35 testCase.verifyEqual(g.coords,in{i}{2});
36 end
37 end
38
39 function testMappingInputCellOfMatrix(testCase)
40
41 in = {
42 {{1:3}, {[1 2 3]'}},
43 {{1:2, 1:3}, {[1 2 3; 4 5 6], [7 8 9; 10 11 12]}},
44 };
45
46 out = {
47 [1 2 3]',
48 [1 2 3 4 5 6; 7 8 9 10 11 12]',
49 };
50
51 for i = 1:length(in)
52 g = grid.Curvilinear(in{i}{2},in{i}{1}{:});
53 testCase.verifyEqual(g.coords,out{i});
54 end
55 end
56
57 function testMappingInputCellOfVectors(testCase)
58 in = {
59 {{1:3}, {[1 2 3]'}},
60 {{1:2, 1:3}, {[1 2 3 4 5 6]', [7 8 9 10 11 12]'}},
61 };
62
63 out = {
64 [1 2 3]',
65 [1 2 3 4 5 6; 7 8 9 10 11 12]',
66 };
67 end
68
69 function testMappingInputError(testCase)
70 testCase.verifyFail();
71 end
72
73 function testScaling(testCase)
74 in = {{1:2, 1:3}, {[1 2 3 4 5 6]', [7 8 9 10 11 12]'}};
75 g = grid.Curvilinear(in{2},in{1}{:});
76
77 testCase.verifyError(@()g.scaling(),'grid:Curvilinear:NoScalingSet');
78
79 g.logicalGrid.h = [2 1];
80 testCase.verifyEqual(g.scaling(),[2 1]);
81 end
82
83 function testGetBoundaryNames(testCase)
84 in = {
85 {{1:10}, @(x) exp(x)},
86 {{1:10,1:6}, @(x,y) [exp(x+y); exp(x-y)]},
87 {{1:10,1:5,1:7}, @(x,y,z)[exp(x+y+z); exp(x-y-z); 2+x+y-z]},
88 };
89
90 out = {
91 {'l', 'r'},
92 {'w', 'e', 's', 'n'},
93 {'w', 'e', 's', 'n', 'd', 'u'},
94 };
95
96 for i = 1:length(in)
97 g = grid.Curvilinear(in{i}{2},in{i}{1}{:});
98 testCase.verifyEqual(g.getBoundaryNames(), out{i});
99 end
100 end
101
102 function testGetBoundary(testCase)
103 grids = {
104 {{1:10}, @(x) exp(x)},
105 {{1:10,1:6}, @(x,y) [exp(x+y); exp(x-y)]},
106 {{1:10,1:5,1:7}, @(x,y,z)[exp(x+y+z); exp(x-y-z); 2+x+y-z]},
107 };
108
109 boundaries = {
110 {'l', 'r'},
111 {'w', 'e', 's', 'n'},
112 {'w', 'e', 's', 'n', 'd', 'u'},
113 };
114
115
116 for ig = 1:length(grids)
117 g = grid.Curvilinear(grids{ig}{2},grids{ig}{1}{:});
118
119 logicalGrid = grid.Cartesian(grids{ig}{1}{:});
120
121 for ib = 1:length(boundaries{ig})
122
123 logicalBoundary = logicalGrid.getBoundary(boundaries{ig}{ib});
124
125 x = num2cell(logicalBoundary',2);
126 expectedBoundary = grids{ig}{2}(x{:})';
127 testCase.verifyEqual(g.getBoundary(boundaries{ig}{ib}), expectedBoundary);
128 end
129 end
130 end
131