diff +scheme/Utux2d.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 8a9393084b30 84200bbae101
children
line wrap: on
line diff
--- a/+scheme/Utux2d.m	Wed Aug 07 13:28:21 2019 +0200
+++ b/+scheme/Utux2d.m	Wed Aug 07 15:23:42 2019 +0200
@@ -11,6 +11,7 @@
         H % Discrete norm
         H_x, H_y % Norms in the x and y directions
         Hi, Hx, Hy, Hxi, Hyi % Kroneckered norms
+        H_w, H_e, H_s, H_n % Boundary quadratures
 
         % Derivatives
         Dx, Dy
@@ -59,6 +60,10 @@
             Hxi = ops_x.HI;
             Hyi = ops_y.HI;
 
+            obj.H_w = Hy;
+            obj.H_e = Hy;
+            obj.H_s = Hx;
+            obj.H_n = Hx;
             obj.H_x = Hx;
             obj.H_y = Hy;
             obj.H = kron(Hx,Hy);
@@ -109,8 +114,9 @@
         %       neighbour_boundary  is a string specifying which boundary to interface to.
         function [closure, penalty] = boundary_condition(obj,boundary,type)
             default_arg('type','dirichlet');
-            sigma_left = -1; % Scalar penalty parameter for left boundaries (West/South)
-            sigma_right = 1; % Scalar penalty parameter for right boundaries (East/North)
+            s = obj.getBoundarySign(boundary);
+            e = obj.getBoundaryOperator('e', boundary);
+            H_1d = obj.getOneDirectionalNorm(boundary);
             switch boundary
                 % Can only specify boundary condition where there is inflow
                 % Extract the postivie resp. negative part of a, for the left
@@ -119,24 +125,18 @@
                 case {'w','W','west','West'}
                     a_inflow = obj.a{1};
                     a_inflow(a_inflow < 0) = 0;
-                    tau = sigma_left*a_inflow*obj.e_w*obj.H_y;
-                    closure = obj.Hi*tau*obj.e_w';
                 case {'e','E','east','East'}
                     a_inflow = obj.a{1};
                     a_inflow(a_inflow > 0) = 0;
-                    tau = sigma_right*a_inflow*obj.e_e*obj.H_y;
-                    closure = obj.Hi*tau*obj.e_e';
                 case {'s','S','south','South'}
                     a_inflow = obj.a{2};
                     a_inflow(a_inflow < 0) = 0;
-                    tau = sigma_left*a_inflow*obj.e_s*obj.H_x;
-                    closure = obj.Hi*tau*obj.e_s';
                 case {'n','N','north','North'}
                     a_inflow = obj.a{2};
                     a_inflow(a_inflow > 0) = 0;
-                    tau = sigma_right*a_inflow*obj.e_n*obj.H_x;
-                    closure = obj.Hi*tau*obj.e_n';
             end
+            tau = s*a_inflow*e*H_1d;
+            closure = obj.Hi*tau*e';
             penalty = -obj.Hi*tau;
         end
 
@@ -168,16 +168,7 @@
             couplingType = type.couplingType;
 
             % Get neighbour boundary operator
-            switch neighbour_boundary
-             case {'e','E','east','East'}
-                 e_neighbour = neighbour_scheme.e_e;
-             case {'w','W','west','West'}
-                 e_neighbour = neighbour_scheme.e_w;
-             case {'n','N','north','North'}
-                 e_neighbour = neighbour_scheme.e_n;
-             case {'s','S','south','South'}
-                 e_neighbour = neighbour_scheme.e_s;
-            end
+            e_neighbour = neighbour_scheme.getBoundaryOperator('e', neighbour_boundary);
 
             switch couplingType
 
@@ -226,16 +217,7 @@
             interpolationDamping = type.interpolationDamping;
 
             % Get neighbour boundary operator
-            switch neighbour_boundary
-             case {'e','E','east','East'}
-                 e_neighbour = neighbour_scheme.e_e;
-             case {'w','W','west','West'}
-                 e_neighbour = neighbour_scheme.e_w;
-             case {'n','N','north','North'}
-                 e_neighbour = neighbour_scheme.e_n;
-             case {'s','S','south','South'}
-                 e_neighbour = neighbour_scheme.e_s;
-            end
+            e_neighbour = neighbour_scheme.getBoundaryOperator('e', neighbour_boundary);
 
             switch couplingType
 
@@ -319,19 +301,55 @@
 
          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;
+            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
+
         function N = size(obj)
             N = obj.m;
         end
 
     end
-
-    methods(Static)
-        % Calculates the matrices needed for the inteface coupling between boundary bound_u of scheme schm_u
-        % and bound_v of scheme schm_v.
-        %   [uu, uv, vv, vu] = inteface_coupling(A,'r',B,'l')
-        function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v)
-            [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v);
-            [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u);
-        end
-    end
-end
\ No newline at end of file
+end