1
0

angularMomentum.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Analysis of the transfer of angular momentum from luminous components
  2. for encounters with a dark matter halo"""
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from analysis import utils
  6. def luminousAngularMomentum(data):
  7. """Calculate angular momentum of the luminous components
  8. Parameters:
  9. data: a data dictionary in the format saved by the simulation
  10. Returns:
  11. The norm of the angular momentum vector of the luminous components
  12. """
  13. maskDisk = data['type'][:,0]=='disk'
  14. maskBulge = data['type'][:,0]=='bulge'
  15. # Plot luminous components
  16. mask = np.logical_or(maskDisk, maskBulge)
  17. return np.linalg.norm(np.sum(data['mass'][mask][:,np.newaxis]
  18. * np.cross(data['r_vec'][mask], data['v_vec'][mask]), axis=0))
  19. # Plotting
  20. f, ax = plt.subplots(1, 1)
  21. # No halo
  22. j1 = []
  23. ts = np.linspace(1, 50001, 251)
  24. for t in ts:
  25. data = utils.loadData('hyperbolic_nohalo', int(t))
  26. j1.append(luminousAngularMomentum(data))
  27. ax.plot(ts, j1/j1[0], c='black', linestyle='dashed', label='1:1:0')
  28. # Halo
  29. j2 = []
  30. ts = np.linspace(1, 150001, 751)
  31. for t in ts:
  32. data = utils.loadData('hyperbolic_halo', int(t))
  33. j2.append(luminousAngularMomentum(data))
  34. ax.plot(ts, j2/j2[0], c='black', linestyle='solid', label='1:3:16')
  35. # Plotting styling
  36. utils.setSize(ax, y=(0, 1.1))
  37. utils.setAxes(ax, x=r'$t$', y=r'Angular momentum (luminous)',
  38. ycoords=(.9,-0.08))
  39. ax.legend(title=r'bulge:disk:halo')
  40. utils.stylizePlot([ax])
  41. plt.show()
  42. # Quantitaive analysis
  43. print('Angular momentum is conserved in encounter 1 to within',
  44. (np.max(j1)-np.min(j1))/j1[0])