eval_spectra.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from ast import Constant
  2. from numba import njit, prange, complex128, float64
  3. import numpy as np
  4. # omega_init = True
  5. params_count = 4
  6. @njit(complex128(float64, float64[:]),
  7. fastmath=True, cache=True)
  8. def lorentzian(omega, xvec):
  9. # global omega_init
  10. pc = params_count
  11. res = 0
  12. poles = len(xvec)//params_count
  13. factor = 1
  14. for i in range(poles):
  15. gamma = xvec[pc*i+0] / (factor**i)
  16. omega_n = xvec[pc*i+1] / (factor**i)
  17. f = (xvec[pc*i+2] + 1j*xvec[pc*i+3]) / (factor**i)
  18. # if (omega_init):
  19. # print('init', gamma, omega_n, f)
  20. if (np.abs(f) == 0):
  21. return res
  22. res = res + f / (omega * (omega + 1j*gamma) - omega_n**2)
  23. # omega_init = False
  24. return res
  25. # @njit(complex128[:](float64[:], float64[:]),
  26. # parallel=True, fastmath=True, cache=True)
  27. def spectra(omega, xvec):
  28. # global omega_init
  29. # omega_init = True
  30. xvec_in = xvec
  31. poles = len(xvec)//params_count
  32. # for i in range(poles):
  33. # for j in range(2):
  34. # if (xvec_in[i+j] < 0):
  35. # xvec_in[i+j] = 0
  36. # # if (xvec_in[i+2] > 0):
  37. # # xvec_in[i+2] = 0
  38. val = np.zeros(omega.size, dtype=np.cdouble)
  39. # print('in eval', xvec_in)
  40. for i in range(omega.size):
  41. val[i] = lorentzian(omega[i], xvec_in)
  42. return val