Mercurial > repos > public > sbplib
annotate +sbp/D2VariablePeriodic.m @ 1037:2d7ba44340d0 feature/burgers1d
Pass scheme specific parameters as cell array. This will enabale constructDiffOps to be more general. In addition, allow for schemes returning function handles as diffOps, which is currently how non-linear schemes such as Burgers1d are implemented.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 18 Jan 2019 09:02:02 +0100 |
parents | 5ccf6aaf6d6b |
children | bf2554f1825d |
rev | line source |
---|---|
681
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 classdef D2VariablePeriodic < sbp.OpSet |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 properties |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 D1 % SBP operator approximating first derivative |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 H % Norm matrix |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 HI % H^-1 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
6 Q % Skew-symmetric matrix |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 e_l % Left boundary operator |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 e_r % Right boundary operator |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 D2 % SBP operator for second derivative |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 M % Norm matrix, second derivative |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 d1_l % Left boundary first derivative |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 d1_r % Right boundary first derivative |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 m % Number of grid points. |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
14 h % Step size |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 x % grid |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 borrowing % Struct with borrowing limits for different norm matrices |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 end |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 methods |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 function obj = D2VariablePeriodic(m,lim,order) |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 x_l = lim{1}; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 x_r = lim{2}; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 L = x_r-x_l; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 obj.h = L/m; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 x = linspace(x_l,x_r,m+1)'; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 obj.x = x(1:end-1); |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 switch order |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 case 6 |
686
5ccf6aaf6d6b
Add D2VariablePeriodic orders 4 and 6.
Martin Almquist <malmquist@stanford.edu>
parents:
681
diff
changeset
|
32 [obj.H, obj.HI, obj.D1, obj.D2, obj.e_l,... |
5ccf6aaf6d6b
Add D2VariablePeriodic orders 4 and 6.
Martin Almquist <malmquist@stanford.edu>
parents:
681
diff
changeset
|
33 obj.e_r, obj.d1_l, obj.d1_r] = ... |
5ccf6aaf6d6b
Add D2VariablePeriodic orders 4 and 6.
Martin Almquist <malmquist@stanford.edu>
parents:
681
diff
changeset
|
34 sbp.implementations.d2_variable_periodic_6(m,obj.h); |
681
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 obj.borrowing.M.d1 = 0.1878; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 obj.borrowing.R.delta_D = 0.3696; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 % Borrowing e^T*D1 - d1 from R |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 case 4 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 [obj.H, obj.HI, obj.D1, obj.D2, obj.e_l,... |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 obj.e_r, obj.d1_l, obj.d1_r] = ... |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 sbp.implementations.d2_variable_periodic_4(m,obj.h); |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 obj.borrowing.M.d1 = 0.2505765857; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 obj.borrowing.R.delta_D = 0.577587500088313; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 % Borrowing e^T*D1 - d1 from R |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 case 2 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 [obj.H, obj.HI, obj.D1, obj.D2, obj.e_l,... |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 obj.e_r, obj.d1_l, obj.d1_r] = ... |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 sbp.implementations.d2_variable_periodic_2(m,obj.h); |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 obj.borrowing.M.d1 = 0.3636363636; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 % Borrowing const taken from Virta 2014 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 obj.borrowing.R.delta_D = 1.000000538455350; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 % Borrowing e^T*D1 - d1 from R |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 otherwise |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 error('Invalid operator order %d.',order); |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 end |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 obj.borrowing.H11 = obj.H(1,1)/obj.h; % First element in H/h, |
686
5ccf6aaf6d6b
Add D2VariablePeriodic orders 4 and 6.
Martin Almquist <malmquist@stanford.edu>
parents:
681
diff
changeset
|
61 |
681
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 obj.m = m; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 obj.M = []; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 end |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 function str = string(obj) |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 str = [class(obj) '_' num2str(obj.order)]; |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 end |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 end |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 |
7368affc8f78
Add D2 variable periodic for second order.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 end |