changeset 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 9c8ed00732fd
children 5afc774fb7c4
files +scheme/Beam.m +scheme/Heat2dCurvilinear.m +scheme/Heat2dVariable.m +scheme/Hypsyst2d.m +scheme/Hypsyst2dCurve.m +scheme/Laplace1d.m +scheme/LaplaceCurvilinear.m +scheme/Schrodinger.m +scheme/Schrodinger2d.m +scheme/Utux.m +scheme/Utux2d.m +scheme/Wave2d.m
diffstat 12 files changed, 46 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/+scheme/Beam.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Beam.m	Tue Jan 22 16:47:34 2019 +0100
@@ -240,10 +240,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
-
-            if ~ismember(boundary, {'l', 'r'})
-                error('No such boundary: boundary = %s',boundary);
-            end
+            assertIsMember(boundary, {'l', 'r'})
 
             if ~iscell(op)
                 op = {op};
@@ -295,13 +292,13 @@
         % Returns the boundary sign. The right boundary is considered the positive boundary
         % boundary -- string
         function s = getBoundarySign(obj, boundary)
+            assertIsMember(boundary, {'l', 'r'})
+
             switch boundary
                 case {'r'}
                     s = 1;
                 case {'l'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Heat2dCurvilinear.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Heat2dCurvilinear.m	Tue Jan 22 16:47:34 2019 +0100
@@ -321,6 +321,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -338,8 +339,6 @@
                         e = obj.e_l{2};
                     case 'n'
                         e = obj.e_r{2};
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -353,8 +352,6 @@
                         d = obj.d1_l{2};
                     case 'n'
                         d = obj.d1_r{2};
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
 
@@ -368,8 +365,6 @@
                         flux = obj.flux_l{2};
                     case 'n'
                         flux = obj.flux_r{2};
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = flux;
                 end
@@ -381,6 +376,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -391,34 +387,32 @@
                     H_b = obj.H_boundary_l{2};
                 case 'n'
                     H_b = obj.H_boundary_r{2};
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % 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 {'e','n'}
                     s = 1;
                 case {'w','s'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % Returns borrowing constant gamma*h
         % boundary -- string
         function gamm = getBoundaryBorrowing(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
+
             switch boundary
                 case {'w','e'}
                     gamm = obj.h(1)*obj.alpha(1);
                 case {'s','n'}
                     gamm = obj.h(2)*obj.alpha(2);
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Heat2dVariable.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Heat2dVariable.m	Tue Jan 22 16:47:34 2019 +0100
@@ -212,6 +212,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -229,8 +230,6 @@
                         e = obj.e_l{2};
                     case 'n'
                         e = obj.e_r{2};
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -244,8 +243,6 @@
                         d = obj.d1_l{2};
                     case 'n'
                         d = obj.d1_r{2};
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -257,6 +254,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -267,34 +265,32 @@
                     H_b = obj.H_boundary{2};
                 case 'n'
                     H_b = obj.H_boundary{2};
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % 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 {'e','n'}
                     s = 1;
                 case {'w','s'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % Returns borrowing constant gamma*h
         % boundary -- string
         function gamm = getBoundaryBorrowing(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
+
             switch boundary
                 case {'w','e'}
                     gamm = obj.h(1)*obj.alpha(1);
                 case {'s','n'}
                     gamm = obj.h(2)*obj.alpha(2);
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Hypsyst2d.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Hypsyst2d.m	Tue Jan 22 16:47:34 2019 +0100
@@ -298,6 +298,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -315,8 +316,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
                 end
@@ -328,6 +327,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             e = obj.getBoundaryOperator('e', boundary);
 
@@ -340,8 +340,6 @@
                     H_b = inv(e'*obj.Hxi*e);
                 case 'n'
                     H_b = inv(e'*obj.Hxi*e);
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Hypsyst2dCurve.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Hypsyst2dCurve.m	Tue Jan 22 16:47:34 2019 +0100
@@ -376,6 +376,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -393,8 +394,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
                 end
@@ -406,6 +405,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             e = obj.getBoundaryOperator('e', boundary);
 
@@ -418,8 +418,6 @@
                     H_b = inv(e'*obj.Hxii*e);
                 case 'n'
                     H_b = inv(e'*obj.Hxii*e);
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Laplace1d.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Laplace1d.m	Tue Jan 22 16:47:34 2019 +0100
@@ -117,6 +117,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'l', 'r'})
 
             if ~iscell(op)
                 op = {op};
@@ -130,8 +131,6 @@
                         e = obj.e_l;
                     case 'r'
                         e = obj.e_r;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -141,8 +140,6 @@
                         d = obj.d_l;
                     case 'r'
                         d = obj.d_r;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -152,13 +149,13 @@
         % Returns the boundary sign. The right boundary is considered the positive boundary
         % boundary -- string
         function s = getBoundarySign(obj, boundary)
+            assertIsMember(boundary, {'l', 'r'})
+
             switch boundary
                 case {'r'}
                     s = 1;
                 case {'l'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/LaplaceCurvilinear.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/LaplaceCurvilinear.m	Tue Jan 22 16:47:34 2019 +0100
@@ -399,6 +399,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -416,8 +417,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -431,8 +430,6 @@
                         d = obj.d_s;
                     case 'n'
                         d = obj.d_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -444,6 +441,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -454,14 +452,14 @@
                     H_b = obj.H_s;
                 case 'n'
                     H_b = obj.H_n;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             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.m));
             switch boundary
                 case 'w'
@@ -472,21 +470,19 @@
                     I = ind(:,1)';
                 case 'n'
                     I = ind(:,end)';
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % Returns borrowing constant gamma
         % boundary -- string
         function gamm = getBoundaryBorrowing(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
+
             switch boundary
                 case {'w','e'}
                     gamm = obj.gamm_u;
                 case {'s','n'}
                     gamm = obj.gamm_v;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Schrodinger.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Schrodinger.m	Tue Jan 22 16:47:34 2019 +0100
@@ -114,6 +114,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'l', 'r'})
 
             if ~iscell(op)
                 op = {op};
@@ -127,8 +128,6 @@
                         e = obj.e_l;
                     case 'r'
                         e = obj.e_r;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -138,8 +137,6 @@
                         d = obj.d1_l;
                     case 'r'
                         d = obj.d1_r;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -149,13 +146,13 @@
         % Returns the boundary sign. The right boundary is considered the positive boundary
         % boundary -- string
         function s = getBoundarySign(obj, boundary)
+            assertIsMember(boundary, {'l', 'r'})
+
             switch boundary
                 case {'r'}
                     s = 1;
                 case {'l'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Schrodinger2d.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Schrodinger2d.m	Tue Jan 22 16:47:34 2019 +0100
@@ -290,6 +290,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -307,8 +308,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -322,8 +321,6 @@
                         d = obj.d_s;
                     case 'n'
                         d = obj.d_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -335,6 +332,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -345,21 +343,19 @@
                     H_b = obj.H_boundary{2};
                 case 'n'
                     H_b = obj.H_boundary{2};
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % 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 {'e','n'}
                     s = 1;
                 case {'w','s'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Utux.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Utux.m	Tue Jan 22 16:47:34 2019 +0100
@@ -76,6 +76,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'l', 'r'})
 
             if ~iscell(op)
                 op = {op};
@@ -89,8 +90,6 @@
                         e = obj.e_l;
                     case 'r'
                         e = obj.e_r;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
                 end
--- a/+scheme/Utux2d.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Utux2d.m	Tue Jan 22 16:47:34 2019 +0100
@@ -276,6 +276,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -293,8 +294,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
                 end
@@ -307,6 +306,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -317,8 +317,6 @@
                     H_b = obj.H_x;
                 case 'n'
                     H_b = obj.H_x;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
--- a/+scheme/Wave2d.m	Wed Jan 16 11:31:04 2019 -0800
+++ b/+scheme/Wave2d.m	Tue Jan 22 16:47:34 2019 +0100
@@ -200,6 +200,7 @@
         % op        -- string or a cell array of strings
         % boundary  -- string
         function varargout = getBoundaryOperator(obj, op, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             if ~iscell(op)
                 op = {op};
@@ -217,8 +218,6 @@
                         e = obj.e_s;
                     case 'n'
                         e = obj.e_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = e;
 
@@ -232,8 +231,6 @@
                         d = obj.d1_s;
                     case 'n'
                         d = obj.d1_n;
-                    otherwise
-                        error('No such boundary: boundary = %s',boundary);
                     end
                     varargout{i} = d;
                 end
@@ -246,6 +243,7 @@
         %
         % boundary -- string
         function H_b = getBoundaryQuadrature(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
 
             switch boundary
                 case 'w'
@@ -256,39 +254,39 @@
                     H_b = obj.H_x;
                 case 'n'
                     H_b = obj.H_x;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % Returns borrowing constant gamma
         % boundary -- string
         function gamm = getBoundaryBorrowing(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
+
             switch boundary
                 case {'w','e'}
                     gamm = obj.gamm_x;
                 case {'s','n'}
                     gamm = obj.gamm_y;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % 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 {'e','n'}
                     s = 1;
                 case {'w','s'}
                     s = -1;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end
 
         % Returns the halfnorm_inv used in SATs. TODO: better notation
         function Hinv = getHalfnormInv(obj, boundary)
+            assertIsMember(boundary, {'w', 'e', 's', 'n'})
+
             switch boundary
                 case 'w'
                     Hinv = obj.Hix;
@@ -298,8 +296,6 @@
                     Hinv = obj.Hiy;
                 case 'n'
                     Hinv = obj.Hiy;
-                otherwise
-                    error('No such boundary: boundary = %s',boundary);
             end
         end