eval_spectra.py 953 B

123456789101112131415161718192021222324252627282930313233
  1. from numba import njit, prange, complex128, float64
  2. import numpy as np
  3. @njit(complex128(float64, float64[:]),
  4. fastmath=True, cache=True)
  5. def lorentzian(omega, xvec):
  6. res = 0
  7. poles = len(xvec)//4
  8. factor = 1
  9. for i in range(poles):
  10. gamma = xvec[i+0] / (factor**i)
  11. omega_n = xvec[i+1] / (factor**i)
  12. f = (xvec[i+2] + 1j*xvec[i+3]) / (factor**i)
  13. if (np.abs(f) == 0):
  14. return res
  15. res = res + f / (omega * (omega + 1j*gamma) - omega_n**2)
  16. return res
  17. @njit(complex128[:](float64[:], float64[:]),
  18. parallel=True, fastmath=True, cache=True)
  19. def spectra(omega, xvec):
  20. # print('in eval', xvec)
  21. poles = len(xvec)//4
  22. # for i in range(poles):
  23. # xvec[i] = np.absolute(xvec[i])
  24. # xvec[i+1] = np.absolute(xvec[i+1])
  25. val = np.zeros(omega.size, dtype=np.cdouble)
  26. for i in prange(omega.size):
  27. val[i] = lorentzian(omega[i], xvec)
  28. return val