diff +scheme/Utux.m @ 1033:037f203b9bf5 feature/burgers1d

Merge with branch feature/advectioRV to utilize the +rv package
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:44:12 +0100
parents d6ab5ceba496
children 8a9393084b30
line wrap: on
line diff
--- a/+scheme/Utux.m	Fri Oct 12 08:50:25 2018 +0200
+++ b/+scheme/Utux.m	Thu Jan 17 10:44:12 2019 +0100
@@ -2,9 +2,12 @@
    properties
         m % Number of points in each direction, possibly a vector
         h % Grid spacing
-        x % Grid
+        grid % Grid
         order % Order accuracy for the approximation
 
+        a % Wave speed
+          % Can either be a constant or function handle.
+
         H % Discrete norm
         D
 
@@ -12,47 +15,49 @@
         Hi
         e_l
         e_r
-        v0
     end
 
 
-    methods 
-         function obj = Utux(m,xlim,order,operator)
-             default_arg('a',1);
-           
-           %Old operators  
-           % [x, h] = util.get_grid(xlim{:},m);
-           %ops = sbp.Ordinary(m,h,order);
-           
-           
-           switch operator
-               case 'NonEquidistant'
-              ops = sbp.D1Nonequidistant(m,xlim,order);
-              obj.D1 = ops.D1;
-               case 'Standard'
-              ops = sbp.D2Standard(m,xlim,order);
-              obj.D1 = ops.D1;
-               case 'Upwind'
-              ops = sbp.D1Upwind(m,xlim,order);
-              obj.D1 = ops.Dm;
-               otherwise
-                   error('Unvalid operator')
-           end
-              obj.x=ops.x;
+    methods
+        function obj = Utux(g, order, opSet, a, fluxSplitting)
+            default_arg('opSet',@sbp.D2Standard);
+            default_arg('a',1);
+            default_arg('fluxSplitting',[]);
+
+            assertType(g, 'grid.Cartesian');
+            if isa(a, 'function_handle')
+                obj.a = spdiag(grid.evalOn(g, a));
+            else
+                obj.a = a;
+            end
 
-            
+            m = g.size();
+            xl = g.getBoundary('l');
+            xr = g.getBoundary('r');
+            xlim = {xl, xr};
+
+            ops = opSet(m, xlim, order);
+
+            if (isequal(opSet, @sbp.D1Upwind))
+                obj.D1 = (ops.Dp + ops.Dm)/2;
+                DissOp = (ops.Dm - ops.Dp)/2;
+                obj.D = -(obj.a*obj.D1 + fluxSplitting*DissOp);
+            else 
+                obj.D1 = ops.D1;
+                obj.D = -obj.a*obj.D1;
+            end
+
+            obj.grid = g;
+
             obj.H =  ops.H;
             obj.Hi = ops.HI;
-        
+
             obj.e_l = ops.e_l;
             obj.e_r = ops.e_r;
-            obj.D=obj.D1;
 
             obj.m = m;
             obj.h = ops.h;
             obj.order = order;
-            obj.x = ops.x;
-
         end
         % Closure functions return the opertors applied to the own doamin to close the boundary
         % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin.
@@ -61,19 +66,45 @@
         %       data                is a function returning the data that should be applied at the boundary.
         %       neighbour_scheme    is an instance of Scheme that should be interfaced to.
         %       neighbour_boundary  is a string specifying which boundary to interface to.
-        function [closure, penalty] = boundary_condition(obj,boundary,type,data)
-            default_arg('type','neumann');
-            default_arg('data',0);
-            tau =-1*obj.e_l;  
-            closure = obj.Hi*tau*obj.e_l';       
-            penalty = 0*obj.e_l;
-                
+        function [closure, penalty] = boundary_condition(obj,boundary,type)
+            default_arg('type','dirichlet');
+            sigma_left = -1; % Scalar penalty parameter for left boundary
+            sigma_right = 1; % Scalar penalty parameter for right boundary
+            switch boundary
+                % Can only specify boundary condition where there is inflow
+                % Extract the postivie resp. negative part of a, for the left
+                % resp. right boundary, and set other values of a to zero.
+                % Then the closure will effectively only contribute to inflow boundaries
+                case {'l','L','left','Left'}
+                    a_inflow = obj.a;
+                    a_inflow(a_inflow < 0) = 0;
+                    tau = sigma_left*a_inflow*obj.e_l;
+                    closure = obj.Hi*tau*obj.e_l';
+                case {'r','R','right','Right'}
+                    a_inflow = obj.a;
+                    a_inflow(a_inflow > 0) = 0;
+                    tau = sigma_right*a_inflow*obj.e_r;
+                    closure = obj.Hi*tau*obj.e_r';
+            end
+            penalty = -obj.Hi*tau;
+
          end
-          
-         function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary)
-          error('An interface function does not exist yet');
+
+         function [closure, penalty] = interface(obj, boundary, neighbour_scheme, neighbour_boundary, type)
+             switch boundary
+                 % Upwind coupling
+                 case {'l','left'}
+                     tau = -1*obj.a*obj.e_l;
+                     closure = obj.Hi*tau*obj.e_l';
+                     penalty = -obj.Hi*tau*neighbour_scheme.e_r';
+                 case {'r','right'}
+                     tau = 0*obj.a*obj.e_r;
+                     closure = obj.Hi*tau*obj.e_r';
+                     penalty = -obj.Hi*tau*neighbour_scheme.e_l';
+             end
+
          end
-      
+
         function N = size(obj)
             N = obj.m;
         end
@@ -81,9 +112,9 @@
     end
 
     methods(Static)
-        % Calculates the matrcis need for the inteface coupling between boundary bound_u of scheme schm_u
+        % 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_couplong(A,'r',B,'l')
+        %   [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);