13
13
def harmonicPotential (x ):
14
14
return 0.5 * x ** 2
15
15
16
+ def wavePacket (x , k_0 ):
17
+ return exp (- 0.5 * x ** 2 + 1j * k_0 * x )
16
18
17
19
class Schroedinger1D :
20
+ ''' This class encapsulates the 1D schroedinger equation solver '''
18
21
def __init__ (self , N = 256 , L = 10 ):
19
22
self ._N = N
20
23
self ._L = L
@@ -24,12 +27,20 @@ def __init__(self, N=256, L=10):
24
27
self ._dk = 2. * pi / (N * self ._dx )
25
28
26
29
self ._x = (arange (N ) - N / 2 ) * self ._dx
30
+ # this is the grid in momentum space. Instead of realigning self._F after fft and before momentumEvolve, resp again
31
+ # after momentumEvolve and before ifft I simply transform the grid itself (see example (6.7) in the lecture notes)
27
32
k = (arange (N ) - N / 2 )
28
33
self ._k = concatenate ((k [self ._N // 2 :], k [0 :self ._N // 2 ])) * self ._dk
29
- self ._f = exp (- 0.5 * self ._x ** 2 + 2. * self ._x * 1j )
34
+
35
+ # a simple wave-package moving constantly to the right and starting at x=0
36
+ self .setInitial (lambda x : wavePacket (x , 2. ))
37
+
38
+ # use the harmonic potential as default potential
30
39
self ._V = harmonicPotential
31
40
32
41
def evolve (self , dt = 0.001 ):
42
+ ''' one iteration-step '''
43
+
33
44
def spatialEvolve (f , x ):
34
45
return f * exp (- 0.5 * self ._V (x ) * dt * 1j )
35
46
def momentumEvolve (F , k ):
@@ -54,8 +65,13 @@ def V(self):
54
65
return self ._V (self ._x )
55
66
56
67
def setPotential (self , V ):
68
+ ''' set the potential (as a function of an array of x-values)'''
57
69
self ._V = V
58
70
71
+ def setInitial (self , f ):
72
+ ''' set the initial conditions (as a function of x of an array of x-values)'''
73
+ self ._f = f (self ._x )
74
+
59
75
if __name__ == '__main__' :
60
76
from matplotlib .pyplot import plot , show
61
77
0 commit comments