potentials.py 2.0 KB

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