changeset 1287:38653d26225c feature/boundary_optimized_grids

Make accurate/minimalBoundaryOptimizedGrid take the domain limits as input
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 01 Jul 2020 14:54:21 +0200
parents 4cb627c7fb90
children e059a43bb675
files +sbp/+util/accurateBoundaryOptimizedGrid.m +sbp/+util/minimalBoundaryOptimizedGrid.m +sbp/D1Nonequidistant.m
diffstat 3 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/+sbp/+util/accurateBoundaryOptimizedGrid.m	Wed Jul 01 13:43:32 2020 +0200
+++ b/+sbp/+util/accurateBoundaryOptimizedGrid.m	Wed Jul 01 14:54:21 2020 +0200
@@ -1,4 +1,6 @@
-function [x,h] = accurateBoundaryOptimizedGrid(L,N,order)
+function [x,h] = accurateBoundaryOptimizedGrid(lim,N,order)
+    L = lim{2} - lim{1};
+    assert(L>0,'Limits must be given in increasing order.')
     %%%% Non-equidistant grid points %%%%%
     xb = boundaryPoints(order);
     m = length(xb)-1; % Number of non-equidistant points
@@ -11,6 +13,7 @@
 
     %%%% Define grid %%%%%%%%
     x = h*[xb; linspace(xb(end)+1,L/h-xb(end)-1,N-2*(m+1))'; L/h-flip(xb) ];
+    x = x + lim{1};
     %%%%%%%%%%%%%%%%%%%%%%%%%
 end
 function xb = boundaryPoints(order)
--- a/+sbp/+util/minimalBoundaryOptimizedGrid.m	Wed Jul 01 13:43:32 2020 +0200
+++ b/+sbp/+util/minimalBoundaryOptimizedGrid.m	Wed Jul 01 14:54:21 2020 +0200
@@ -1,4 +1,6 @@
-function [x,h] = minimalBoundaryOptimizedGrid(L,N,order)
+function [x,h] = minimalBoundaryOptimizedGrid(lim,N,order)
+	L = lim{2} - lim{1};
+    assert(L>0,'Limits must be given in increasing order.')
     %%%% Non-equidistant grid points %%%%%
     xb = boundaryPoints(order);
     m = length(xb)-1; % Number of non-equidistant points
@@ -11,6 +13,7 @@
 
     %%%% Define grid %%%%%%%%
     x = h*[xb; linspace(xb(end)+1,L/h-xb(end)-1,N-2*(m+1))'; L/h-flip(xb) ];
+    x = x + lim{1};
     %%%%%%%%%%%%%%%%%%%%%%%%%
 end
 
--- a/+sbp/D1Nonequidistant.m	Wed Jul 01 13:43:32 2020 +0200
+++ b/+sbp/D1Nonequidistant.m	Wed Jul 01 14:54:21 2020 +0200
@@ -19,15 +19,10 @@
             % 'Accurate' operators are optimized for accuracy
             % 'Minimal' operators have the smallest possible boundary
             %  closure
-
-            x_l = lim{1};
-            x_r = lim{2};
-            L = x_r-x_l;
-
             switch option
 
                 case {'Accurate','accurate','A'}
-                    [x,h] = sbp.util.accurateBoundaryOptimizedGrid(L,m,order);
+                    [x,h] = sbp.util.accurateBoundaryOptimizedGrid(lim,m,order);
                     if order == 4
                         [obj.D1,obj.H] = ...
                             sbp.implementations.d1_noneq_4(m,h);
@@ -48,7 +43,7 @@
                     end
 
                 case {'Minimal','minimal','M'}
-                    [x,h] = sbp.util.minimalBoundaryOptimizedGrid(L,m,order);
+                    [x,h] = sbp.util.minimalBoundaryOptimizedGrid(lim,m,order);
                     if order == 4
                         [obj.D1,obj.H] = ...
                             sbp.implementations.d1_noneq_minimal_4(m,h);
@@ -70,7 +65,7 @@
 
             end
             obj.h = h;
-            obj.x = x + x_l;
+            obj.x = x;
 
             obj.e_l = sparse(m,1);
             obj.e_r = sparse(m,1);