peak_heigth.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import matplotlib.pyplot as plt
  2. from charged_shells import expansion, interactions, mapping
  3. from charged_shells.parameters import ModelParams
  4. import numpy as np
  5. from typing import Literal
  6. from pathlib import Path
  7. from functools import partial
  8. Array = np.ndarray
  9. Expansion = expansion.Expansion
  10. RotConfig = Literal['ep', 'pp']
  11. def peak_energy_plot(kappaR: Array,
  12. a_bar: Array,
  13. which: Literal['ep', 'pp'],
  14. R: float = 150,
  15. dist: float = 2.,
  16. l_max=20,
  17. save_as: Path = None):
  18. params = ModelParams(R=R, kappaR=kappaR)
  19. # energy = []
  20. # for params in params.unravel():
  21. # ex1 = expansion.MappedExpansionQuad(a_bar, params.kappaR, 0.001, l_max=l_max)
  22. # ex2 = ex1.clone()
  23. # if which == 'ep':
  24. # ex1.rotate_euler(alpha=0, beta=np.pi / 2, gamma=0)
  25. # energy.append(interactions.charged_shell_energy(ex1, ex2, dist, params))
  26. #
  27. # energy = np.array(energy)
  28. ex1 = expansion.MappedExpansionQuad(a_bar[:, None], params.kappaR[None, :], 0.001, l_max=l_max)
  29. ex2 = ex1.clone()
  30. if which == 'ep':
  31. ex1.rotate_euler(alpha=0, beta=np.pi / 2, gamma=0)
  32. energy_fn = mapping.parameter_map_two_expansions(partial(interactions.charged_shell_energy, dist=dist), 1)
  33. energy = energy_fn(ex1, ex2, params)
  34. fig, ax = plt.subplots()
  35. for en, ab in zip(energy, a_bar):
  36. ax.plot(kappaR, en / en[0], label=rf'$\bar a = {ab:.1f}$')
  37. ax.legend(fontsize=12)
  38. ax.tick_params(which='both', direction='in', top=True, right=True, labelsize=15)
  39. ax.set_xlabel(r'$\kappa R$', fontsize=15)
  40. ax.set_ylabel(rf'$\bar V$', fontsize=15)
  41. plt.tight_layout()
  42. if save_as is not None:
  43. plt.savefig(save_as, dpi=600)
  44. plt.show()
  45. if __name__ == '__main__':
  46. kappaR = np.arange(1, 10, 0.1)
  47. a_bar = np.arange(0.2, 0.8, 0.2)
  48. peak_energy_plot(kappaR, a_bar, which='ep',
  49. # save_as=Path('/home/andraz/ChargedShells/Figures/nonmonotonicity_check_ep.pdf')
  50. )