Mercurial > repos > public > sbplib
annotate +sbp/D2Variable.m @ 1198:2924b3a9b921 feature/d2_compatible
Add OpSet for fully compatible D2Variable, created from regular D2Variable by replacing d1 by first row of D1. Formal reduction by one order of accuracy at the boundary point.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Fri, 16 Aug 2019 14:30:28 -0700 |
parents | 52a9dedb9171 |
children | 738de3a4058b |
rev | line source |
---|---|
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
1 classdef D2Variable < sbp.OpSet |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
2 properties |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
3 D1 % SBP operator approximating first derivative |
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
4 H % Norm matrix |
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
5 HI % H^-1 |
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
6 Q % Skew-symmetric matrix |
268
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
7 e_l % Left boundary operator |
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
8 e_r % Right boundary operator |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
9 D2 % SBP operator for second derivative |
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
10 M % Norm matrix, second derivative |
268
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
11 d1_l % Left boundary first derivative |
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
12 d1_r % Right boundary first derivative |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
13 m % Number of grid points. |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
14 h % Step size |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
15 x % grid |
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
16 borrowing % Struct with borrowing limits for different norm matrices |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
17 end |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
18 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
19 methods |
264
8a625c5a3633
Changed input parameter L (domain length) to lim (cell with domain boundaries)
Martin Almquist <martin.almquist@it.uu.se>
parents:
263
diff
changeset
|
20 function obj = D2Variable(m,lim,order) |
336
f36d172e196b
Added missing string method.
Jonatan Werpers <jonatan@werpers.com>
parents:
268
diff
changeset
|
21 |
264
8a625c5a3633
Changed input parameter L (domain length) to lim (cell with domain boundaries)
Martin Almquist <martin.almquist@it.uu.se>
parents:
263
diff
changeset
|
22 x_l = lim{1}; |
8a625c5a3633
Changed input parameter L (domain length) to lim (cell with domain boundaries)
Martin Almquist <martin.almquist@it.uu.se>
parents:
263
diff
changeset
|
23 x_r = lim{2}; |
8a625c5a3633
Changed input parameter L (domain length) to lim (cell with domain boundaries)
Martin Almquist <martin.almquist@it.uu.se>
parents:
263
diff
changeset
|
24 L = x_r-x_l; |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
25 obj.h = L/(m-1); |
264
8a625c5a3633
Changed input parameter L (domain length) to lim (cell with domain boundaries)
Martin Almquist <martin.almquist@it.uu.se>
parents:
263
diff
changeset
|
26 obj.x = linspace(x_l,x_r,m)'; |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
27 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
28 switch order |
670
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
29 |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
30 case 6 |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
31 |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
32 [obj.H, obj.HI, obj.D1, obj.D2, ... |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
33 ~, obj.e_l, obj.e_r, ~, ~, ~, ~, ~,... |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
34 obj.d1_l, obj.d1_r] = ... |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
35 sbp.implementations.d4_variable_6(m, obj.h); |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
36 obj.borrowing.M.d1 = 0.1878; |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
37 obj.borrowing.R.delta_D = 0.3696; |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
38 % Borrowing e^T*D1 - d1 from R |
52a9dedb9171
Add 6th order to D2variable.
Martin Almquist <malmquist@stanford.edu>
parents:
668
diff
changeset
|
39 |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
40 case 4 |
268
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
41 [obj.H, obj.HI, obj.D1, obj.D2, obj.e_l,... |
4b9310edcdf8
Renamned boundary operators!
Martin Almquist <martin.almquist@it.uu.se>
parents:
264
diff
changeset
|
42 obj.e_r, obj.d1_l, obj.d1_r] = ... |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
43 sbp.implementations.d2_variable_4(m,obj.h); |
389
42c89b5eedc0
Add borrowing constants for D2 operators in D4Variable
Jonatan Werpers <jonatan@werpers.com>
parents:
336
diff
changeset
|
44 obj.borrowing.M.d1 = 0.2505765857; |
668
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
45 |
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
46 obj.borrowing.R.delta_D = 0.577587500088313; |
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
47 % Borrowing e^T*D1 - d1 from R |
362
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
48 case 2 |
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
49 [obj.H, obj.HI, obj.D1, obj.D2, obj.e_l,... |
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
50 obj.e_r, obj.d1_l, obj.d1_r] = ... |
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
51 sbp.implementations.d2_variable_2(m,obj.h); |
395 | 52 obj.borrowing.M.d1 = 0.3636363636; |
362
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
53 % Borrowing const taken from Virta 2014 |
668
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
54 |
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
55 obj.borrowing.R.delta_D = 1.000000538455350; |
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
56 % Borrowing e^T*D1 - d1 from R |
362
ded4156e53e2
Added 2nd order accurate 2nd derivative with variable coefficents in a separate implementation file, used by the class D2Variable.
Martin Almquist <martin.almquist@it.uu.se>
parents:
268
diff
changeset
|
57 |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
58 otherwise |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
59 error('Invalid operator order %d.',order); |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
60 end |
668
43ea848b6aa1
Add borrowing constants to D2variable
Martin Almquist <malmquist@stanford.edu>
parents:
395
diff
changeset
|
61 obj.borrowing.H11 = obj.H(1,1)/obj.h; % First element in H/h, |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
62 obj.m = m; |
263
21a180acbd49
Renamed standard class to D2Standard etc, Rewrote class properties.
Martin Almquist <martin.almquist@it.uu.se>
parents:
262
diff
changeset
|
63 obj.M = []; |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
64 end |
336
f36d172e196b
Added missing string method.
Jonatan Werpers <jonatan@werpers.com>
parents:
268
diff
changeset
|
65 function str = string(obj) |
f36d172e196b
Added missing string method.
Jonatan Werpers <jonatan@werpers.com>
parents:
268
diff
changeset
|
66 str = [class(obj) '_' num2str(obj.order)]; |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
67 end |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
68 end |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
69 |
336
f36d172e196b
Added missing string method.
Jonatan Werpers <jonatan@werpers.com>
parents:
268
diff
changeset
|
70 |
252
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
71 end |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
72 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
73 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
74 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
75 |
07fa0d6a05bb
Renamned class files and added nonequidistant operators.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
76 |