Mercurial > repos > public > sbplib
annotate +sbp/D2VariableCompatible.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 | |
children | a3d9567d9004 |
rev | line source |
---|---|
1198
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 classdef D2VariableCompatible < sbp.OpSet |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 properties |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 D1 % SBP operator approximating first derivative |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 H % Norm matrix |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 HI % H^-1 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
6 Q % Skew-symmetric matrix |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 e_l % Left boundary operator |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 e_r % Right boundary operator |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 D2 % SBP operator for second derivative |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 M % Norm matrix, second derivative |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 d1_l % Left boundary first derivative |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 d1_r % Right boundary first derivative |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 m % Number of grid points. |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
14 h % Step size |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 x % grid |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 borrowing % Struct with borrowing limits for different norm matrices |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 methods |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 function obj = D2VariableCompatible(m,lim,order) |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 x_l = lim{1}; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 x_r = lim{2}; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 L = x_r-x_l; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 obj.h = L/(m-1); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 obj.x = linspace(x_l,x_r,m)'; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 switch order |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 case 6 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
32 [obj.H, obj.HI, obj.D1, D2, ... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 ~, obj.e_l, obj.e_r, ~, ~, ~, ~, ~,... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 d1_l, d1_r] = ... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 sbp.implementations.d4_variable_6(m, obj.h); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 case 4 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 [obj.H, obj.HI, obj.D1, D2, obj.e_l,... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 obj.e_r, d1_l, d1_r] = ... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 sbp.implementations.d2_variable_4(m,obj.h); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 case 2 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 [obj.H, obj.HI, obj.D1, D2, obj.e_l,... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 obj.e_r, d1_l, d1_r] = ... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 sbp.implementations.d2_variable_2(m,obj.h); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 otherwise |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 error('Invalid operator order %d.',order); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 obj.borrowing.H11 = obj.H(1,1)/obj.h; % First element in H/h, |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 obj.borrowing.M.d1 = obj.H(1,1)/obj.h; % First element in H/h is borrowing also for M |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 obj.borrowing.R.delta_D = inf; % Because delta_D is zero, one can borrow infinitely much. |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 % This sets penalties of the form 1/borrowing to 0, which is |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 % the desired behaviour. |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 obj.m = m; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 obj.M = []; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 D1 = obj.D1; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 e_r = obj.e_r; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 e_l = obj.e_l; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 % D2 = Hinv * (-M + br*er*d1r^T - bl*el*d1l^T); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 % Replace d1' by e'*D1 in D2. |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 D2_compatible = @(b) D2(b) - obj.HI*(b(m)*e_r*d1_r' - b(m)*e_r*e_r'*D1) ... |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 + obj.HI*(b(1)*e_l*d1_l' - b(1)*e_l*e_l'*D1); |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 obj.D2 = D2_compatible; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 obj.d1_l = (e_l'*D1)'; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 obj.d1_r = (e_r'*D1)'; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 function str = string(obj) |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
72 str = [class(obj) '_' num2str(obj.order)]; |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
73 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
74 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
75 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
76 end |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
77 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
78 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
79 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
80 |
2924b3a9b921
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.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
81 |