Skip to content

Instantly share code, notes, and snippets.

@jbernhard
Created July 18, 2014 17:03
Show Gist options
  • Save jbernhard/fb43401ee702b4c058ab to your computer and use it in GitHub Desktop.
Save jbernhard/fb43401ee702b4c058ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Calculate v2{2} for an isotropic emission law (zero flow). Will converge
to zero as the number of particles -> infinity.
"""
import itertools
import sys
import numpy as np
import numpy.random as rnd
def main():
try:
npart = int(sys.argv[1])
except (IndexError, ValueError):
print('usage: ' + sys.argv[0] + ' number_particles')
exit(1)
phi = 2*np.pi*rnd.rand(npart)
deltaphi = np.array(
[phi1-phi2 for (phi1, phi2) in itertools.combinations(phi, 2)]
)
v2_2x = np.cos(2.*deltaphi).mean()
v2_2y = np.sin(2.*deltaphi).mean()
v2_2 = (v2_2x*v2_2x + v2_2y*v2_2y)**.5
print(v2_2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment