Mercurial > repos > public > sbplib
annotate +scheme/Schrodinger2d.m @ 912:1cdf5ead2a16 feature/utux2D
Refactor interface method for Schrodinger2d
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Sun, 25 Nov 2018 19:46:39 -0800 |
parents | b9c98661ff5d |
children | 46f5dc61d90b |
rev | line source |
---|---|
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 classdef Schrodinger2d < scheme.Scheme |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 % Discretizes the Laplacian with constant coefficent, |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
4 % in the Schrödinger equation way (i.e., the discretization matrix is not necessarily |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 % definite) |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
6 % u_t = a*i*Laplace u |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 % opSet should be cell array of opSets, one per dimension. This |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 % is useful if we have periodic BC in one direction. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 properties |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 m % Number of points in each direction, possibly a vector |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 h % Grid spacing |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
14 grid |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 dim |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 order % Order of accuracy for the approximation |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 % Diagonal matrix for variable coefficients |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 a % Constant coefficient |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 D % Total operator |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 D1 % First derivatives |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 % Second derivatives |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 D2 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 H, Hi % Inner products |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 e_l, e_r |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 d1_l, d1_r % Normal derivatives at the boundary |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
31 e_w, e_e, e_s, e_n |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
32 d_w, d_e, d_s, d_n |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
33 |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 H_boundary % Boundary inner products |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 methods |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
40 function obj = Schrodinger2d(g ,order, a, opSet) |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 default_arg('opSet',{@sbp.D2Variable, @sbp.D2Variable}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 default_arg('a',1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 dim = 2; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 assert(isa(g, 'grid.Cartesian')) |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
719
diff
changeset
|
46 if isa(a, 'function_handle') |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
719
diff
changeset
|
47 a = grid.evalOn(g, a); |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
719
diff
changeset
|
48 a = spdiag(a); |
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
719
diff
changeset
|
49 end |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 m = g.size(); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 m_tot = g.N(); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 h = g.scaling(); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 xlim = {g.x{1}(1), g.x{1}(end)}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 ylim = {g.x{2}(1), g.x{2}(end)}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 lim = {xlim, ylim}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 % 1D operators |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 ops = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 for i = 1:dim |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 ops{i} = opSet{i}(m(i), lim{i}, order); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 I = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 D1 = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 D2 = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 H = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 Hi = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 e_l = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 e_r = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
72 d1_l = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
73 d1_r = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
74 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
75 for i = 1:dim |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
76 I{i} = speye(m(i)); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
77 D1{i} = ops{i}.D1; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
78 D2{i} = ops{i}.D2; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
79 H{i} = ops{i}.H; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
80 Hi{i} = ops{i}.HI; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
81 e_l{i} = ops{i}.e_l; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
82 e_r{i} = ops{i}.e_r; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
83 d1_l{i} = ops{i}.d1_l; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
84 d1_r{i} = ops{i}.d1_r; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
85 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
86 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
87 % Constant coeff D2 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
88 for i = 1:dim |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
89 D2{i} = D2{i}(ones(m(i),1)); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
90 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
91 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
92 %====== Assemble full operators ======== |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
93 obj.D1 = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
94 obj.D2 = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
95 obj.e_l = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
96 obj.e_r = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
97 obj.d1_l = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
98 obj.d1_r = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
99 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
100 % D1 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
101 obj.D1{1} = kron(D1{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
102 obj.D1{2} = kron(I{1},D1{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
103 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
104 % Boundary operators |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
105 obj.e_l{1} = kron(e_l{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
106 obj.e_l{2} = kron(I{1},e_l{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
107 obj.e_r{1} = kron(e_r{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
108 obj.e_r{2} = kron(I{1},e_r{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
109 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
110 obj.d1_l{1} = kron(d1_l{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
111 obj.d1_l{2} = kron(I{1},d1_l{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
112 obj.d1_r{1} = kron(d1_r{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
113 obj.d1_r{2} = kron(I{1},d1_r{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
114 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
115 % D2 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
116 obj.D2{1} = kron(D2{1},I{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
117 obj.D2{2} = kron(I{1},D2{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
118 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
119 % Quadratures |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
120 obj.H = kron(H{1},H{2}); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
121 obj.Hi = inv(obj.H); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
122 obj.H_boundary = cell(dim,1); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
123 obj.H_boundary{1} = H{2}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
124 obj.H_boundary{2} = H{1}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
125 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
126 % Differentiation matrix D (without SAT) |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
127 D2 = obj.D2; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
128 D = sparse(m_tot,m_tot); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
129 for j = 1:dim |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
130 D = D + a*1i*D2{j}; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
131 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
132 obj.D = D; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
133 %=========================================% |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
134 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
135 % Misc. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
136 obj.m = m; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
137 obj.h = h; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
138 obj.order = order; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
139 obj.grid = g; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
140 obj.dim = dim; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
141 obj.a = a; |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
142 obj.e_w = obj.e_l{1}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
143 obj.e_e = obj.e_r{1}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
144 obj.e_s = obj.e_l{2}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
145 obj.e_n = obj.e_r{2}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
146 obj.d_w = obj.d1_l{1}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
147 obj.d_e = obj.d1_r{1}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
148 obj.d_s = obj.d1_l{2}; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
149 obj.d_n = obj.d1_r{2}; |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
150 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
151 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
152 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
153 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
154 % Closure functions return the operators applied to the own domain to close the boundary |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
155 % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other doamin. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
156 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
157 % type is a string specifying the type of boundary condition. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
158 % data is a function returning the data that should be applied at the boundary. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
159 % neighbour_scheme is an instance of Scheme that should be interfaced to. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
160 % neighbour_boundary is a string specifying which boundary to interface to. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
161 function [closure, penalty] = boundary_condition(obj, boundary, type, parameter) |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
162 default_arg('type','Neumann'); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
163 default_arg('parameter', []); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
164 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
165 % j is the coordinate direction of the boundary |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
166 % nj: outward unit normal component. |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
167 % nj = -1 for west, south, bottom boundaries |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
168 % nj = 1 for east, north, top boundaries |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
169 [j, nj] = obj.get_boundary_number(boundary); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
170 switch nj |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
171 case 1 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
172 e = obj.e_r; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
173 d = obj.d1_r; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
174 case -1 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
175 e = obj.e_l; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
176 d = obj.d1_l; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
177 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
178 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
179 Hi = obj.Hi; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
180 H_gamma = obj.H_boundary{j}; |
743
f4595f14d696
Change schemes to work for special coefficients.
Martin Almquist <malmquist@stanford.edu>
parents:
719
diff
changeset
|
181 a = e{j}'*obj.a*e{j}; |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
182 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
183 switch type |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
184 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
185 % Dirichlet boundary condition |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
186 case {'D','d','dirichlet','Dirichlet'} |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
187 closure = nj*Hi*d{j}*a*1i*H_gamma*(e{j}' ); |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
188 penalty = -nj*Hi*d{j}*a*1i*H_gamma; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
189 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
190 % Free boundary condition |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
191 case {'N','n','neumann','Neumann'} |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
192 closure = -nj*Hi*e{j}*a*1i*H_gamma*(d{j}' ); |
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
193 penalty = nj*Hi*e{j}*a*1i*H_gamma; |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
194 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
195 % Unknown boundary condition |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
196 otherwise |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
197 error('No such boundary condition: type = %s',type); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
198 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
199 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
200 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
201 % opts Struct that specifies the interface coupling. |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
202 % Fields: |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
203 % -- interpolation: struct of interpolation operators (empty for conforming grids) |
910
b9c98661ff5d
Change the name of the last interface method argument from type to opts in all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
905
diff
changeset
|
204 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
205 if isempty(opts) |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
206 [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
207 else |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
208 assertType(opts, 'struct'); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
209 if isfield(opts, 'I_local2neighbor') |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
210 [closure, penalty] = interfaceNonConforming(obj,boundary,neighbour_scheme,neighbour_boundary,opts); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
211 else |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
212 [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary,opts); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
213 end |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
214 end |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
215 end |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
216 |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
217 function [closure, penalty] = interfaceStandard(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
218 % u denotes the solution in the own domain |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
219 % v denotes the solution in the neighbour domain |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
220 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
221 % Get boundary operators |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
222 [e_neighbour, d_neighbour] = neighbour_scheme.get_boundary_ops(neighbour_boundary); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
223 [e, d, H_gamma] = obj.get_boundary_ops(boundary); |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
224 Hi = obj.Hi; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
225 a = obj.a; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
226 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
227 % Get outward unit normal component |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
228 [~, n] = obj.get_boundary_number(boundary); |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
229 |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
230 Hi = obj.Hi; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
231 sigma = -n*1i*a/2; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
232 tau = -n*(1i*a)'/2; |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
233 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
234 closure = tau*Hi*d*H_gamma*e' + sigma*Hi*e*H_gamma*d'; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
235 penalty = -tau*Hi*d*H_gamma*e_neighbour' ... |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
236 -sigma*Hi*e*H_gamma*d_neighbour'; |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
237 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
238 end |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
239 |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
240 function [closure, penalty] = interfaceNonConforming(obj,boundary,neighbour_scheme,neighbour_boundary,opts) |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
241 % u denotes the solution in the own domain |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
242 % v denotes the solution in the neighbour domain |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
243 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
244 % Get boundary operators |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
245 [e_neighbour, d_neighbour] = neighbour_scheme.get_boundary_ops(neighbour_boundary); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
246 [e, d, H_gamma] = obj.get_boundary_ops(boundary); |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
247 Hi = obj.Hi; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
248 a = obj.a; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
249 |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
250 % Get outward unit normal component |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
251 [~, n] = obj.get_boundary_number(boundary); |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
252 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
253 % Get interpolation operators from opts |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
254 I_u2v_good = opts.I_local2neighbor.good; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
255 I_u2v_bad = opts.I_local2neighbor.bad; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
256 I_v2u_good = opts.I_neighbor2local.good; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
257 I_v2u_bad = opts.I_neighbor2local.bad; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
258 |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
259 sigma = -n*1i*a/2; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
260 tau = -n*(1i*a)'/2; |
719
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
261 |
b3f8fb9cefd2
Add interpolation to Schrödinger 2D scheme.
Martin Almquist <malmquist@stanford.edu>
parents:
718
diff
changeset
|
262 closure = tau*Hi*d*H_gamma*e' + sigma*Hi*e*H_gamma*d'; |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
263 penalty = -tau*Hi*d*H_gamma*I_v2u_good*e_neighbour' ... |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
264 -sigma*Hi*e*H_gamma*I_v2u_bad*d_neighbour'; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
743
diff
changeset
|
265 |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
266 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
267 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
268 % Returns the coordinate number and outward normal component for the boundary specified by the string boundary. |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
269 function [j, nj] = get_boundary_number(obj, boundary) |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
270 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
271 switch boundary |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
272 case {'w','W','west','West', 'e', 'E', 'east', 'East'} |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
273 j = 1; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
274 case {'s','S','south','South', 'n', 'N', 'north', 'North'} |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
275 j = 2; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
276 otherwise |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
277 error('No such boundary: boundary = %s',boundary); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
278 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
279 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
280 switch boundary |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
281 case {'w','W','west','West','s','S','south','South'} |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
282 nj = -1; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
283 case {'e', 'E', 'east', 'East','n', 'N', 'north', 'North'} |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
284 nj = 1; |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
285 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
286 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
287 |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
288 % Returns the boundary ops and sign for the boundary specified by the string boundary. |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
289 % The right boundary is considered the positive boundary |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
290 function [e, d, H_b] = get_boundary_ops(obj, boundary) |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
291 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
292 switch boundary |
912
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
293 case 'w' |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
294 e = obj.e_w; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
295 d = obj.d_w; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
296 H_b = obj.H_boundary{1}; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
297 case 'e' |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
298 e = obj.e_e; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
299 d = obj.d_e; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
300 H_b = obj.H_boundary{1}; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
301 case 's' |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
302 e = obj.e_s; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
303 d = obj.d_s; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
304 H_b = obj.H_boundary{2}; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
305 case 'n' |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
306 e = obj.e_n; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
307 d = obj.d_n; |
1cdf5ead2a16
Refactor interface method for Schrodinger2d
Martin Almquist <malmquist@stanford.edu>
parents:
910
diff
changeset
|
308 H_b = obj.H_boundary{2}; |
718
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
309 otherwise |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
310 error('No such boundary: boundary = %s',boundary); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
311 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
312 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
313 |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
314 function N = size(obj) |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
315 N = prod(obj.m); |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
316 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
317 end |
71aa5828cbbf
Add Schrödinger scheme for 2d single block. Will develop to multiblock with interpolation.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
318 end |