Mercurial > repos > public > sbplib
annotate +sbp/+implementations/d2_variable_hollow_2.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 |
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_2(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 = 1; |
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 % Norm |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 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
|
10 Hv(1) = 1/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 Hv(m:m) = 1/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 Hv = h*Hv; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 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
|
14 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
|
15 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 % Boundary operators |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 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
|
23 d1_l(1:3) = 1/h*[-3/2 2 -1/2]; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 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
|
25 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 % D1 operator |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 diags = -1:1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 stencil = [-1/2 0 1/2]; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 D1 = 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
|
30 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 D1(1,1)=-1;D1(1,2)=1;D1(m,m-1)=-1;D1(m,m)=1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
32 D1(m,m-1)=-1;D1(m,m)=1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 D1=D1/h; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 %Q=H*D1 + 1/2*(e_1*e_1') - 1/2*(e_m*e_m'); |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 |
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 nBP = 2; |
1305
b5907140c069
Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents:
1303
diff
changeset
|
38 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
|
39 coeffs = load('sbplib/+sbp/+implementations/coeffs_d2_variable_2.mat'); |
1303
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 function D2 = D2_fun(c) |
1305
b5907140c069
Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents:
1303
diff
changeset
|
42 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
|
43 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
|
44 |
1305
b5907140c069
Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents:
1303
diff
changeset
|
45 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
|
46 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
|
47 M_r = M_r + coeffs.C_r{i}*c(m-coeffs.nBPC+i); |
1303
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 end |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 |
1305
b5907140c069
Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents:
1303
diff
changeset
|
50 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
|
51 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
|
52 |
1305
b5907140c069
Clean up hollow D2 generation by using precomputed coefficients stored in mat files
Martin Almquist <malmquist@stanford.edu>
parents:
1303
diff
changeset
|
53 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
|
54 end |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 D2 = @D2_fun; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 end |