comparison +sbp/+grid/minimalBoundaryOptimizedGrid.m @ 1297:e53b1e25970a feature/boundary_optimized_grids

Change +sbp/+util/ to +sbp/+grid and change function names to camel case
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 07 Jul 2020 16:08:08 +0200
parents +sbp/+util/minimalBoundaryOptimizedGrid.m@e059a43bb675
children 0ffb5bfa65e4
comparison
equal deleted inserted replaced
1296:2853b655c172 1297:e53b1e25970a
1 function [x,h] = minimalBoundaryOptimizedGrid(lim,N,order)
2 assert(iscell(lim) && numel(lim) == 2,'The limits should be cell arrays with 2 elements.');
3 L = lim{2} - lim{1};
4 assert(L>0,'Limits must be given in increasing order.');
5 %%%% Non-equidistant grid points %%%%%
6 xb = boundaryPoints(order);
7 m = length(xb)-1; % Number of non-equidistant points
8 assert(N-2*(m+1)>=0,'Not enough grid points to contain the boundary region. Requires at least %d points.',2*(m+1));
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11 %%%% Compute h %%%%%%%%%%
12 h = L/(2*xb(end) + N-1-2*m);
13 %%%%%%%%%%%%%%%%%%%%%%%%%
14
15 %%%% Define grid %%%%%%%%
16 x = h*[xb; linspace(xb(end)+1,L/h-xb(end)-1,N-2*(m+1))'; L/h-flip(xb) ];
17 x = x + lim{1};
18 %%%%%%%%%%%%%%%%%%%%%%%%%
19 end
20
21 function xb = boundaryPoints(order)
22 switch order
23 case 4
24 x0 = 0.0000000000000e+00;
25 x1 = 7.7122987842562e-01;
26 xb = [x0 x1]';
27 case 6
28 x0 = 0.0000000000000e+00;
29 x1 = 4.0842950991998e-01;
30 x2 = 1.1968523189207e+00;
31 xb = [x0 x1 x2]';
32 case 8
33 x0 = 0.0000000000000e+00;
34 x1 = 4.9439570885261e-01;
35 x2 = 1.4051531374839e+00;
36 xb = [x0 x1 x2]';
37 case 10
38 x0 = 0.0000000000000e+00;
39 x1 = 5.8556160757529e-01;
40 x2 = 1.7473267488572e+00;
41 x3 = 3.0000000000000e+00;
42 xb = [x0 x1 x2 x3]';
43 case 12
44 x0 = 0.0000000000000e+00;
45 x1 = 4.6552112904489e-01;
46 x2 = 1.4647984306493e+00;
47 x3 = 2.7620429464763e+00;
48 x4 = 4.0000000000000e+00;
49 xb = [x0 x1 x2 x3 x4]';
50 otherwise
51 error('Invalid operator order %d.',order);
52 end
53 end