patch_shape_comparison.py 4.2 KB

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