potentials.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import expansion
  2. import functions as fn
  3. import numpy as np
  4. import parameters
  5. import matplotlib.pyplot as plt
  6. Array = np.ndarray
  7. ModelParams = parameters.ModelParams
  8. Expansion = expansion.Expansion
  9. def charged_shell_potential(theta: Array | float,
  10. phi: Array | float,
  11. dist: float,
  12. ex: Expansion,
  13. params: ModelParams) -> Array:
  14. """
  15. Electrostatic potential around a charged shell with patches given by expansion over spherical harmonics.
  16. :param theta: array of azimuthal angles
  17. :param phi: array of polar angles
  18. :param dist: distance between the particles in units of radius R
  19. :param ex: Expansion object detailing patch distribution
  20. :param params: ModelParams object specifying parameter values for the model
  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, params.kappaR) * fn.sph_bessel_k(ex.l_array, params.kappa * dist)
  30. / fn.sph_bessel_k(ex.l_array, params.kappaR))
  31. return (1 / (params.kappa * params.epsilon * params.epsilon0)
  32. * np.real(np.sum(ex.repeat_over_m(l_factors)[None, :] * ex.coeffs
  33. * fn.sph_harm(l_array[None, :], m_array[None, :], theta[:, None], phi[:, None]), axis=1)))
  34. if __name__ == '__main__':
  35. params = ModelParams(1, 3, 1, 1)
  36. ex = expansion.MappedExpansion(1, params.kappaR, 0.001, max_l=20)
  37. theta = np.linspace(0, np.pi, 1000)
  38. phi = 0.
  39. dist = 1.
  40. potential = charged_shell_potential(theta, phi, dist, ex, params)
  41. # print(potential)
  42. plt.plot(potential)
  43. plt.show()