Mercurial > repos > public > sbplib
changeset 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 | 0e56192f6459 |
children | f7bb2a94d291 |
files | +grid/Curvilinear.m |
diffstat | 1 files changed, 30 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
diff -r 0e56192f6459 -r c3483685116a +grid/Curvilinear.m --- a/+grid/Curvilinear.m Thu Feb 25 11:17:48 2016 +0100 +++ b/+grid/Curvilinear.m Thu Feb 25 11:30:05 2016 +0100 @@ -27,28 +27,9 @@ obj.coords = zeros(N,D); if iscell(mapping) - if ~isequal(size(mapping),[1 D]) - error('grid:Curvilinear:Curvilinear','The cell array must be a row array.'); - end - - if isequal(size(mapping{1}),[N 1]) - obj.coords = cell2mat(mapping); - elseif isequal(size(mapping{1}), obj.logic.m) - for i = 1:length(mapping) - obj.coords(:,i) = reshapeRowMaj(mapping{i}, [N 1]); - end - else - error('grid:Curvilinear:Curvilinear','The matrix must have size [N 1] or the same dimension as the grid. Actual: %s', toString(obj.logic.m)); - end - + obj.coords = cellMappingToCoords(mapping, N, D, obj.logic.m); elseif isnumeric(mapping) - if isequal(size(mapping), [N, D]) - obj.coords = mapping; - elseif isequal(size(mapping), [N*D, 1]) - obj.coords = reshapeRowMaj(mapping,[N D]); - else - error('grid:Curvilinear:Curvilinear','A matrix mapping must be of size [N D] or [N*D 1].'); - end + obj.coords = matrixMappingToCoords(mapping, N, D) else error('grid:Curvilinear:Curvilinear','mapping must be a matrix or a cell array.'); end @@ -93,4 +74,31 @@ gf = obj.logic.projectFunc(gf,g.baseGrid()); end end -end \ No newline at end of file +end + + +function coords = cellMappingToCoords(mapping, N, D, m) + if ~isequal(size(mapping),[1 D]) + error('grid:Curvilinear:Curvilinear','The cell array must be a row array.'); + end + + if isequal(size(mapping{1}),[N 1]) + coords = cell2mat(mapping); + elseif isequal(size(mapping{1}), m) + for i = 1:length(mapping) + coords(:,i) = reshapeRowMaj(mapping{i}, [N 1]); + end + else + error('grid:Curvilinear:Curvilinear','The matrix must have size [N 1] or the same dimension as the grid. Actual: %s', toString(m)); + end +end + +function coords = matrixMappingToCoords(mapping, N, D) + if isequal(size(mapping), [N, D]) + coords = mapping; + elseif isequal(size(mapping), [N*D, 1]) + coords = reshapeRowMaj(mapping,[N D]); + else + error('grid:Curvilinear:Curvilinear','A matrix mapping must be of size [N D] or [N*D 1].'); + end +end