patch_shape_comparison.py 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, 1001)
  37. phi = 0.
  38. dist = 1
  39. potential_ic = potentials.inverse_patchy_particle_potential(theta, dist, a_bar, -2 * sigma_m, (sigma_m, sigma_m), params, 30)
  40. potential1 = potentials.charged_shell_potential(theta, phi, dist, ex_point, params)
  41. potential2 = potentials.charged_shell_potential(theta, phi, dist, ex_gauss, params)
  42. potential3 = potentials.charged_shell_potential(theta, phi, dist, ex_cap, params)
  43. # print(potential.shape)
  44. # print(potential)
  45. # expansion.plot_theta_profile_multiple([ex_point, ex_gauss, ex_cap], ['IC', 'Gauss', 'cap'], num=1000)
  46. fig, ax = plt.subplots()
  47. ax.plot(theta, 1000 * potential1.T, label='CS', linewidth=2)
  48. # ax.plot(theta, potential_ic.T, label='IC', ls=':', linewidth=2, marker='o', markevery=50, mfc='none')
  49. ax.scatter(theta[::50], 1000 * potential_ic.T[::50], marker='o', label='IC', facecolors='none', edgecolors='tab:red')
  50. ax.plot(theta, 1000 * potential2.T, label='Gauss', linewidth=2, ls='--')
  51. ax.plot(theta, 1000 * potential3.T, label='cap', linewidth=2, ls='--')
  52. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=12)
  53. ax.set_xlabel(r'$\theta$', fontsize=15)
  54. ax.set_ylabel(r'$\phi$ [mV]', fontsize=15)
  55. custom_ticks = [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4, np.pi]
  56. custom_labels = ['0', r'$\pi/4$', r'$\pi/2$', r'$3\pi/4$', r'$\pi$']
  57. plt.axhline(y=0, color='black', linestyle=':')
  58. plt.axvline(x=target_patch_size, color='black', linestyle=':')
  59. plt.xticks(custom_ticks, custom_labels, fontsize=13)
  60. plt.legend(fontsize=12)
  61. plt.tight_layout()
  62. # plt.savefig(Path("/home/andraz/ChargedShells/Figures/potential_shape_comparison.png"), dpi=600)
  63. plt.show()
  64. # path_comparison = rotational_path.PathExpansionComparison([ex_point, ex_gauss, ex_cap],
  65. # path_plot.QuadPath,
  66. # dist=2,
  67. # params=params)
  68. # path_comparison.plot(['IC', 'Gauss', 'cap'],
  69. # save_as=Path("/home/andraz/ChargedShells/Figures/energy_shape_comparison_kR1.png"))