Mercurial > repos > public > sbplib
annotate +sbp/+implementations/d2_2.m @ 267:f7ac3cd6eeaa operator_remake
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Fri, 09 Sep 2016 14:53:41 +0200 |
parents | bfa130b7abf6 |
children | 8b8672134be8 |
rev | line source |
---|---|
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
1 function [H, HI, D1, D2, e_1, e_m, M, Q, S_1, S_m] = d2_2(m,h) |
266
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
2 |
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
3 BP = 1; |
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
4 if(m<2*BP) |
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
5 error(['Operator requires at least ' num2str(2*BP) ' grid points']); |
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
6 end |
bfa130b7abf6
Added error message for too few grid points to all implementation files.
Martin Almquist <martin.almquist@it.uu.se>
parents:
261
diff
changeset
|
7 |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
8 e_1=sparse(m,1);e_1(1)=1; |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
9 e_m=sparse(m,1);e_m(m)=1; |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
10 |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
11 H=(speye(m,m));H(1,1)=0.5;H(m,m)=0.5; |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
12 H=h*H; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
13 HI=inv(H); |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
14 |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
15 diags = -1:1; |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
16 stencil = [-1/2 0 1/2]; |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
17 D1 = stripeMatrix(stencil, diags, m); |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
18 |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
19 D1(1,1)=-1;D1(1,2)=1;D1(m,m-1)=-1;D1(m,m)=1; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
20 D1(m,m-1)=-1;D1(m,m)=1; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
21 D1=D1/h; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
22 |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
23 Q=H*D1 + 1/2*(e_1*e_1') - 1/2*(e_m*e_m'); |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
24 |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
25 diags = -1:1; |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
26 stencil = [1 -2 1]; |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
27 D2 = stripeMatrix(stencil, diags, m); |
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
28 |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
29 D2(1,1)=1;D2(1,2)=-2;D2(1,3)=1; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
30 D2(m,m-2)=1;D2(m,m-1)=-2;D2(m,m)=1; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
31 D2=D2/h^2; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
32 |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
33 S_U=[-3/2, 2, -1/2]/h; |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
34 S_1=sparse(1,m); |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
35 S_1(1:3)=S_U; |
267
f7ac3cd6eeaa
Sparsified all implementation files, removed all matlab warnings, fixed small bugs on minimum grid points.
Martin Almquist <martin.almquist@it.uu.se>
parents:
266
diff
changeset
|
36 S_m=sparse(1,m); |
261
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
37 S_m(m-2:m)=fliplr(-S_U); |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
38 |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
39 |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
40 M=-H*D2-e_1*S_1+e_m*S_m; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
41 S_1 = S_1'; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
42 S_m = S_m'; |
6009f2712d13
Moved and renamned all implementations.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff
changeset
|
43 end |