solutionofthetime-dependentschrödingerequation usingthecrank ... · 2017-05-10 · peter leitner...
TRANSCRIPT
Solution of the Time-dependent Schrödinger Equationusing the Crank-Nicolson algorithm with MPI on a 2-D
regular Cartesian gridSeminar on High Performance Computing 2
Summer term 2017
Peter Leitner & Stefan Hofmeister
Wednesday, May 10, 2017
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 1 / 13
Time-dependent Schrödinger Equation
Schrödinger Equation in 2-D for an electron in a given potential
i~∂
∂t|ψ(t, x)〉 = H(p, x) |ψ(t, x)〉 , H =
p2x
2m+
p2y
2m+ V (x , y) (1)
Attempt to simply discretize the differential operators,
∂tψ(t, x) ≈ψn+1j ,l − ψ
nj ,l
∆t,
p2
2mψ(t, x) = − ~2
2m∇2ψ(t, x) ≈ − ~2
2m
ψn+1j+1,l − 2ψn+1
j ,l + ψn+1j−1
(∆x)2 + . . .
is – as the von Neumann stability analysis shows – unconditionally stable.However, each solution of Schrödinger’s equation has to fulfill a continuityequation for the probability w(t, x) d3x = ψ∗ψ d3x to find the electronwithin a volume d3x around x ,
∂tw(t, x) +∇ · j = 0, j =~
2im[ψ∗(∇ψ)− (∇ψ∗)ψ] (2)
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 2 / 13
From the continuity equation follows the conservation of the norm of thewave function:
ddt
∫d3x w(t, x) =
∫d3x ∂tw(t, x) = −
∫d3x ∇ · j (t, x) = −
∫dS · j (t, x)
∫R3
d3x ‖w(0, x)‖2 = 1 SE−→∫R3
d3x ‖w(t, x)‖2 = 1 (3)
The normalization of the wave function ψ(t, x) is however not conserved by the fullyimplicit discretization as this method is not unitary ⇒ a discretization preserving thehermiticity of the Hamiltonian is needed that maintains the normalization of thewavefunction.The temporal evolution of the wave function can be expressed using the unitarytime-evolution operator U(t):
|ψ(t + ∆t, x)〉 ' U(t) |ψ(t, x)〉 , U(t) = exp(−iHt/~) (4)
With the time-evolution operator one can find the explicit Forward-Time Centered-Space(FTCS) scheme ψn+1
j,l = (1− iH∆t)ψnj,l and the implicit Backward-Time scheme
(1 + iH∆t)ψn+1j,l = ψn
j,l . Neither scheme is unitary and thus violates probabilityconservation.
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 3 / 13
A finite-difference approximation of exp(−iH∆t/~) that is unitary wasfound by Cayley:
exp(−iH∆t/~) =1− iH∆t
2~
1 + iH∆t2~
+O((∆t)2)
(4)⇒(1 +
i2~
H∆t)|ψ(t + ∆t, x)〉 =
(1− i
2~H∆t
)|ψ(t, x)〉 (5)
This is exactly the Crank-Nicolson scheme for the Schrödinger equation.
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 4 / 13
Discretization
By substituting the 2-D discrete wave function ψ(t; x , y)→ ψnj ,l into
Eq. (5) and considering the Hamiltonian in the form
H = |p = −i~∇| = − ~2
2m∂2
∂x2 −~2
2m∂2
∂y2 + V (x , y)
one obtains the discretized 2-D Schrödinger Equation
ψn+1j,l −
i∆t
2~
(~2
2m
ψj+1,ln + 1− 2ψn+1j,l + ψn+1
j−1,l
(∆x)2+ψn+1j,l+1 − 2ψn+1
j,l + ψn+1j,l−1
(∆y)2− Vj,lψ
n+1j,l
)
= ψnj,l +
i∆t
2~
(~2
2m
ψnj+1,l − 2ψn
j,l + ψnj−1,l
(∆x)2+
~2
2m
ψnj,l+1 − 2ψn
j,l + ψnj,l−1
(∆y)2− Vj,lψj,l
)(6)
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 5 / 13
Rewrite Eq. (6) in matrix-form. Assign a short-hand notation for the prefactors of the wavefunction at the next time step at various spatial grid points:
ψn+1j,l : bj,l = 1 +
i∆t
~~2
2m
(1
(∆x)2+
1(∆y)2
)+
i∆t
2~Vj,l
ψn+1j−1,l : c = −
i∆t
2~~2
2m1
(∆x)2
ψn+1j+1,l : a = c
ψn+1j,l+1 : d = −
i∆t
2~~2
2m1
(∆x)2
ψn+1j,l−1 : e = d
and for the RHS:
ψnj,l : fj,l = 1−
i∆t
~~2
2m
(1
(∆x)2+
1(∆y)2
)−
i∆t
2~Vj,l
ψnj+1,l : g =
i∆t
2~~2
2m1
(∆x)2
ψnj−1,l : h = g
ψnj,l+1 : k =
i∆t
2~~2
2m1
(∆y)2
ψnj,l−1 : p = k
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 6 / 13
LHS of the discretized Schrödinger Equation
Map the two indices j and l of the wave function ψnj,l on a single one (j , l) 7→ i :
i = 1 + (j − 1)(L− 1) + l − 1 for j = 0, 1, . . . , J; l = 0, 1, . . . , L
Thereby ψn1,1 → ψn
1, ψn1,2 → ψn
2, . . ., ψn1,J → ψn
J , ψn2,1 → ψn
J+1, . . . For simplicity (and lack ofspace) shown here only for J = L = 4, though later J, L ∼ 103 will be used. It exhibitssub-blocks of shape J × L:
b1,1 d 0 a 0 0 0 0 0e b1,2 d 0 a 0 0 0 00 e b1,3 0 0 a 0 0 0c 0 0 b2,1 d 0 a 0 00 c 0 e b2,2 d 0 a 00 0 c 0 e b2,3 0 0 a0 0 0 c 0 0 b3,1 d 00 0 0 0 c 0 e b3,2 d0 0 0 0 0 c 0 e b3,3
ψn+11ψn+1
2ψn+1
3ψn+1
4ψn+1
5ψn+1
6ψn+1
7ψn+1
8ψn+1
9
= r
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 7 / 13
RHS of the discretized Schrödinger Equation
Vectorization of the RHS is not necessary when working with Fortranexclusively but essential when using the numpy module with Python:
r =
f1,1 k 0 g 0 0 0 0 0p f1,2 k 0 g 0 0 0 00 p f1,3 0 0 g 0 0 0h 0 0 f2,1 k 0 g 0 00 h 0 p f2,2 k 0 g 00 0 h 0 p f2,3 0 0 g0 0 0 h 0 0 f3,1 k 00 0 0 0 h 0 p f3,2 k0 0 0 0 0 h 0 p f33
ψn1ψn
2ψn
3ψn
4ψn
5ψn
6ψn
7ψn
8ψn
9
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 8 / 13
After vectorization, the discretized Schrödinger Equation simplifies to
Aψn+1 = r = Bψn
Pseudo-code:
for n in range(N):
Compute Bψn = r as a matrix-vector productSolve Aψn+1 = r with LU decompositionThis yields ψn+1
Map the rolling index i back to indices j , l : ψn+1i → ψn+1
j ,l
Check that the wave packet remains normalized:∫∆2
d2x ‖ψ(t, x)‖2 ≈J,L∑j ,l=1
∆x∆y∥∥ψn
j ,l
∥∥2 != 1
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 9 / 13
Setting up the matrices in Python
# Build the main diagonalb_main_diag = [] # coefficient matrix of LHSf_main_diag = [] # coefficient matrix of RHSfor j in range(J-1):
for l in range(J-1):b_main_diag.append(b[j,l]); f_main_diag.append(f[j,l])
e_minor_diag = np.ones((len(b_main_diag)-1,), dtype=complex)*ed_minor_diag = np.ones((len(b_main_diag)-1,), dtype=complex)*da_minor_diag = np.ones((len(b_main_diag)-3,), dtype=complex)*ac_minor_diag = np.ones((len(b_main_diag)-3,), dtype=complex)*ck_minor_diag = np.ones((len(f_main_diag)-1,), dtype=complex)*kp_minor_diag = np.ones((len(f_main_diag)-1,), dtype=complex)*pg_minor_diag = np.ones((len(f_main_diag)-3,), dtype=complex)*gh_minor_diag = np.ones((len(f_main_diag)-3,), dtype=complex)*h
# Build the coefficient matrices for A*psi^(n+1) = B*psi^nA = np.diag(b_main_diag) + np.diag(e_minor_diag,-1) + np.diag(d_minor_diag,1) \
+ np.diag(c_minor_diag,-3) + np.diag(a_minor_diag,3)B = np.diag(f_main_diag) + np.diag(p_minor_diag,-1) + np.diag(k_minor_diag,1) \
+ np.diag(h_minor_diag,-3) + np.diag(g_minor_diag,3)
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 10 / 13
Setting-up the RHS in Python
for n in range(Nt):if n == 0:
psi_n_mat = psi_0# Rewrite matrix psi_jl as a vector psi_ipsi_n_vec = np.empty(((J-1)**2,), dtype=complex)for j in range(J-1):
for l in range(J-1):i = ind(j,l)psi_n_vec[i] = psi_n_mat[j,l]
else:psi_n_vec = psi_np1_vec
RHS = np.dot(B,psi_n_vec)r = RHS
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 11 / 13
LU decomposition; finally to be parallelized as Fortran code
# LU decomposition:P, L, U = scipy.linalg.lu(A)LU = L + UnA = np.size(A, 0)y = np.zeros((nA,), dtype=complex)x = np.zeros((nA,), dtype=complex)
r = np.dot(np.linalg.inv(P),r)
for i in range(1, nA+1):s = r[i-1]for j in range(1, i):
s = s - LU[i-1,j-1]*y[j-1]y[i-1] = s
for i in range(nA, 0, -1):s = y[i-1]for j in range(i+1, nA+1):
s = s - LU[i-1,j-1]*x[j-1]x[i-1] = s/LU[i-1,i-1]
psi_np1_vec = x
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 12 / 13
Parallelizing the code
The following strategies for code parallelization systems are envisaged:Application of Distributed SuperLU (SuperLU_DIST) of the SuperLUlibraryCrank-Nicolson predictor-corrector (CNPC) method
Decomposition of spatial domain Ω in subdomains Ωi which can beassigned to their own processorForward Euler to predict unknown values on the interface Γ betweensubdomains Ωi ⊂ ΩSolving the problem independently on the subdomains Ωi withBackward Euler using the predicted values ψ∗
Γ at tn+1Correction of interface values ψn+1
Γ with Backward Euler using interiorvalues
Peter Leitner & Stefan Hofmeister Crank-Nicolson using MPI Wednesday, May 10, 2017 13 / 13