potentials.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import expansion
  2. import functions as fn
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. Array = np.ndarray
  6. def charged_shell_potential(theta: Array | float,
  7. phi: Array | float,
  8. dist: float,
  9. ex: expansion.Expansion,
  10. kappaR: float,
  11. R: float) -> Array:
  12. """
  13. Electrostatic potential around a charged shell with patches given by expansion over spherical harmonics.
  14. :param theta: array of azimuthal angles
  15. :param phi: array of polar angles
  16. :param dist: distance between the particles in units of radius R
  17. :param ex: Expansion object detailing patch distribution
  18. :param kappaR: screening value
  19. :param R: particle radius in nm
  20. :return: potential values in units of 1 / epsilon * epsilon0
  21. """
  22. if isinstance(theta, float):
  23. theta = np.full_like(phi, theta)
  24. if isinstance(phi, float):
  25. phi = np.full_like(theta, phi)
  26. if not theta.shape == phi.shape:
  27. raise ValueError('theta and phi arrays should have the same shape.')
  28. l_array, m_array = ex.lm_arrays
  29. l_factors = (fn.coefficient_Cpm(ex.l_array, kappaR) * fn.sph_bessel_k(ex.l_array, kappaR * dist)
  30. / fn.sph_bessel_k(ex.l_array, kappaR))
  31. return np.real(R / kappaR * np.sum(ex.repeat_over_m(l_factors)[None, :] * ex.coeffs
  32. * fn.sph_harm(l_array[None, :], m_array[None, :], theta[:, None], phi[:, None]),
  33. axis=1))
  34. if __name__ == '__main__':
  35. kappaR = 3
  36. R = 150
  37. ex = expansion.MappedExpansion(1, kappaR, 0.001, max_l=20)
  38. theta = np.linspace(0, np.pi, 1000)
  39. phi = 0.
  40. dist = 1.
  41. potential = charged_shell_potential(theta, phi, dist, ex, kappaR, R)
  42. # print(potential)
  43. plt.plot(potential)
  44. plt.show()