Loading W lattice sums in python

Former-commit-id: 041c0d9b2c2be5f9392b09a1a22ef0300a1555cc
This commit is contained in:
Marek Nečada 2018-05-17 06:00:01 +03:00
parent cbab332c34
commit d00ffb2de2
1 changed files with 33 additions and 0 deletions

View File

@ -740,3 +740,36 @@ def G0_sum_1_slow(source_cart, dest_cart, k, nmax):
return G_Mie_scat_precalc_cart(source_cart, dest_cart, RH, RV, a=0.001, nmax=nmax, k_i=1, k_e=k, μ_i=1, μ_e=1, J_ext=1, J_scat=3)
def loadWfile(fileName, lMax = None):
'''
Load the translation operator lattice sums generated by hexlattice_ewald.c
'''
nparticles = 2 # TODO generalize
um = 1e-6 # micrometer in SI units
data = np.loadtxt(fileName)
nsamples = data.shape[0]
Wdata = data[:,5:]
if (lMax is None):
nelem = int((Wdata.shape[1]/nparticles**2)**.5/2)
lMax = nelem2lMax(nelem)
else:
nelem = lMax2nelem(lMax)
Ws = Wdata[:,::2] + 1j*Wdata[:,1::2]
# indices: destparticle, srcparticle, wavetype, desty, srcy
Ws.shape = (nsamples, nparticles, nparticles, 2, nelem, nelem)
# maybe TODO copy the following so the original data gets freed to save memory
freqs_weirdunits = data[:,0]
k0s = data[:,2]
ks = data[:,3:4]
freqs = freqs_weirdunits * c / um
return {
'freqs' : freqs,
'ks' : ks,
'k0s' : k0s,
'Ws' : Ws,
'freqs_weirdunits' : freqs_weirdunits,
}