Add yflip possibility to symmetries.py, piecewise loading of Wdata

Former-commit-id: 2b35cdc1fcf45a56fe5bd5214d4a6e9dc40f3d73
This commit is contained in:
Marek Nečada 2018-10-03 09:25:05 +03:00
parent 8507b09332
commit c3e234b892
2 changed files with 95 additions and 34 deletions

View File

@ -880,8 +880,24 @@ def processWfiles_sameKs(freqfilenames, destfilename, lMax = None, f='npz'):
return
def loadWfile_info(fileName, lMax = None, midk_halfwidth = None, freqlimits = None):
"""
Returns all the relevant data from the W file except for the W values themselves
"""
slovnik = loadWfile_processed(fileName, lMax = lMax, fatForm = False, midk_halfwidth=midk_halfwidth, freqlimits=freqlimits)
slovnik['Ws'] = None
return slovnik
def loadWfile_processed(fileName, lMax = None, fatForm = True, midk_halfwidth = None):
def loadWfile_processed(fileName, lMax = None, fatForm = True, midk_halfwidth = None, freqlimits = None, iteratechunk = None):
"""
midk_halfwidth: int
if given, takes only the "middle" k-value by index nk//2 and midk_halfwidth values from both sides
freqlimit: pair of doubles;
if given, only the values from the given frequency range (in Hz) are returned to save RAM
N.B.: the frequencies in the processed file are expected to be sorted!
iteratechunk: positive int ; NI
if given, this works as a generator with only iteratechunk frequencies processed and returned at each iteration to save memory
"""
if os.path.isdir(fileName): # .npy files in a directory
p = fileName
j = os.path.join
@ -919,26 +935,68 @@ def loadWfile_processed(fileName, lMax = None, fatForm = True, midk_halfwidth =
else:
lMax = data['lMax'][()]
nelem = lMax2nelem(lMax)
if fatForm: #indices: (...,) destparticle, desttype, desty, srcparticle, srctype, srcy
Ws2 = np.moveaxis(Ws, [-5,-4,-3,-2,-1], [-4,-2,-5,-3,-1] )
fatWs = np.empty(Ws2.shape[:-5]+(nparticles, 2,nelem, nparticles, 2, nelem),dtype=complex)
fatWs[...,:,0,:,:,0,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,1,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,0,:] = Ws2[...,1,:,:,:,:] #B
fatWs[...,:,0,:,:,1,:] = Ws2[...,1,:,:,:,:] #B
Ws = fatWs
return{
'lMax': lMax,
'nelem': nelem,
'npart': nparticles,
'nfreqs': nfreqs,
'nk' : nk,
'freqs': freqs,
'freqs_weirdunits': freqs_weirdunits,
'EeVs_orig': EeVs_orig,
'k0s': k0s,
'ks': ks,
'Ws': Ws,
}
if freqlimits is not None:
minind = np.searchsorted(freqs, freqlimits[0], size='left')
maxind = np.searchsorted(freqs, freqlimits[1], size='right')
freqs = freqs[minind:maxind]
Ws = Ws[minind:maxind]
k0s = k0s[minind:maxind]
EeVs_orig = EeVs_orig[minind:maxind]
freqs_weirdunints = freqs_weirdunits[minint:maxind]
nfreqs = maxind-minind
if iteratechunk is None: # everyting at once
if fatForm: #indices: (...,) destparticle, desttype, desty, srcparticle, srctype, srcy
Ws2 = np.moveaxis(Ws, [-5,-4,-3,-2,-1], [-4,-2,-5,-3,-1] )
fatWs = np.empty(Ws2.shape[:-5]+(nparticles, 2,nelem, nparticles, 2, nelem),dtype=complex)
fatWs[...,:,0,:,:,0,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,1,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,0,:] = Ws2[...,1,:,:,:,:] #B
fatWs[...,:,0,:,:,1,:] = Ws2[...,1,:,:,:,:] #B
Ws = fatWs
return{
'lMax': lMax,
'nelem': nelem,
'npart': nparticles,
'nfreqs': nfreqs,
'nk' : nk,
'freqs': freqs,
'freqs_weirdunits': freqs_weirdunits,
'EeVs_orig': EeVs_orig,
'k0s': k0s,
'ks': ks,
'Ws': Ws,
}
else:
def gen(lMax, nelem, nparticles, nfreqs, nk, freqs, freqs_weirdunits, EeVs_orig, k0s, ks, Ws, iteratechunk):
starti = 0
while(starti < nfreqs):
stopi = min(starti+iteratechunk, nfreqs)
chunkWs = Ws[starti:stopi]
if fatForm: #indices: (...,) destparticle, desttype, desty, srcparticle, srctype, srcy
Ws2 = np.moveaxis(chunkWs, [-5,-4,-3,-2,-1], [-4,-2,-5,-3,-1] )
fatWs = np.empty(Ws2.shape[:-5]+(nparticles, 2,nelem, nparticles, 2, nelem),dtype=complex)
fatWs[...,:,0,:,:,0,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,1,:] = Ws2[...,0,:,:,:,:] #A
fatWs[...,:,1,:,:,0,:] = Ws2[...,1,:,:,:,:] #B
fatWs[...,:,0,:,:,1,:] = Ws2[...,1,:,:,:,:] #B
chunkWs = fatWs
yield {
'lMax': lMax,
'nelem': nelem,
'npart': nparticles,
'nfreqs': stopi-starti,
'nk' : nk,
'freqs': freqs[starti:stopi],
'freqs_weirdunits': freqs_weirdunits[starti:stopi],
'EeVs_orig': EeVs_orig[starti:stopi],
'k0s': k0s[starti:stopi],
'ks': ks,
'Ws': chunkWs,
'chunk_range': (starti, stopi),
'nfreqs_total': nfreqs
}
starti += iteratechunk
return gen(lMax, nelem, nparticles, nfreqs, nk, freqs, freqs_weirdunits, EeVs_orig, k0s, ks, Ws, iteratechunk)

View File

@ -77,7 +77,7 @@ def mmult_ptypty(a, b):
return(qpms.apply_ndmatrix_left(a, b, (-6,-5,-4)))
#TODO lepší název fce
def gen_point_D3h_svwf_rep(lMax):
def gen_point_D3h_svwf_rep(lMax, vflip = 'x'):
'''
Gives the projection operators $P_kl('\Gamma')$ from Dresselhaus (4.28)
for all irreps $\Gamma$ of D3h.;
@ -89,11 +89,12 @@ def gen_point_D3h_svwf_rep(lMax):
C3_yy = qpms.WignerD_yy_fromvector(lMax, np.array([0,0,2*pi/3]))
C3_tyty = np.moveaxis(np.eye(2)[:,:,ň,ň] * C3_yy, 2,1)
zfl_tyty = qpms.zflip_tyty(lMax)
yfl_tyty = qpms.yflip_tyty(lMax)
xfl_tyty = qpms.xflip_tyty(lMax)
#yfl_tyty = qpms.yflip_tyty(lMax)
#xfl_tyty = qpms.xflip_tyty(lMax)
vfl_tyty = qpms.yflip_tyty(lMax) if vflip == 'y' else qpms.xflip_tyty(lMax)
I_tyty = np.moveaxis(np.eye(2)[:,:,ň,ň] * np.eye(nelem), 2,1)
order = D3h_permgroup.order()
sphrep_full = generate_grouprep(D3h_permgroup, I_tyty, D3h_srcgens, [C3_tyty, xfl_tyty, zfl_tyty],
sphrep_full = generate_grouprep(D3h_permgroup, I_tyty, D3h_srcgens, [C3_tyty, vfl_tyty, zfl_tyty],
immultop = mmult_tyty, imcmp = np.allclose)
sphreps = dict()
for repkey, matrixrep in D3h_irreps.items():
@ -118,21 +119,23 @@ def gen_point_D3h_svwf_rep(lMax):
sphreps[repkey] = sphrep
return sphreps
def gen_hexlattice_Kpoint_svwf_rep(lMax, psi):
def gen_hexlattice_Kpoint_svwf_rep(lMax, psi, vflip = 'x'):
my, ny = qpms.get_mn_y(lMax)
nelem = len(my)
C3_yy = qpms.WignerD_yy_fromvector(lMax, np.array([0,0,2*pi/3]))
C3_tyty = np.moveaxis(np.eye(2)[:,:,ň,ň] * C3_yy, 2,1)
zfl_tyty = qpms.zflip_tyty(lMax)
yfl_tyty = qpms.yflip_tyty(lMax)
xfl_tyty = qpms.xflip_tyty(lMax)
#yfl_tyty = qpms.yflip_tyty(lMax)
#xfl_tyty = qpms.xflip_tyty(lMax)
vfl_tyty = qpms.yflip_tyty(lMax) if vflip == 'y' else qpms.xflip_tyty(lMax)
I_tyty = np.moveaxis(np.eye(2)[:,:,ň,ň] * np.eye(nelem), 2,1)
hex_C3_K_ptypty = np.diag([exp(-psi*1j*2*pi/3),exp(+psi*1j*2*pi/3)])[:,ň,ň,:,ň,ň] * C3_tyty[ň,:,:,ň,:,:]
hex_zfl_ptypty = np.eye(2)[:,ň,ň,:,ň,ň] * zfl_tyty[ň,:,:,ň,:,:]
hex_xfl_ptypty = np.array([[0,1],[1,0]])[:,ň,ň,:,ň,ň] * xfl_tyty[ň,:,:,ň,:,:]
#hex_xfl_ptypty = np.array([[0,1],[1,0]])[:,ň,ň,:,ň,ň] * xfl_tyty[ň,:,:,ň,:,:]
hex_vfl_ptypty = np.array([[0,1],[1,0]])[:,ň,ň,:,ň,ň] * vfl_tyty[ň,:,:,ň,:,:]
hex_I_ptypty = np.eye((2*2*nelem)).reshape((2,2,nelem,2,2,nelem))
order = D3h_permgroup.order()
hex_K_sphrep_full = generate_grouprep(D3h_permgroup, hex_I_ptypty, D3h_srcgens, [hex_C3_K_ptypty, hex_xfl_ptypty, hex_zfl_ptypty],
hex_K_sphrep_full = generate_grouprep(D3h_permgroup, hex_I_ptypty, D3h_srcgens, [hex_C3_K_ptypty, hex_vfl_ptypty, hex_zfl_ptypty],
immultop = mmult_ptypty, imcmp = np.allclose)
hex_K_sphreps = dict()
for repkey, matrixrep in D3h_irreps.items():
@ -163,12 +166,12 @@ def normalize(v):
return v*np.nan
return v / norm
def gen_hexlattice_Kpoint_svwf_rep_projectors(lMax,psi, do_bases = False):
def gen_hexlattice_Kpoint_svwf_rep_projectors(lMax, psi, vflip='x', do_bases=False):
nelem = lMax * (lMax+2)
projectors = dict()
if do_bases:
bases = dict()
for repi, W in gen_hexlattice_Kpoint_svwf_rep(lMax,psi).items():
for repi, W in gen_hexlattice_Kpoint_svwf_rep(lMax,psi,vflip=vflip).items():
totalvecs = 0
tmplist = list()
for p in (0,1):