From 0643ff4b3ed008fe4de7dec5b86f89976e252016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Wed, 3 May 2017 08:23:27 +0300 Subject: [PATCH] Faster versions of hexpoint calculations (work in progress) Former-commit-id: 44a7ed6419a966e2d71c258953d1d01dc0ed87ab --- misc/iht-saving.py | 4 +- qpms/hexpoints.py | 134 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 3 deletions(-) diff --git a/misc/iht-saving.py b/misc/iht-saving.py index 35454fc..e8e641b 100644 --- a/misc/iht-saving.py +++ b/misc/iht-saving.py @@ -28,8 +28,8 @@ omega = omega_eV * eV / hbar k_0 = omega * math.sqrt(epsilon_b) / c -output_prefix = './diracpoints-newdata/%d/' % maxlayer +output_prefix = '/tmp/diracpoints-newdata2/%d/' % maxlayer os.makedirs(output_prefix, exist_ok=True) -qpms.hexlattice_precalc_AB_save(file=output_prefix+str(omega_eV), lMax=lMax, k_hexside=k_0*hexside, +qpms.hexlattice_precalc_AB_save3(file=output_prefix+str(omega_eV), lMax=lMax, k_hexside=k_0*hexside, maxlayer=maxlayer, savepointinfo=True) diff --git a/qpms/hexpoints.py b/qpms/hexpoints.py index 1a104fc..1beb7d4 100644 --- a/qpms/hexpoints.py +++ b/qpms/hexpoints.py @@ -169,9 +169,141 @@ def generate_trianglepoints_hexcomplement(maxlayer, v3d = True, circular = True, } -from qpms_c import get_mn_y +from qpms_c import get_mn_y, trans_calculator from .qpms_p import Ã, B̃, cart2sph +def hexlattice_precalc_AB_save2(file, lMax, k_hexside, maxlayer, circular=True, savepointinfo = False, J_scat=3): + params = { + 'lMax' : lMax, + 'k_hexside' : k_hexside, + 'maxlayer' : maxlayer, + 'circular' : circular, + 'savepointinfo' : savepointinfo, + 'J_scat' : J_scat + } + tpdict = generate_trianglepoints(maxlayer, v3d=True, circular=circular, sixthindices=True, mirrorindices=True) + tphcdict = generate_trianglepoints_hexcomplement(maxlayer, v3d=True, circular=circular, thirdindices=True, mirrorindices=True) + my, ny = get_mn_y(lMax) + nelem = len(my) + a_self_nm = np.empty((tpdict['nmi'].shape[0],nelem,nelem), dtype=complex) + b_self_nm = np.empty((tpdict['nmi'].shape[0],nelem,nelem), dtype=complex) + a_self_m0 = np.empty((tpdict['mi'].shape[1],nelem,nelem), dtype=complex) + b_self_m0 = np.empty((tpdict['mi'].shape[1],nelem,nelem), dtype=complex) + a_d2u_nm = np.empty((tphcdict['nmi'].shape[0],nelem,nelem), dtype=complex) + b_d2u_nm = np.empty((tphcdict['nmi'].shape[0],nelem,nelem), dtype=complex) + a_d2u_m0 = np.empty((tphcdict['mi'].shape[1],nelem,nelem), dtype=complex) + b_d2u_m0 = np.empty((tphcdict['mi'].shape[1],nelem,nelem), dtype=complex) + + k_0 = k_hexside*_s3 # not really a wave vector here because of the normalisation! + tc = trans_calculator(lMax) + + y = np.arange(nelem) + + points = tpdict['points'][tpdict['nmi']] + d_i2j = cart2sph(points) + a_self_nm, b_self_nm = tc.get_AB(my[nx,:,nx],ny[nx,:,nx],my[nx,nx,:],ny[nx,nx,:],k_0*d_i2j[:,nx,nx,0],d_i2j[:,nx,nx,1],d_i2j[:,nx,nx,2],False,J_scat) + + points = tpdict['points'][tpdict['mi'][0]] + d_i2j = cart2sph(points) + a_self_m0, b_self_m0 = tc.get_AB(my[nx,:,nx],ny[nx,:,nx],my[nx,nx,:],ny[nx,nx,:],k_0*d_i2j[:,nx,nx,0],d_i2j[:,nx,nx,1],d_i2j[:,nx,nx,2],False,J_scat) + + points = tphcdict['points'][tphcdict['nmi']] + d_i2j = cart2sph(points) + a_d2u_nm, b_d2u_nm = tc.get_AB(my[nx,:,nx],ny[nx,:,nx],my[nx,nx,:],ny[nx,nx,:],k_0*d_i2j[:,nx,nx,0],d_i2j[:,nx,nx,1],d_i2j[:,nx,nx,2],False,J_scat) + + points = tphcdict['points'][tphcdict['mi'][0]] + d_i2j = cart2sph(points) + a_d2u_m0, b_d2u_m0 = tc.get_AB(my[nx,:,nx],ny[nx,:,nx],my[nx,nx,:],ny[nx,nx,:],k_0*d_i2j[:,nx,nx,0],d_i2j[:,nx,nx,1],d_i2j[:,nx,nx,2],False,J_scat) + + tosave = { + 'a_self_nm' : a_self_nm, + 'a_self_m0' : a_self_m0, + 'b_self_nm' : b_self_nm, + 'b_self_m0' : b_self_m0, + 'a_d2u_nm' : a_d2u_nm, + 'a_d2u_m0' : a_d2u_m0, + 'b_d2u_nm' : b_d2u_nm, + 'b_d2u_m0' : b_d2u_m0, + 'precalc_params' : params + } + if savepointinfo: + tosave['tp_points'] = tpdict['points'], + tosave['tp_si'] = tpdict['si'], + tosave['tp_mi'] = tpdict['mi'], + tosave['tp_nmi'] = tpdict['nmi'] + tosave['tphc_points'] = tphcdict['points'], + tosave['tphc_ti'] = tphcdict['ti'], + tosave['tphc_mi'] = tphcdict['mi'], + tosave['tphc_nmi'] = tphcdict['nmi'] + np.savez(file, **tosave) + +def hexlattice_precalc_AB_save3(file, lMax, k_hexside, maxlayer, circular=True, savepointinfo = False, J_scat=3): + params = { + 'lMax' : lMax, + 'k_hexside' : k_hexside, + 'maxlayer' : maxlayer, + 'circular' : circular, + 'savepointinfo' : savepointinfo, + 'J_scat' : J_scat + } + tpdict = generate_trianglepoints(maxlayer, v3d=True, circular=circular, sixthindices=True, mirrorindices=True) + tphcdict = generate_trianglepoints_hexcomplement(maxlayer, v3d=True, circular=circular, thirdindices=True, mirrorindices=True) + my, ny = get_mn_y(lMax) + nelem = len(my) + a_self_nm = np.empty((tpdict['nmi'].shape[0],nelem,nelem), dtype=complex) + b_self_nm = np.empty((tpdict['nmi'].shape[0],nelem,nelem), dtype=complex) + a_self_m0 = np.empty((tpdict['mi'].shape[1],nelem,nelem), dtype=complex) + b_self_m0 = np.empty((tpdict['mi'].shape[1],nelem,nelem), dtype=complex) + a_d2u_nm = np.empty((tphcdict['nmi'].shape[0],nelem,nelem), dtype=complex) + b_d2u_nm = np.empty((tphcdict['nmi'].shape[0],nelem,nelem), dtype=complex) + a_d2u_m0 = np.empty((tphcdict['mi'].shape[1],nelem,nelem), dtype=complex) + b_d2u_m0 = np.empty((tphcdict['mi'].shape[1],nelem,nelem), dtype=complex) + + k_0 = k_hexside*_s3 # not really a wave vector here because of the normalisation! + tc = trans_calculator(lMax) + + y = np.arange(nelem) + + points = tpdict['points'][tpdict['nmi']] + d_i2j = cart2sph(points) + a_self_nm, b_self_nm = tc.get_AB_arrays(k_0*d_i2j[:,0],d_i2j[:,1],d_i2j[:,2],np.array([False]),J_scat) + + points = tpdict['points'][tpdict['mi'][0]] + d_i2j = cart2sph(points) + a_self_m0, b_self_m0 = tc.get_AB_arrays(k_0*d_i2j[:,0],d_i2j[:,1],d_i2j[:,2],np.array([False]),J_scat) + + points = tphcdict['points'][tphcdict['nmi']] + d_i2j = cart2sph(points) + a_d2u_nm, b_d2u_nm = tc.get_AB_arrays(k_0*d_i2j[:,0],d_i2j[:,1],d_i2j[:,2],np.array([False]),J_scat) + + points = tphcdict['points'][tphcdict['mi'][0]] + d_i2j = cart2sph(points) + a_d2u_m0, b_d2u_m0 = tc.get_AB_arrays(k_0*d_i2j[:,0],d_i2j[:,1],d_i2j[:,2],np.array([False]),J_scat) + + tosave = { + 'a_self_nm' : a_self_nm, + 'a_self_m0' : a_self_m0, + 'b_self_nm' : b_self_nm, + 'b_self_m0' : b_self_m0, + 'a_d2u_nm' : a_d2u_nm, + 'a_d2u_m0' : a_d2u_m0, + 'b_d2u_nm' : b_d2u_nm, + 'b_d2u_m0' : b_d2u_m0, + 'precalc_params' : params + } + if savepointinfo: + tosave['tp_points'] = tpdict['points'], + tosave['tp_si'] = tpdict['si'], + tosave['tp_mi'] = tpdict['mi'], + tosave['tp_nmi'] = tpdict['nmi'] + tosave['tphc_points'] = tphcdict['points'], + tosave['tphc_ti'] = tphcdict['ti'], + tosave['tphc_mi'] = tphcdict['mi'], + tosave['tphc_nmi'] = tphcdict['nmi'] + np.savez(file, **tosave) + + + def hexlattice_precalc_AB_save(file, lMax, k_hexside, maxlayer, circular=True, savepointinfo = False, J_scat=3): params = { 'lMax' : lMax,