Mercurial > repos > public > sbplib
annotate +scheme/Schrodinger.m @ 490:b13d44271ead feature/quantumTriangles
Schrodinger2dCurve Added
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Thu, 09 Feb 2017 11:41:21 +0100 |
parents | a39fe3bcbd95 |
children | b91d23271481 |
rev | line source |
---|---|
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
1 classdef Schrodinger < scheme.Scheme |
0 | 2 properties |
3 m % Number of points in each direction, possibly a vector | |
4 h % Grid spacing | |
5 x % Grid | |
6 order % Order accuracy for the approximation | |
428
a39fe3bcbd95
Changed so that the shrodinger scheme works with the grids
Ylva Rydin <ylva.rydin@telia.com>
parents:
426
diff
changeset
|
7 grid |
a39fe3bcbd95
Changed so that the shrodinger scheme works with the grids
Ylva Rydin <ylva.rydin@telia.com>
parents:
426
diff
changeset
|
8 |
0 | 9 D % non-stabalized scheme operator |
10 H % Discrete norm | |
11 M % Derivative norm | |
12 alpha | |
13 | |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
14 D2 |
0 | 15 Hi |
16 e_l | |
17 e_r | |
18 d1_l | |
19 d1_r | |
20 gamm | |
21 end | |
22 | |
23 methods | |
24 % Solving SE in the form u_t = i*u_xx -i*V; | |
25 function obj = Schrodinger(m,xlim,order,V) | |
26 default_arg('V',0); | |
426
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
27 ops = sbp.D2Standard(m,xlim,order); |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
28 |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
29 obj.x=ops.x; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
30 obj.h=ops.h; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
31 obj.D2 = ops.D2; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
32 obj.H = ops.H; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
33 obj.Hi = ops.HI; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
34 obj.M = ops.M; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
35 obj.e_l = ops.e_l; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
36 obj.e_r = ops.e_r; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
37 obj.d1_l = ops.d1_l; |
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
38 obj.d1_r = ops.d1_r; |
0 | 39 |
40 | |
41 if isa(V,'function_handle') | |
426
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
42 V_vec = V(obj.x); |
0 | 43 else |
426
29944ea7674b
Updated the Shrodinger scheme to the new operator syntax
Ylva Rydin <ylva.rydin@telia.com>
parents:
67
diff
changeset
|
44 V_vec = obj.x*0 + V; |
0 | 45 end |
46 | |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
47 V_mat = spdiags(V_vec,0,m,m); |
0 | 48 |
67
446d67a49cd8
Fixed some errors in scheme.Schrodinger.m
Jonatan Werpers <jonatan@werpers.com>
parents:
65
diff
changeset
|
49 obj.D = 1i * obj.D2 - 1i * V_mat; |
0 | 50 |
51 obj.m = m; | |
52 obj.order = order; | |
53 end | |
54 | |
55 | |
56 % Closure functions return the opertors applied to the own doamin to close the boundary | |
57 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. | |
58 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. | |
59 % type is a string specifying the type of boundary condition if there are several. | |
60 % data is a function returning the data that should be applied at the boundary. | |
61 % neighbour_scheme is an instance of Scheme that should be interfaced to. | |
62 % neighbour_boundary is a string specifying which boundary to interface to. | |
63 function [closure, penalty] = boundary_condition(obj,boundary,type,data) | |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
64 default_arg('type','dirichlet'); |
0 | 65 default_arg('data',0); |
66 | |
67 [e,d,s] = obj.get_boundary_ops(boundary); | |
68 | |
69 switch type | |
70 % Dirichlet boundary condition | |
71 case {'D','d','dirichlet'} | |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
72 tau = s * 1i*d; |
0 | 73 closure = obj.Hi*tau*e'; |
74 | |
75 switch class(data) | |
76 case 'double' | |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
77 penalty = -obj.Hi*tau*data; |
0 | 78 case 'function_handle' |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
79 penalty = @(t)-obj.Hi*tau*data(t); |
0 | 80 otherwise |
81 error('Wierd data argument!') | |
82 end | |
83 | |
84 % Unknown, boundary condition | |
85 otherwise | |
86 error('No such boundary condition: type = %s',type); | |
87 end | |
88 end | |
89 | |
90 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary) | |
91 % u denotes the solution in the own domain | |
92 % v denotes the solution in the neighbour domain | |
93 [e_u,d_u,s_u] = obj.get_boundary_ops(boundary); | |
94 [e_v,d_v,s_v] = neighbour_scheme.get_boundary_ops(neighbour_boundary); | |
95 | |
67
446d67a49cd8
Fixed some errors in scheme.Schrodinger.m
Jonatan Werpers <jonatan@werpers.com>
parents:
65
diff
changeset
|
96 a = -s_u* 1/2 * 1i ; |
65
33f0654a2413
Fixed mistakes in Schrodinger scheme. BC are now working.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
97 b = a'; |
0 | 98 |
99 tau = b*d_u; | |
67
446d67a49cd8
Fixed some errors in scheme.Schrodinger.m
Jonatan Werpers <jonatan@werpers.com>
parents:
65
diff
changeset
|
100 sig = -a*e_u; |
0 | 101 |
102 closure = obj.Hi * (tau*e_u' + sig*d_u'); | |
103 penalty = obj.Hi * (-tau*e_v' - sig*d_v'); | |
104 end | |
105 | |
106 % Ruturns the boundary ops and sign for the boundary specified by the string boundary. | |
107 % The right boundary is considered the positive boundary | |
108 function [e,d,s] = get_boundary_ops(obj,boundary) | |
109 switch boundary | |
110 case 'l' | |
111 e = obj.e_l; | |
112 d = obj.d1_l; | |
113 s = -1; | |
114 case 'r' | |
115 e = obj.e_r; | |
116 d = obj.d1_r; | |
117 s = 1; | |
118 otherwise | |
119 error('No such boundary: boundary = %s',boundary); | |
120 end | |
121 end | |
122 | |
123 function N = size(obj) | |
124 N = obj.m; | |
125 end | |
126 | |
127 end | |
128 | |
129 methods(Static) | |
130 % Calculates the matrcis need for the inteface coupling between boundary bound_u of scheme schm_u | |
131 % and bound_v of scheme schm_v. | |
132 % [uu, uv, vv, vu] = inteface_couplong(A,'r',B,'l') | |
133 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v) | |
134 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v); | |
135 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u); | |
136 end | |
137 end | |
138 end |