Mercurial > repos > public > sbplib
annotate +sbp/+implementations/d2_variable_hollow_2.m @ 1303:49e3870335ef feature/poroelastic
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Sat, 11 Jul 2020 06:54:15 -0700 |
parents | |
children | b5907140c069 |
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 M=sparse(m,m); |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 nBP = 2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 scheme_width = 3; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 scheme_radius = (scheme_width-1)/2; |
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 function D2 = D2_fun(c) |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 for r = 1+scheme_radius:nBP |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 Mm1 = -c(r-1)/2 - c(r)/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 M0 = c(r-1)/2 + c(r) + c(r+1)/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 Mp1 = -c(r)/2 - c(r+1)/2; |
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 M(r, r-1) = Mm1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 M(r, r) = M0; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 M(r, r+1) = Mp1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 end |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 for r = m-nBP+1:m-scheme_radius |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 Mm1 = -c(r-1)/2 - c(r)/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 M0 = c(r-1)/2 + c(r) + c(r+1)/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 Mp1 = -c(r)/2 - c(r+1)/2; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 M(r, r-1) = Mm1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 M(r, r) = M0; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 M(r, r+1) = Mp1; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 end |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 M(1:2,1:2)=[c(1)/2 + c(2)/2 -c(1)/2 - c(2)/2; -c(1)/2 - c(2)/2 c(1)/2 + c(2) + c(3)/2;]; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 M(m-1:m,m-1:m)=[c(m-2)/2 + c(m-1) + c(m)/2 -c(m-1)/2 - c(m)/2; -c(m-1)/2 - c(m)/2 c(m-1)/2 + c(m)/2;]; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 M=M/h; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 D2=HI*(-M-c(1)*e_l*d1_l'+c(m)*e_r*d1_r'); |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 end |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 D2 = @D2_fun; |
49e3870335ef
Make the hollow scheme generation more efficient by introducing the D2VariableHollow opSet
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
72 end |