-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkoreleBRC.py
176 lines (145 loc) · 8.56 KB
/
koreleBRC.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import numpy as np
from numba import jit
# import datetime
# num_of_proces=4
#@jit(catche=True))
#def koff(B, p, i, m, v2):
#return B[m * v2 + i % v2, p]
#@jit(cache=True)#,forceobj=True)#@jit(cache=True)
#def ksi_opt_lop(numE, numG, v2, saitnum, virp, kff, hvirp, kvv=0, kv=0):
#Dll1 = np.zeros([numE, numE, v2, saitnum])
#Dll_1 = np.zeros([numE, numE, v2, saitnum])
#if kv != 0 or kvv != 0:
#for pb in range(numE):
#for pa in range(numE):
#for i in range(v2):
#for i_s in range(saitnum):
#i_ = np.zeros(saitnum, dtype=np.int)
#i_[i_s] += 1
#hh = (virp[i] + i_).tobytes()
#if hh in hvirp:
#Dll1[pa, pb, i, i_s] = np.conjugate(kff[pa, i, i_s]) * kff[pb, hvirp[hh], i_s]
#Dll_1[pb, pa, hvirp[hh], i_s] = np.conjugate(Dll1[pa, pb, i, i_s])
#return Dll1, Dll_1
#@jit(cache=True,forceobj=True)
def calc_Xi(numE, v2, saitnum, virp, kff, hvirp):
Dll1 = np.zeros([numE, numE, saitnum])
Dll_1 = np.zeros([numE, numE, saitnum])
i_ = np.zeros(saitnum, dtype=np.int)
for i_s in range(saitnum):
i_[i_s] += 1
for i in range(v2):
hh = (virp[i] + i_).tobytes()
if hh in hvirp:
Dll1,Dll_1=Xi_inner(i_s,Dll1,Dll_1,numE,saitnum,i,hvirp[hh],virp,kff)
i_[i_s] -=1
return Dll1, Dll_1
@jit(cache=True)#,forceobj=True)#@jit(cache=True,nopython=True)
def Xi_inner(i_s,Dll1,Dll_1,numE,saitnum,i,i2,virp,kff):
for pb in range(numE):
for pa in range(numE):
for n in range(saitnum):
Dll1[pa, pb, i_s] += np.sqrt(virp[i,i_s]+1)*np.conjugate(kff[pa, i, n]) * kff[pb, i2, n]#np.einum("ik,lk",np.conjugate(kff[pa, i, n]) * kff[pb, i2, n])
Dll_1[pa, pb, i_s] += np.sqrt(virp[i2,i_s])*np.conjugate(kff[pa, i2, n])*kff[pb, i, n]
return Dll1,Dll_1
@jit(cache=True)#,forceobj=True)#@jit(cache=True,nopython=True)
def He_e(pa,pb,pc,pd,mul,numE,saitnum,kff):
temp=0.0
temp=ksi2(pa, pb, pc, pd, saitnum, mul, kff)
return temp
@jit(cache=True)#,forceobj=True)#@jit(cache=True,nopython=True)
def He_vv(pa,pb,pc,pd,mul,numE,saitnum,v2,s,kff,Xip,Xim):
temp=0.0
temp+=4*ksi2(pa, pb, pc, pd, saitnum, mul*s, kff)
for n in range(saitnum):
temp+=mul[n]*(Xip[pa,pb,n]*Xip[pc,pd,n]
+Xip[pa,pb,n]*Xim[pc,pd,n]
+Xim[pa,pb,n]*Xip[pc,pd,n]
+Xim[pa,pb,n]*Xim[pc,pd,n])
for i in range(v2):
temp+=2*np.sqrt(s[n])*mul[n]*(kff[pa,i,n]*kff[pb,i,n]*(Xip[pc,pd,n]+Xim[pc,pd,n])+
kff[pc,i,n]*kff[pd,i,n]*(Xip[pa,pb,n]+Xim[pa,pb,n]))
return temp
@jit(cache=True)#,forceobj=True)#@jit(nopython=True, cache=True)
def ksi2(pa, pb, pc, pd, saitnum, mul, kff):
summ = 0
for l in range(saitnum):
summ += np.dot(np.conjugate(kff[pa, :, l]), kff[pb, :, l]) * np.dot(np.conjugate(kff[pc, :, l]), kff[pd, :, l]) * mul[l]
# summ = np.einsum("il,il,jl,jl,l",np.conjugate(kff[pa]),kff[pb],np.conjugate(kff[pc]),kff[pd],mul)
return summ
#@jit(cache=True,forceobj=True)#@jit(nopython=True, cache=True)
#def h_e(p1, p2, p3, p4, saitnum, virp, S, mul, dll1, dll_1, kff, om0, ke=1, kvv=0, kv=0, FR=True):
#sum2 = 0
#if kvv != 0:
#for ss in range(saitnum):
#sum2 += kvv * mul[ss] * (np.dot(np.sqrt(virp[:, ss]), dll_1[p1, p2, :, ss]) * np.dot(np.sqrt(virp[:, ss]), dll_1[p3, p4, :, ss]) +
#np.dot(np.sqrt((virp[:, ss] + 1)), dll1[p1, p2, :, ss]) * np.dot(np.sqrt(virp[:, ss]), dll_1[p3, p4, :, ss]) +
#np.dot(np.sqrt(virp[:, ss]), dll_1[p1, p2, :, ss]) * np.dot(np.sqrt((virp[:, ss] + 1)), dll1[p3, p4, :, ss]) +
#np.dot(np.sqrt((virp[:, ss] + 1)), dll1[p1, p2, :, ss]) * np.dot(np.sqrt((virp[:, ss] + 1)), dll1[p3, p4, :, ss])) / (2 * om0[ss])
#if FR:
#sum2 += np.dot(np.conjugate(kff[p1, :, ss]), kff[p2, :, ss]) * kvv * 2 * mul[ss] * np.sqrt(S[ss]) * (np.dot(np.sqrt(virp[:, ss]), dll_1[p3, p4, :, ss]) + np.dot(np.sqrt(virp[:, ss] + 1), dll1[p3, p4, :, ss])) / (2 * om0[ss])
#if FR:
#sum2 += np.dot(np.conjugate(kff[p3, :, ss]), kff[p4, :, ss]) * kvv * 2 * mul[ss] * np.sqrt(S[ss]) * (np.dot(np.sqrt(virp[:, ss]), dll_1[p1, p2, :, ss]) + np.dot(np.sqrt(virp[:, ss] + 1), dll1[p1, p2, :, ss])) / (2 * om0[ss])
#if FR:
#sum2 += 4 * kvv * mul[ss] * S[ss] * np.dot(np.conjugate(kff[p1, :, ss]), kff[p2, :, ss]) * np.dot(np.conjugate(kff[p3, :, ss]), kff[p4, :, ss]) / (2 * om0[ss])
#if kv != 0:
#for ss in range(saitnum):
#sum2 += mul[ss] * kv * np.dot(np.conjugate(kff[p3, :, ss]), kff[p4, :, ss]) * (np.dot(np.sqrt(virp[:, ss]), dll_1[p1, p2, :, ss]) + np.dot(np.sqrt(virp[:, ss] + 1), dll1[p1, p2, :, ss])) / np.sqrt(2 * om0[ss])
#sum2 += mul[ss] * kv * np.dot(np.conjugate(kff[p1, :, ss]), kff[p2, :, ss]) * (np.dot(np.sqrt(virp[:, ss]), dll_1[p3, p4, :, ss]) + np.dot(np.sqrt(virp[:, ss] + 1), dll1[p3, p4, :, ss])) / np.sqrt(2 * om0[ss])
#if FR:
#for ss in range(saitnum):
#sum2 += np.dot(np.conjugate(kff[p1, :, ss]), kff[p2, :, ss]) * mul[ss] * kv * np.dot(np.conjugate(kff[p3, :, ss]), kff[p4, :, ss]) * np.sqrt(2 * S[ss] / om0[ss])
#for ss in range(saitnum):
#sum2 += np.dot(np.conjugate(kff[p3, :, ss]), kff[p4, :, ss]) * mul[ss] * kv * np.dot(np.conjugate(kff[p1, :, ss]), kff[p2, :, ss]) * np.sqrt(2 * S[ss] / om0[ss])
#if ke != 0:
#sum2 += ke * ksi2(p1, p2, p3, p4, saitnum, mul, kff)
#return sum2
def h_g(i, j, i2, j2, virp, saitnum, mul,hvirp):
summ=0.0
i_ = np.zeros(saitnum, dtype=np.int)
for i_s in range(saitnum):
i_[i_s] += 1
hh = (virp[j] + i_).tobytes()
ap=np.sqrt(j+1) if (hh in hvirp) and hvirp[hh]==i else 0#virp[i]==virp[j_s+1]
hh = (virp[j] - i_).tobytes()
am=np.sqrt(j) if (hh in hvirp) and hvirp[hh]==i else 0 #virp[i]==virp[j_s-1]
hh = (virp[j2] + i_).tobytes()
bp=np.sqrt(j2+1) if (hh in hvirp) and hvirp[hh]==i2 else 0#virp[i1]==virp[j_s2+1]
hh = (virp[j2] - i_).tobytes()
bm=np.sqrt(j2) if (hh in hvirp) and hvirp[hh]==i2 else 0#virp[i1]==virp[j_s2-1]
summ+=(ap+am)*(bp+bm)
# for i in range(v2):
# hh = (virp[i] + i_).tobytes()
# if hh in hvirp:
# hvirp[hh]
i_[i_s] -=1
return summ
#@jit(cache=True,forceobj=True)#@jit(cache=True,nopython=True)
def Corrcoff_2(numG, numE, B, virp, v2, saitnum, S=0, mul=1, snum=1,C_type=['e']):
#if np.size(S) == 1:
#S = np.array([S] * saitnum)
hvirp = {}
for i in range(v2):
hvirp[virp[i].tobytes()] = i
kff = np.moveaxis((B.reshape(saitnum, v2, saitnum * v2)), [0, 1, 2], [2, 1, 0])
# Dll1, Dll_1 = ksi_opt_lop(numE, numG, v2, saitnum, virp, kff, hvirp, kvv=kvv, kv=kv)
Xim,Xip=calc_Xi(numE, v2, saitnum, virp, kff, hvirp)
CorrOffd = np.zeros((snum, numE + numG, numE + numG))
CorrD = np.zeros((snum, numE + numG, numE + numG))
for zz in range(snum):
for ii in range(numE + numG):
for jj in range(numE + numG):
if ii < numG and jj < numG:
CorrOffd[zz, ii, jj] = h_g(ii, jj, jj, ii, virp, saitnum, mul,hvirp)
CorrD[zz, ii, jj] =h_g(ii, ii, jj, jj, virp, saitnum, mul,hvirp)
if jj < numG and ii >= numG and ii < numG + numE:
CorrOffd[zz, ii, jj] = 0
CorrD[zz, ii, jj] = 0
if jj >= numG and ii >= numG and jj < (numG + numE) and ii < (numG + numE):
if C_type[zz]=='e':
CorrOffd[zz, ii, jj] = He_e(ii - numG, jj - numG, jj - numG, ii - numG,mul[zz],numE,saitnum,kff)
CorrD[zz, ii, jj] = He_e(ii - numG, ii - numG, jj - numG, jj - numG,mul[zz],numE,saitnum,kff)
elif C_type[zz]=='v':
CorrOffd[zz, ii, jj] = He_vv(ii - numG, jj - numG, jj - numG, ii - numG,mul[zz],numE,saitnum,v2,S,kff,Xip,Xim)#0#h_e(ii - numG, jj - numG, jj - numG, ii - numG, saitnum, virp, S, mul[zz], Dll1, Dll_1, kff, OM, ke=ke, kvv=kvv, kv=kv, FR=FR)
CorrD[zz, ii, jj] = He_vv(ii - numG, ii - numG, jj - numG, jj - numG,mul[zz],numE,saitnum,v2,S,kff,Xip,Xim)#0#h_e(ii - numG, ii - numG, jj - numG, jj - numG, saitnum, virp, S, mul[zz], Dll1, Dll_1, kff, OM, ke=ke, kvv=kvv, kv=kv, FR=FR)
return CorrOffd, CorrD