Mercurial > repos > public > sbplib
diff +grid/Curvilinear.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 | 30321dc180e1 |
line wrap: on
line diff
--- a/+grid/Curvilinear.m Mon Mar 21 16:33:49 2016 +0100 +++ b/+grid/Curvilinear.m Mon Apr 04 18:23:50 2016 +0200 @@ -83,12 +83,60 @@ % Return the names of all boundaries in this grid. function bs = getBoundaryNames(obj) - bs = []; + bs = obj.logic.getBoundaryNames(); 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.logic.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.logic.m; + m(D) = []; + N = prod(m); + + X = zeros(N, obj.D); + + p = obj.points; + for i = 1:obj.D() + coordMat{i} = reshapeRowMaj(p(:,i), obj.logic.m); + end + + for i = 1:length(coordMat) + Xtemp = coordMat{i}(I{:}); + X(:,i) = reshapeRowMaj(Xtemp, [N,1]); + end end end end