-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester_PML.py
140 lines (104 loc) · 3.34 KB
/
tester_PML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'''
Tests the solver for a single Schrodinger equation of the type H psi = E psi with H = P²/2 + V
'''
from EQUATION import *
from SYSTEM import *
from TERM import *
import scipy as sc
import numpy as np
from scipy import special
def V(x,y,V0,R0):
V_ = np.zeros((len(x),len(y))) + V0
index = np.where(x**2 + y**2 < R0**2)
V_[index] = 0
return V_
def V_harmonic(x,y):
return x**2/2
def psi_0(X,Y):
return np.exp(-(((X-0.)**2 + (Y-0.)**2)/0.1**2))*np.exp(1.j*100.*X)
def Dx(sigma,dh):
return 0.5*dh*(np.roll(sigma,1,axis=0) - np.roll(sigma,-1,axis=0))
def Dy(sigma,dh):
return 0.5*dh*(np.roll(sigma,1,axis=1) - np.roll(sigma,-1,axis=1))
def sigma_x(x,y):
sig_x = np.zeros((len(x),len(y)))
index = np.where(abs(x) >= 0.9)
sig_x[index] = 10*x[index]**2
return sig_x
def sigma_y(x,y):
sig_y = np.zeros((len(x),len(y)))
index = np.where(abs(y) >= 0.9)
sig_y[index] = 10*y[index]**2
return sig_y
Z = 8
N = 2**Z
L = 1.
dh = 2.*L/(N-1)
X, Y = np.mgrid[-L:L+dh:dh,-L:L+dh:dh]
k_line = np.fft.fftfreq(N,dh)
k_x, k_y = np.meshgrid(k_line,k_line)
K2 = k_x**2 + k_y**2
V0 = 1e5
R0 = 0.4
dt = 1e-4
N_stride = 100
N_steps = 100
#Initializing system and equation
system = SYSTEM()
eq1 = EQUATION('eq1',psi_0(X,Y))
system.add_equation(eq1) #Adding equation to the system
#Binding Potential Term
term2 = TERM(V(X,Y,V0,R0),'Position','Binding Potential')
eq1.add_term(term2)
#Gross-Pitaevskii Term
f = lambda eq: np.abs(eq.solution)**2
kwargs = {'Function': f,'Variables':{'eq':eq1}}
term3 = TERM(f(eq1),'Position','Psi squared',True,**kwargs)
eq1.add_term(term3)
#Non time-derivative terms (NTD)
sig_x = sigma_x(X,Y)
sig_y = sigma_y(X,Y)
dx_sig_x = Dx(sig_x,dh)
dy_sig_y = Dy(sig_y,dh)
print(sig_x)
print(sig_y)
term4_0 = TERM(0.5j*(sig_x + sig_y),'Position','NTD1')
eq1.add_term(term4_0)
term4_1 = TERM(-0.25*sig_y*dx_sig_x*k_x + -0.25*sig_x*dy_sig_y*k_y,'Momentum','NTD2')
eq1.add_term(term4_1)
#Time derivative terms (TD)
phi0 = lambda eq: 0.25j*sig_x*sig_y*eq.solution
kwargs0 = {'Function':phi0,'Variables':{'eq':eq1}}
term5_0 = TERM(phi0(eq1),'Position','Phi0',False,True,**kwargs0)
eq1.add_term(term5_0)
#Terms in V
V_ = V(X,Y,V0,R0)
"""
phi1 = lambda eq: 0.5*(sig_x + sig_y)*V_*eq.solution
kwargs1 = {'Function':phi1,'Variables':{'eq':eq1}}
term5_1 = TERM(phi1(eq1),'Position','Phi1',False,True,**kwargs1)
eq1.add_term(term5_1)
phi2 = lambda eq: 0.25*sig_x*sig_y*V_*eq.solution
kwargs2 = {'auxiliary':True,'Function':phi2,'Variables':{'eq':eq1}}
term5_2 = TERM(phi2(eq1),'Position','Phi2',False,True,**kwargs2)
eq1.add_term(term5_2) #Auxiliary term
phi3 = lambda: term5_2.matrix
kwargs3 = {'Function':phi3,'Variables':{}}
term5_3 = TERM(phi3(),'Position','Phi3',False,True,**kwargs3)
eq1.add_term(term5_3)
"""
#Terms in psi²
phi4 = lambda eq: 0.5*(sig_x + sig_y)*np.abs(eq.solution)**2*eq.solution
kwargs4 = {'Function':phi4,'Variables':{'eq':eq1}}
term5_4 = TERM(phi4(eq1),'Position','Phi1',False,True,**kwargs4)
eq1.add_term(term5_4)
phi5 = lambda eq: 0.25*sig_x*sig_y*np.abs(eq.solution)**2*eq.solution
kwargs5 = {'auxiliary':True,'Function':phi5,'Variables':{'eq':eq1}}
term5_5 = TERM(phi5(eq1),'Position','Phi2',False,True,**kwargs5)
eq1.add_term(term5_5)
phi6 = lambda: term5_5.matrix
kwargs6 = {'Function':phi6,'Variables':{}}
term5_6 = TERM(phi6(),'Position','Phi3',False,True,**kwargs6)
eq1.add_term(term5_6)
#Time derivative term (??)
system.solve(X,Y,dt,N_stride,N_steps)