Mercurial > repos > public > sbplib
comparison +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 |
comparison
equal
deleted
inserted
replaced
190:2c2ba1f3bbe3 | 191:7c1d3fc33f90 |
---|---|
123 error('grid:Cartesian:NotImplemented') | 123 error('grid:Cartesian:NotImplemented') |
124 end | 124 end |
125 | 125 |
126 % Return the names of all boundaries in this grid. | 126 % Return the names of all boundaries in this grid. |
127 function bs = getBoundaryNames(obj) | 127 function bs = getBoundaryNames(obj) |
128 bs = []; | 128 switch obj.D() |
129 case 1 | |
130 bs = {'l', 'r'}; | |
131 case 2 | |
132 bs = {'w', 'e', 's', 'n'}; | |
133 case 3 | |
134 bs = {'w', 'e', 's', 'n', 'd', 'u'}; | |
135 otherwise | |
136 error('not implemented'); | |
137 end | |
129 end | 138 end |
130 | 139 |
131 % Return coordinates for the given boundary | 140 % Return coordinates for the given boundary |
132 function b = getBoundary(obj, name) | 141 function X = getBoundary(obj, name) |
133 b = []; | 142 % In what dimension is the boundary? |
143 switch name | |
144 case {'l', 'r', 'w', 'e'} | |
145 D = 1; | |
146 case {'s', 'n'} | |
147 D = 2; | |
148 case {'d', 'u'} | |
149 D = 3; | |
150 otherwise | |
151 error('not implemented'); | |
152 end | |
153 | |
154 % At what index is the boundary? | |
155 switch name | |
156 case {'l', 'w', 's', 'd'} | |
157 index = 1; | |
158 case {'r', 'e', 'n', 'u'} | |
159 index = obj.m(D); | |
160 otherwise | |
161 error('not implemented'); | |
162 end | |
163 | |
164 | |
165 | |
166 I = cell(1, obj.d); | |
167 for i = 1:obj.d | |
168 if i == D | |
169 I{i} = index; | |
170 else | |
171 I{i} = ':'; | |
172 end | |
173 end | |
174 | |
175 % Calculate size of result: | |
176 m = obj.m; | |
177 m(D) = []; | |
178 N = prod(m); | |
179 | |
180 X = zeros(N, obj.d); | |
181 | |
182 coordMat = obj.matrices(); | |
183 for i = 1:length(coordMat) | |
184 Xtemp = coordMat{i}(I{:}); | |
185 X(:,i) = reshapeRowMaj(Xtemp, [N,1]); | |
186 end | |
134 end | 187 end |
135 | |
136 end | 188 end |
137 end | 189 end |