patch_size.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import numpy as np
  2. from scipy.optimize import bisect
  3. import expansion
  4. from matplotlib import pyplot as plt
  5. import parameters
  6. import potentials
  7. Expansion = expansion.Expansion
  8. Array = np.ndarray
  9. ModelParams = parameters.ModelParams
  10. @expansion.map_over_expansion
  11. def charge_patch_size(ex: Expansion, phi: float = 0, theta0: Array | float = 0, theta1: Array | float = np.pi / 2):
  12. return bisect(lambda theta: ex.charge_value(theta, phi), theta0, theta1)
  13. def potential_patch_size(ex: Expansion, params: ModelParams,
  14. phi: float = 0, theta0: Array | float = 0, theta1: Array | float = np.pi / 2,
  15. match_expansion_axis_to_params: int = None):
  16. meatp = match_expansion_axis_to_params
  17. @expansion.map_over_expansion
  18. def potential_zero(exp: Expansion, prms: ModelParams):
  19. return bisect(lambda theta: potentials.charged_shell_potential(theta, phi, 1, exp, prms), theta0, theta1)
  20. print(ex.shape)
  21. params_list = params.unravel()
  22. if meatp is not None:
  23. expansion_list = [Expansion(ex.l_array, np.take(ex.coefs, i, axis=meatp)) for i in range(ex.shape[meatp])]
  24. else:
  25. expansion_list = [ex]
  26. results = []
  27. for exp, prms in zip(expansion_list, params_list):
  28. results.append(potential_zero(exp, prms))
  29. if __name__ == '__main__':
  30. a_bar = np.linspace(0.2, 0.8, 100)
  31. kappaR = np.array([0.26, 1, 3, 10, 26])
  32. params = ModelParams(R=150, kappaR=kappaR)
  33. ex = expansion.MappedExpansionQuad(a_bar=a_bar[:, None], sigma_m=0.001, l_max=20, kappaR=kappaR[None, :])
  34. print(ex.shape)
  35. patch_size = charge_patch_size(ex)
  36. patch_size_pot = potential_patch_size(ex, params, match_expansion_axis_to_params=1)
  37. plt.plot(a_bar, patch_size * 180 / np.pi, label=kappaR)
  38. plt.legend()
  39. plt.show()