Mercurial > repos > public > sbplib
comparison +grid/Curvilinear.m @ 172:c3483685116a feature/grids
Refactored input parsing in Curvilinear.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 25 Feb 2016 11:30:05 +0100 |
parents | 62b5f3c34bcb |
children | f7bb2a94d291 |
comparison
equal
deleted
inserted
replaced
171:0e56192f6459 | 172:c3483685116a |
---|---|
25 N = obj.logic.N(); | 25 N = obj.logic.N(); |
26 | 26 |
27 obj.coords = zeros(N,D); | 27 obj.coords = zeros(N,D); |
28 | 28 |
29 if iscell(mapping) | 29 if iscell(mapping) |
30 if ~isequal(size(mapping),[1 D]) | 30 obj.coords = cellMappingToCoords(mapping, N, D, obj.logic.m); |
31 error('grid:Curvilinear:Curvilinear','The cell array must be a row array.'); | |
32 end | |
33 | |
34 if isequal(size(mapping{1}),[N 1]) | |
35 obj.coords = cell2mat(mapping); | |
36 elseif isequal(size(mapping{1}), obj.logic.m) | |
37 for i = 1:length(mapping) | |
38 obj.coords(:,i) = reshapeRowMaj(mapping{i}, [N 1]); | |
39 end | |
40 else | |
41 error('grid:Curvilinear:Curvilinear','The matrix must have size [N 1] or the same dimension as the grid. Actual: %s', toString(obj.logic.m)); | |
42 end | |
43 | |
44 elseif isnumeric(mapping) | 31 elseif isnumeric(mapping) |
45 if isequal(size(mapping), [N, D]) | 32 obj.coords = matrixMappingToCoords(mapping, N, D) |
46 obj.coords = mapping; | |
47 elseif isequal(size(mapping), [N*D, 1]) | |
48 obj.coords = reshapeRowMaj(mapping,[N D]); | |
49 else | |
50 error('grid:Curvilinear:Curvilinear','A matrix mapping must be of size [N D] or [N*D 1].'); | |
51 end | |
52 else | 33 else |
53 error('grid:Curvilinear:Curvilinear','mapping must be a matrix or a cell array.'); | 34 error('grid:Curvilinear:Curvilinear','mapping must be a matrix or a cell array.'); |
54 end | 35 end |
55 end | 36 end |
56 | 37 |
92 function gf = projectFunc(obj, gf, g) | 73 function gf = projectFunc(obj, gf, g) |
93 gf = obj.logic.projectFunc(gf,g.baseGrid()); | 74 gf = obj.logic.projectFunc(gf,g.baseGrid()); |
94 end | 75 end |
95 end | 76 end |
96 end | 77 end |
78 | |
79 | |
80 function coords = cellMappingToCoords(mapping, N, D, m) | |
81 if ~isequal(size(mapping),[1 D]) | |
82 error('grid:Curvilinear:Curvilinear','The cell array must be a row array.'); | |
83 end | |
84 | |
85 if isequal(size(mapping{1}),[N 1]) | |
86 coords = cell2mat(mapping); | |
87 elseif isequal(size(mapping{1}), m) | |
88 for i = 1:length(mapping) | |
89 coords(:,i) = reshapeRowMaj(mapping{i}, [N 1]); | |
90 end | |
91 else | |
92 error('grid:Curvilinear:Curvilinear','The matrix must have size [N 1] or the same dimension as the grid. Actual: %s', toString(m)); | |
93 end | |
94 end | |
95 | |
96 function coords = matrixMappingToCoords(mapping, N, D) | |
97 if isequal(size(mapping), [N, D]) | |
98 coords = mapping; | |
99 elseif isequal(size(mapping), [N*D, 1]) | |
100 coords = reshapeRowMaj(mapping,[N D]); | |
101 else | |
102 error('grid:Curvilinear:Curvilinear','A matrix mapping must be of size [N D] or [N*D 1].'); | |
103 end | |
104 end |