Mercurial > repos > public > sbplib
diff +scheme/Burgers2d.m @ 1197:433c89bf19e0 feature/rv
Merge with default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 07 Aug 2019 15:23:42 +0200 |
parents | 6cb03209f0a7 |
children |
line wrap: on
line diff
--- a/+scheme/Burgers2d.m Wed Aug 07 13:28:21 2019 +0200 +++ b/+scheme/Burgers2d.m Wed Aug 07 15:23:42 2019 +0200 @@ -101,17 +101,17 @@ % type is a string specifying the type of boundary condition if there are several. function [closure, penalty] = boundary_condition(obj,boundary,type) default_arg('type','dirichlet'); - [e, H_b, index, s] = obj.get_boundary_ops(boundary); + s = obj.getBoundarySign(boundary); + e = obj.getBoundaryOperator('e', boundary); + indices = obj.getBoundaryIndices(boundary); + H_1d = obj.getOneDirectionalNorm(boundary); switch type - % Stable dirchlet-like boundary conditions (u+-abs(u))*u/3 - % with +- at left/right boundaries in each coordinate direction case {'D', 'd', 'dirichlet', 'Dirichlet'} - - magnitude = 1/3; - Tau = s*magnitude*obj.Hi*e*H_b/2; - m = length(index); - tau = @(v) Tau*spdiags((v(index)-s*abs(v(index))),0,m,m); - closure = @(v) Tau*((v(index)-s*abs(v(index))).*v(index)); + penalty_parameter = 1/3; + Tau = s*penalty_parameter*obj.Hi*e*H_1d/2; + m = obj.grid.m; + tau = @(v) Tau*spdiags((v(indices)-s*abs(v(indices))),0,m(1),m(2)); + closure = @(v) Tau*((v(indices)-s*abs(v(indices))).*v(indices)); penalty = @(v) -tau(v); otherwise error('No such boundary condition: type = %s',type); @@ -120,33 +120,66 @@ end - % Ruturns the boundary ops, half-norm, boundary indices and sign for the boundary specified by the string boundary. - % The right boundary for each coordinate direction is considered the positive boundary - function [e, H_b, index, s] = get_boundary_ops(obj, boundary) - ind = grid.funcToMatrix(obj.grid, 1:obj.grid.N()); + % Returns the boundary sign. The right boundary is considered the positive boundary + % boundary -- string + function s = getBoundarySign(obj, boundary) + assertIsMember(boundary, {'w', 'e', 's', 'n'}) switch boundary - case {'w', 'W', 'west', 'West'} - e = obj.e_w; - H_b = obj.H_y; - index = ind(1,:); + case {'e','n'} + s = 1; + case {'w','s'} s = -1; - case {'e', 'E', 'east', 'East'} - e = obj.e_e; - H_b = obj.H_y; - index = ind(end,:); - s = 1; - case {'s', 'S', 'south', 'South'} - e = obj.e_s; - H_b = obj.H_x; - index = ind(:,1); - s = -1; - case {'n', 'N', 'north', 'North'} - e = obj.e_n; - H_b = obj.H_x; - index = ind(:,end); - s = 1; - otherwise - error('No such boundary: boundary = %s',boundary); + end + end + + % Returns the boundary operator op for the boundary specified by the string boundary. + % op -- string + % boundary -- string + function o = getBoundaryOperator(obj, op, boundary) + assertIsMember(op, {'e'}) + assertIsMember(boundary, {'w', 'e', 's', 'n'}) + + o = obj.([op, '_', boundary]); + end + + % Returns square boundary quadrature matrix, of dimension + % corresponding to the number of boundary points + % + % boundary -- string + function H_b = getBoundaryQuadrature(obj, boundary) + assertIsMember(boundary, {'w', 'e', 's', 'n'}) + H_b = obj.(['H_', boundary]); + end + + % Returns square boundary quadrature matrix, of dimension + % corresponding to the number of boundary points + % + % boundary -- string + function H_1d = getOneDirectionalNorm(obj, boundary) + assertIsMember(boundary, {'w', 'e', 's', 'n'}) + switch boundary + case {'w','e'} + H_1d = obj.H_y; + case {'s','n'} + H_1d = obj.H_x; + end + end + + % Returns the indices of the boundary points in the grid matrix + % boundary -- string + function I = getBoundaryIndices(obj, boundary) + assertIsMember(boundary, {'w', 'e', 's', 'n'}) + + ind = grid.funcToMatrix(obj.grid, 1:prod(obj.grid.m)); + switch boundary + case 'w' + I = ind(1,:); + case 'e' + I = ind(end,:); + case 's' + I = ind(:,1)'; + case 'n' + I = ind(:,end)'; end end