annotate +sbp/+implementations/d2_variable_hollow_4.m @ 1337:bf2554f1825d feature/D2_boundary_opt

Add periodic D1 and D2 operators for orders 8,10,12
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 13 May 2022 13:28:10 +0200
parents b5907140c069
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
1 function [H, HI, D1, D2, e_l, e_r, d1_l, d1_r] = d2_variable_hollow_4(m,h)
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
2
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
3 BP = 6;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
4 if(m<2*BP)
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
5 error(['Operator requires at least ' num2str(2*BP) ' grid points']);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
6 end
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
7
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
8
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
9
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
10
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
11 % Norm
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
12 Hv = ones(m,1);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
13 Hv(1:4) = [17/48 59/48 43/48 49/48];
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
14 Hv(m-3:m) = rot90(Hv(1:4),2);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
15 Hv = h*Hv;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
16 H = spdiag(Hv, 0);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
17 HI = spdiag(1./Hv, 0);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
18
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
19
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
20 % Boundary operators
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
21 e_l = sparse(m,1);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
22 e_l(1) = 1;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
23 e_r = rot90(e_l, 2);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
24
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
25 d1_l = sparse(m,1);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
26 d1_l(1:4) = 1/h*[-11/6 3 -3/2 1/3];
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
27 d1_r = -rot90(d1_l, 2);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
28
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
29
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
30
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
31
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
32 S = d1_l*d1_l' + d1_r*d1_r';
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
33
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
34 stencil = [1/12 -2/3 0 2/3 -1/12];
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
35 diags = -2:2;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
36
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
37 Q_U = [
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
38 0 0.59e2/0.96e2 -0.1e1/0.12e2 -0.1e1/0.32e2;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
39 -0.59e2/0.96e2 0 0.59e2/0.96e2 0;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
40 0.1e1/0.12e2 -0.59e2/0.96e2 0 0.59e2/0.96e2;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
41 0.1e1/0.32e2 0 -0.59e2/0.96e2 0;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
42 ];
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
43
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
44 Q = stripeMatrix(stencil, diags, m);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
45 Q(1:4,1:4) = Q_U;
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
46 Q(m-3:m,m-3:m) = -rot90(Q_U, 2);
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
47
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
48 D1 = HI*(Q - 1/2*e_l*e_l' + 1/2*e_r*e_r');
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
49
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
50
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
51 % Second derivative
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
52 nBP = 6;
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
53 M = sparse(m,m);
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
54 coeffs = load('sbplib/+sbp/+implementations/coeffs_d2_variable_4.mat');
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
55
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
56 function D2 = D2_fun(c)
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
57 M_l = zeros(nBP, coeffs.nBPC);
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
58 M_r = zeros(nBP, coeffs.nBPC);
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
59
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
60 for i=1:coeffs.nBPC
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
61 M_l = M_l + coeffs.C_l{i}*c(i);
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
62 M_r = M_r + coeffs.C_r{i}*c(m-coeffs.nBPC+i);
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
63 end
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
64
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
65 M(1:nBP, 1:coeffs.nBPC) = M_l;
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
66 M(m-nBP+1:m, m-coeffs.nBPC+1:m) = M_r;
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
67
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
68 D2 = M/h^2;
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
69 end
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
70 D2 = @D2_fun;
1305
b5907140c069 Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents: 1303
diff changeset
71
1303
49e3870335ef Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
72 end