comparison +scheme/Heat2dVariable.m @ 1042:8d73fcdb07a5 feature/getBoundaryOp

Add asserts to boundary identifier inputs
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Jan 2019 16:47:34 +0100
parents 78db023a7fe3
children
comparison
equal deleted inserted replaced
1007:9c8ed00732fd 1042:8d73fcdb07a5
210 210
211 % Returns the boundary operator op for the boundary specified by the string boundary. 211 % Returns the boundary operator op for the boundary specified by the string boundary.
212 % op -- string or a cell array of strings 212 % op -- string or a cell array of strings
213 % boundary -- string 213 % boundary -- string
214 function varargout = getBoundaryOperator(obj, op, boundary) 214 function varargout = getBoundaryOperator(obj, op, boundary)
215 assertIsMember(boundary, {'w', 'e', 's', 'n'})
215 216
216 if ~iscell(op) 217 if ~iscell(op)
217 op = {op}; 218 op = {op};
218 end 219 end
219 220
227 e = obj.e_r{1}; 228 e = obj.e_r{1};
228 case 's' 229 case 's'
229 e = obj.e_l{2}; 230 e = obj.e_l{2};
230 case 'n' 231 case 'n'
231 e = obj.e_r{2}; 232 e = obj.e_r{2};
232 otherwise
233 error('No such boundary: boundary = %s',boundary);
234 end 233 end
235 varargout{i} = e; 234 varargout{i} = e;
236 235
237 case 'd' 236 case 'd'
238 switch boundary 237 switch boundary
242 d = obj.d1_r{1}; 241 d = obj.d1_r{1};
243 case 's' 242 case 's'
244 d = obj.d1_l{2}; 243 d = obj.d1_l{2};
245 case 'n' 244 case 'n'
246 d = obj.d1_r{2}; 245 d = obj.d1_r{2};
247 otherwise
248 error('No such boundary: boundary = %s',boundary);
249 end 246 end
250 varargout{i} = d; 247 varargout{i} = d;
251 end 248 end
252 end 249 end
253 end 250 end
255 % Returns square boundary quadrature matrix, of dimension 252 % Returns square boundary quadrature matrix, of dimension
256 % corresponding to the number of boundary points 253 % corresponding to the number of boundary points
257 % 254 %
258 % boundary -- string 255 % boundary -- string
259 function H_b = getBoundaryQuadrature(obj, boundary) 256 function H_b = getBoundaryQuadrature(obj, boundary)
257 assertIsMember(boundary, {'w', 'e', 's', 'n'})
260 258
261 switch boundary 259 switch boundary
262 case 'w' 260 case 'w'
263 H_b = obj.H_boundary{1}; 261 H_b = obj.H_boundary{1};
264 case 'e' 262 case 'e'
265 H_b = obj.H_boundary{1}; 263 H_b = obj.H_boundary{1};
266 case 's' 264 case 's'
267 H_b = obj.H_boundary{2}; 265 H_b = obj.H_boundary{2};
268 case 'n' 266 case 'n'
269 H_b = obj.H_boundary{2}; 267 H_b = obj.H_boundary{2};
270 otherwise
271 error('No such boundary: boundary = %s',boundary);
272 end 268 end
273 end 269 end
274 270
275 % Returns the boundary sign. The right boundary is considered the positive boundary 271 % Returns the boundary sign. The right boundary is considered the positive boundary
276 % boundary -- string 272 % boundary -- string
277 function s = getBoundarySign(obj, boundary) 273 function s = getBoundarySign(obj, boundary)
274 assertIsMember(boundary, {'w', 'e', 's', 'n'})
275
278 switch boundary 276 switch boundary
279 case {'e','n'} 277 case {'e','n'}
280 s = 1; 278 s = 1;
281 case {'w','s'} 279 case {'w','s'}
282 s = -1; 280 s = -1;
283 otherwise
284 error('No such boundary: boundary = %s',boundary);
285 end 281 end
286 end 282 end
287 283
288 % Returns borrowing constant gamma*h 284 % Returns borrowing constant gamma*h
289 % boundary -- string 285 % boundary -- string
290 function gamm = getBoundaryBorrowing(obj, boundary) 286 function gamm = getBoundaryBorrowing(obj, boundary)
287 assertIsMember(boundary, {'w', 'e', 's', 'n'})
288
291 switch boundary 289 switch boundary
292 case {'w','e'} 290 case {'w','e'}
293 gamm = obj.h(1)*obj.alpha(1); 291 gamm = obj.h(1)*obj.alpha(1);
294 case {'s','n'} 292 case {'s','n'}
295 gamm = obj.h(2)*obj.alpha(2); 293 gamm = obj.h(2)*obj.alpha(2);
296 otherwise
297 error('No such boundary: boundary = %s',boundary);
298 end 294 end
299 end 295 end
300 296
301 function N = size(obj) 297 function N = size(obj)
302 N = prod(obj.m); 298 N = prod(obj.m);