eval_spectra.py 901 B

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