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