Mercurial > repos > public > sbplib
comparison +scheme/Schrodinger1dCurve.m @ 429:dde5760863de feature/quantumTriangles
Added a scheme for the time deforming shrodinger equation in 1d
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Mon, 06 Feb 2017 09:54:18 +0100 |
parents | |
children | 25053554524b |
comparison
equal
deleted
inserted
replaced
428:a39fe3bcbd95 | 429:dde5760863de |
---|---|
1 classdef Schrodinger1dCurve < scheme.Scheme | |
2 properties | |
3 m % Number of points in each direction, possibly a vector | |
4 h % Grid spacing | |
5 xi % Grid | |
6 order % Order accuracy for the approximation | |
7 grid | |
8 | |
9 D % non-stabalized scheme operator | |
10 H % Discrete norm | |
11 M % Derivative norm | |
12 alpha | |
13 | |
14 V_mat | |
15 D1 | |
16 D2 | |
17 Hi | |
18 e_l | |
19 e_r | |
20 d1_l | |
21 d1_r | |
22 gamm | |
23 end | |
24 | |
25 methods | |
26 % Solving SE in the form u_t = i*u_xx +i*V on deforming 1D domain; | |
27 function obj = Schrodinger1dCurve(m,order,V,constJi) | |
28 default_arg('V',0); | |
29 default_arg('constJi',false) | |
30 xilim={0 1}; | |
31 if constJi | |
32 ops = sbp.D2Standard(m,xilim,order); | |
33 else | |
34 ops = sbp.D4Variable(m,xilim,order); | |
35 end | |
36 | |
37 obj.xi=ops.x; | |
38 obj.h=ops.h; | |
39 obj.D2 = ops.D2; | |
40 obj.D1 = ops.D1; | |
41 obj.H = ops.H; | |
42 obj.Hi = ops.HI; | |
43 obj.M = ops.M; | |
44 obj.e_l = ops.e_l; | |
45 obj.e_r = ops.e_r; | |
46 obj.d1_l = ops.d1_l; | |
47 obj.d1_r = ops.d1_r; | |
48 | |
49 | |
50 if isa(V,'function_handle') | |
51 V_vec = V(obj.x); | |
52 else | |
53 V_vec = obj.xi*0 + V; | |
54 end | |
55 | |
56 obj.V_mat = spdiags(V_vec,0,m,m); | |
57 | |
58 obj.D = @(a,a_xi,Ji) obj.d_fun(a, a_xi, Ji, constJi); | |
59 | |
60 obj.m = m; | |
61 obj.order = order; | |
62 end | |
63 | |
64 | |
65 % Closure functions return the opertors appliedo to the own doamin to close the boundary | |
66 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. | |
67 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. | |
68 % type is a string specifying the type of boundary condition if there are several. | |
69 % data is a function returning the data that should be applied at the boundary. | |
70 % neighbour_scheme is an instance of Scheme that should be interfaced to. | |
71 % neighbour_boundary is a string specifying which boundary to interface to. | |
72 | |
73 function [D] = d_fun(obj,a, a_xi , Ji , constJi) | |
74 if constJi | |
75 D= -0.5*(obj.D1*a - a_xi + a*obj.D1) + 1i*Ji*obj.D2 + 1i*obj.V_mat; | |
76 % D= -a*obj.D1 + 1i*Ji*obj.D2 + 1i*obj.V_mat; | |
77 else | |
78 D= -0.5*(obj.D1*a - a_xi + a*obj.D1) + 1i*obj.D2(diag(Ji)) + 1i*obj.V_mat; | |
79 % D= - a*obj.D1 + 1i*obj.D2(diag(Ji)) + 1i*obj.V_mat; | |
80 % D=-obj.D1*a - a_xi + 1i*obj.D2(diag(Ji)) + 1i*obj.V_mat; | |
81 end | |
82 end | |
83 | |
84 function [closure, penalty] = boundary_condition(obj,boundary,type,data) | |
85 default_arg('type','dirichlet'); | |
86 default_arg('data',0); | |
87 | |
88 [e,d,s,p] = obj.get_boundary_ops(boundary); | |
89 | |
90 switch type | |
91 % Dirichlet boundary condition | |
92 case {'D','d','dirichlet'} | |
93 tau1 = s * 1i*d; | |
94 tau2 = @(a) (-1*s*a(p,p) - abs(a(p,p)))/4*e; | |
95 closure = @(a) obj.Hi*tau1*e' + obj.Hi*tau2(a)*e'; | |
96 | |
97 switch class(data) | |
98 case 'double' | |
99 penalty = @(a) -(obj.Hi*tau1*data+obj.Hi*tau2(a)*data); | |
100 % case 'function_handle' | |
101 % penalty = @(t)-obj.Hi*tau*data(t); | |
102 otherwise | |
103 error('Wierd data argument!') | |
104 end | |
105 | |
106 % Unknown, boundary condition | |
107 otherwise | |
108 error('No such boundary condition: type = %s',type); | |
109 end | |
110 end | |
111 | |
112 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary) | |
113 % u denotes the solution in the own domain | |
114 % v denotes the solution in the neighbour domain | |
115 % [e_u,d_u,s_u] = obj.get_boundary_ops(boundary); | |
116 % [e_v,d_v,s_v] = neighbour_scheme.get_boundary_ops(neighbour_boundary); | |
117 | |
118 % a = -s_u* 1/2 * 1i ; | |
119 % b = a'; | |
120 | |
121 % tau = b*d_u; | |
122 % sig = -a*e_u; | |
123 | |
124 % closure = obj.Hi * (tau*e_u' + sig*d_u'); | |
125 % penalty = obj.Hi * (-tau*e_v' - sig*d_v'); | |
126 end | |
127 | |
128 % Ruturns the boundary ops and sign for the boundary specified by the string boundary. | |
129 % The right boundary is considered the positive boundary | |
130 function [e,d,s,p] = get_boundary_ops(obj,boundary) | |
131 switch boundary | |
132 case 'l' | |
133 e = obj.e_l; | |
134 d = obj.d1_l; | |
135 s = -1; | |
136 p=1; | |
137 case 'r' | |
138 e = obj.e_r; | |
139 d = obj.d1_r; | |
140 s = 1; | |
141 p=obj.m; | |
142 otherwise | |
143 error('No such boundary: boundary = %s',boundary); | |
144 end | |
145 end | |
146 | |
147 function N = size(obj) | |
148 N = obj.m; | |
149 end | |
150 | |
151 end | |
152 | |
153 methods(Static) | |
154 % Calculates the matrcis need for the inteface coupling between boundary bound_u of scheme schm_u | |
155 % and bound_v of scheme schm_v. | |
156 % [uu, uv, vv, vu] = inteface_couplong(A,'r',B,'l') | |
157 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v) | |
158 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v); | |
159 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u); | |
160 end | |
161 end | |
162 end |