Mercurial > repos > public > sbplib
comparison +sbp/+implementations/d1_noneq_minimal_4.m @ 1286:4cb627c7fb90 feature/boundary_optimized_grids
Make D1Nonequidistant use the grid generation functions accurate/minimalBoundaryOptimizedGrid and remove grid generation from +implementations
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 01 Jul 2020 13:43:32 +0200 |
parents | f7ac3cd6eeaa |
children |
comparison
equal
deleted
inserted
replaced
1285:6b68f939d023 | 1286:4cb627c7fb90 |
---|---|
1 function [D1,H,x,h] = d1_noneq_minimal_4(N,L) | 1 function [D1,H] = d1_noneq_minimal_4(N,h) |
2 | 2 |
3 % L: Domain length | |
4 % N: Number of grid points | 3 % N: Number of grid points |
5 if(nargin < 2) | |
6 L = 1; | |
7 end | |
8 | |
9 if(N<6) | 4 if(N<6) |
10 error('Operator requires at least 6 grid points'); | 5 error('Operator requires at least 6 grid points'); |
11 end | 6 end |
12 | 7 |
13 % BP: Number of boundary points | 8 % BP: Number of boundary points |
14 % m: Number of nonequidistant spacings | |
15 % order: Accuracy of interior stencil | |
16 BP = 3; | 9 BP = 3; |
17 m = 1; | |
18 order = 4; | |
19 | |
20 %%%% Non-equidistant grid points %%%%% | |
21 x0 = 0.0000000000000e+00; | |
22 x1 = 7.7122987842562e-01; | |
23 x2 = 1.7712298784256e+00; | |
24 x3 = 2.7712298784256e+00; | |
25 | |
26 xb = sparse(m+1,1); | |
27 for i = 0:m | |
28 xb(i+1) = eval(['x' num2str(i)]); | |
29 end | |
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
31 | |
32 %%%% Compute h %%%%%%%%%% | |
33 h = L/(2*xb(end) + N-1-2*m); | |
34 %%%%%%%%%%%%%%%%%%%%%%%%% | |
35 | |
36 %%%% Define grid %%%%%%%% | |
37 x = h*[xb; linspace(xb(end)+1,L/h-xb(end)-1,N-2*(m+1))'; L/h-flip(xb) ]; | |
38 %%%%%%%%%%%%%%%%%%%%%%%%% | |
39 | 10 |
40 %%%% Norm matrix %%%%%%%% | 11 %%%% Norm matrix %%%%%%%% |
41 P = sparse(BP,1); | 12 P = sparse(BP,1); |
42 %#ok<*NASGU> | 13 %#ok<*NASGU> |
43 P0 = 2.6864248295847e-01; | 14 P0 = 2.6864248295847e-01; |
53 H(end-BP+1:end) = flip(P); | 24 H(end-BP+1:end) = flip(P); |
54 H = spdiags(h*H,0,N,N); | 25 H = spdiags(h*H,0,N,N); |
55 %%%%%%%%%%%%%%%%%%%%%%%%% | 26 %%%%%%%%%%%%%%%%%%%%%%%%% |
56 | 27 |
57 %%%% Q matrix %%%%%%%%%%% | 28 %%%% Q matrix %%%%%%%%%%% |
58 | |
59 % interior stencil | 29 % interior stencil |
60 switch order | 30 order = 4; |
61 case 2 | 31 d = [1/12,-2/3,0,2/3,-1/12]; |
62 d = [-1/2,0,1/2]; | |
63 case 4 | |
64 d = [1/12,-2/3,0,2/3,-1/12]; | |
65 case 6 | |
66 d = [-1/60,3/20,-3/4,0,3/4,-3/20,1/60]; | |
67 case 8 | |
68 d = [1/280,-4/105,1/5,-4/5,0,4/5,-1/5,4/105,-1/280]; | |
69 case 10 | |
70 d = [-1/1260,5/504,-5/84,5/21,-5/6,0,5/6,-5/21,5/84,-5/504,1/1260]; | |
71 case 12 | |
72 d = [1/5544,-1/385,1/56,-5/63,15/56,-6/7,0,6/7,-15/56,5/63,-1/56,1/385,-1/5544]; | |
73 end | |
74 d = repmat(d,N,1); | 32 d = repmat(d,N,1); |
75 Q = spdiags(d,-order/2:order/2,N,N); | 33 Q = spdiags(d,-order/2:order/2,N,N); |
76 | 34 |
77 % Boundaries | 35 % Boundaries |
78 Q0_0 = -5.0000000000000e-01; | 36 Q0_0 = -5.0000000000000e-01; |