interactions_test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from charged_shells import interactions, charge_distributions
  2. from charged_shells.parameters import ModelParams
  3. import time
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. def v22_distance_test():
  7. params = ModelParams(R=10, kappaR=3.29)
  8. ex0 = charge_distributions.create_expansion24(1, 0, 0)
  9. ex1 = ex0.clone()
  10. ex0.rotate_euler(0, np.array([0, 0, np.pi / 2]), 0)
  11. ex1.rotate_euler(0, np.array([0, np.pi / 2, np.pi / 2]), 0)
  12. dist = np.linspace(2, 3.2, 100)
  13. energy_array = np.zeros((dist.shape[0], 3))
  14. for i, d in enumerate(dist):
  15. energy_array[i, ...] = interactions.charged_shell_energy(ex0, ex1, params, d)
  16. print(interactions.charged_shell_energy(ex0, ex1, params, dist=2.))
  17. plt.plot(dist, energy_array)
  18. plt.show()
  19. def quadrupole_variation_test():
  20. params = ModelParams(R=10, kappaR=3.29)
  21. sigma2 = np.array([0.45, 0.5, 0.55, 0.6, 0.65])
  22. ex0 = charge_distributions.create_expansion24(sigma2, 0, sigma0=0.1)
  23. ex1 = ex0.clone()
  24. ex1.rotate_euler(0, np.pi / 2, 0)
  25. dist = np.linspace(2, 3.2, 100)
  26. energy_array = np.zeros((dist.shape[0], len(sigma2)))
  27. for i, d in enumerate(dist):
  28. energy_array[i, ...] = interactions.charged_shell_energy(ex0, ex1, params, d)
  29. plt.plot(dist, energy_array)
  30. plt.show()
  31. def timing():
  32. params = ModelParams(R=150, kappaR=3)
  33. ex1 = charge_distributions.create_mapped_quad_expansion(0.44, params.kappaR, 0.001, l_max=20)
  34. ex2 = ex1.clone()
  35. dist = 2.
  36. # ex1, ex2 = expansions_to_common_l(ex1, ex2)
  37. # print(ex1.coeffs)
  38. # print(ex2.coeffs)
  39. t0 = time.perf_counter()
  40. energy = interactions.charged_shell_energy(ex1, ex2, params, dist)
  41. t1 = time.perf_counter()
  42. print('energy: ', energy)
  43. print('time: ', t1 - t0)
  44. # plt.plot(energy)
  45. # plt.show()
  46. if __name__ == '__main__':
  47. # v22_distance_test()
  48. # timing()
  49. quadrupole_variation_test()