Mercurial > repos > public > sbplib
diff +grid/Cartesian.m @ 191:7c1d3fc33f90 feature/grids
Added methods for returning boundary names and boundary coordinates from Cartesian and Curvilinear grids.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 04 Apr 2016 18:23:50 +0200 |
parents | c5ca9bbfed41 |
children | 3da69d57e684 |
line wrap: on
line diff
--- a/+grid/Cartesian.m Mon Mar 21 16:33:49 2016 +0100 +++ b/+grid/Cartesian.m Mon Apr 04 18:23:50 2016 +0200 @@ -125,13 +125,65 @@ % Return the names of all boundaries in this grid. function bs = getBoundaryNames(obj) - bs = []; + switch obj.D() + case 1 + bs = {'l', 'r'}; + case 2 + bs = {'w', 'e', 's', 'n'}; + case 3 + bs = {'w', 'e', 's', 'n', 'd', 'u'}; + otherwise + error('not implemented'); + end end % Return coordinates for the given boundary - function b = getBoundary(obj, name) - b = []; + function X = getBoundary(obj, name) + % In what dimension is the boundary? + switch name + case {'l', 'r', 'w', 'e'} + D = 1; + case {'s', 'n'} + D = 2; + case {'d', 'u'} + D = 3; + otherwise + error('not implemented'); + end + + % At what index is the boundary? + switch name + case {'l', 'w', 's', 'd'} + index = 1; + case {'r', 'e', 'n', 'u'} + index = obj.m(D); + otherwise + error('not implemented'); + end + + + + I = cell(1, obj.d); + for i = 1:obj.d + if i == D + I{i} = index; + else + I{i} = ':'; + end + end + + % Calculate size of result: + m = obj.m; + m(D) = []; + N = prod(m); + + X = zeros(N, obj.d); + + coordMat = obj.matrices(); + for i = 1:length(coordMat) + Xtemp = coordMat{i}(I{:}); + X(:,i) = reshapeRowMaj(Xtemp, [N,1]); + end end - end end \ No newline at end of file