patch_shape_comparison.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import expansion
  2. import patch_size
  3. import potentials
  4. import numpy as np
  5. from parameters import ModelParams
  6. import functions as fn
  7. import matplotlib.pyplot as plt
  8. import scipy.special as sps
  9. from pathlib import Path
  10. import rotational_path
  11. import path_plot
  12. def point_to_gauss_map(sigma_m, a_bar, lbd, params: ModelParams):
  13. return (sigma_m * fn.coefficient_Cim(2, params.kappaR) / fn.coefficient_Cpm(2, params.kappaR)
  14. * np.sinh(lbd) / (lbd * fn.sph_bessel_i(2, lbd)) * a_bar ** 2)
  15. def point_to_cap_map(sigma_m, a_bar, theta0, params: ModelParams):
  16. return (sigma_m * 10 * fn.coefficient_Cim(2, params.kappaR) / fn.coefficient_Cpm(2, params.kappaR) *
  17. a_bar ** 2 / (sps.eval_legendre(1, np.cos(theta0)) - sps.eval_legendre(3, np.cos(theta0))))
  18. if __name__ == '__main__':
  19. target_patch_size = 0.9
  20. params = ModelParams(R=150, kappaR=1)
  21. sigma_m = 0.001
  22. def fn1(x):
  23. return expansion.MappedExpansionQuad(a_bar=x, kappaR=params.kappaR, sigma_m=sigma_m, l_max=30)
  24. def fn2(x):
  25. return expansion.GaussianCharges(lambda_k=x, omega_k=np.array([[0, 0], [np.pi, 0]]), sigma1=0.001, l_max=30)
  26. def fn3(x):
  27. return expansion.SphericalCap(theta0_k=x, sigma1=0.001, l_max=50, omega_k=np.array([[0, 0], [np.pi, 0]]))
  28. a_bar = patch_size.inverse_potential_patch_size(target_patch_size, fn1, 0.5, params)
  29. lbd = patch_size.inverse_potential_patch_size(target_patch_size, fn2, 5, params)
  30. theta0 = patch_size.inverse_potential_patch_size(target_patch_size, fn3, 0.5, params)
  31. ex_point = expansion.MappedExpansionQuad(a_bar=a_bar, kappaR=params.kappaR, sigma_m=sigma_m, l_max=30)
  32. gauss_sigma = point_to_gauss_map(sigma_m, a_bar, lbd, params)
  33. ex_gauss = expansion.GaussianCharges(lambda_k=lbd, omega_k=np.array([[0, 0], [np.pi, 0]]), sigma1=gauss_sigma, l_max=30)
  34. cap_sigma = point_to_cap_map(sigma_m, a_bar, theta0, params)
  35. ex_cap = expansion.SphericalCap(theta0_k=theta0, sigma1=cap_sigma, omega_k=np.array([[0, 0], [np.pi, 0]]), l_max=30)
  36. theta = np.linspace(0, np.pi, 1000)
  37. phi = 0.
  38. dist = 1
  39. potential1 = potentials.charged_shell_potential(theta, phi, dist, ex_point, params)
  40. potential2 = potentials.charged_shell_potential(theta, phi, dist, ex_gauss, params)
  41. potential3 = potentials.charged_shell_potential(theta, phi, dist, ex_cap, params)
  42. # print(potential.shape)
  43. # print(potential)
  44. # expansion.plot_theta_profile_multiple([ex_point, ex_gauss, ex_cap], ['IC', 'Gauss', 'cap'], num=1000)
  45. # fig, ax = plt.subplots()
  46. # ax.plot(theta, potential1.T, label='IC')
  47. # ax.plot(theta, potential2.T, label='Gauss')
  48. # ax.plot(theta, potential3.T, label='cap')
  49. # ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  50. # ax.set_xlabel(r'$\theta$', fontsize=13)
  51. # ax.set_ylabel(r'$\phi$', fontsize=13)
  52. # plt.legend(fontsize=12)
  53. # plt.tight_layout()
  54. # plt.savefig(Path("/home/andraz/ChargedShells/Figures/potential_shape_comparison.png"), dpi=600)
  55. # plt.show()
  56. path_comparison = rotational_path.PathExpansionComparison([ex_point, ex_gauss, ex_cap],
  57. path_plot.QuadPath,
  58. dist=2,
  59. params=params)
  60. path_comparison.plot(['IC', 'Gauss', 'cap'],
  61. save_as=Path("/home/andraz/ChargedShells/Figures/energy_shape_comparison_kR1.png"))