Mercurial > repos > public > sbplib
annotate +sbp/D1UpwindCompatible.m @ 1344:b4e5e45bd239 feature/D2_boundary_opt
Remove round off zeros from D2Nonequidistant operators
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sat, 15 Oct 2022 15:48:20 +0200 |
parents | 5fa2f62a58a1 |
children |
rev | line source |
---|---|
1269
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 classdef D1UpwindCompatible < sbp.OpSet |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 properties |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 Dp, Dm % SBP operator approximating first derivative |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 H % Norm matrix |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 HI % H^-1 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
6 e_l % Left boundary operator |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 e_r % Right boundary operator |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 m % Number of grid points. |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 h % Step size |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 x % grid |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 borrowing % Struct with borrowing limits for different norm matrices |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
14 methods |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 function obj = D1UpwindCompatible(m,lim,order) |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 x_l = lim{1}; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 x_r = lim{2}; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 L = x_r-x_l; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 obj.h = L/(m-1); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 obj.x = linspace(x_l,x_r,m)'; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 ops = sbp.D2Standard(m, lim, order); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 D1 = ops.D1; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 H = ops.H; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 obj.H = H; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 obj.HI = inv(H); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 obj.e_l = ops.e_l; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 obj.e_r = ops.e_r; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
32 switch order |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 case 2 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 ops = sbp.D2Standard(m, lim, 2); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 Dp = D1 + obj.h^1*1/2*(H\ops.M); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 Dm = D1 - obj.h^1*1/2*(H\ops.M); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 case 4 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 ops = sbp.D4Variable(m, lim, 2); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 Dp = D1 - obj.h^3*1/12*(H\ops.M4); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 Dm = D1 + obj.h^3*1/12*(H\ops.M4); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 otherwise |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 error('Invalid operator order %d.',order); |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 obj.Dp = Dp; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 obj.Dm = Dm; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 obj.m = m; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 obj.borrowing = []; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 function str = string(obj) |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 str = [class(obj) '_' num2str(obj.order)]; |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 end |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 |
5fa2f62a58a1
Add class for upwind D1 based on the standard norm matrices
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 |