@@ -12,7 +12,7 @@ def save(filename):
1212
1313 f .write (" " .join (str (v ) for v in p ) + "\n " )
1414
15- def plummer (N , scale = 1.0 , mass = 1.0 ):
15+ def coldPlummer (N , scale = 1.0 , mass = 1.0 ):
1616 for _ in range (N ):
1717 r = scale / math .sqrt (random .random ()** (- 2 / 3 ) - 1 )
1818 theta = math .acos (2 * random .random () - 1 )
@@ -23,3 +23,44 @@ def plummer(N, scale=1.0, mass=1.0):
2323 z = r * math .cos (theta )
2424
2525 particleAdd (x , y , z , 0 , 0 , 0 , mass / N )
26+
27+ def disk (N , radius = 10.0 , mass = 1.0 , thickness = 0.1 ):
28+ """
29+ Generates a simple equilibrium-ish exponential disk galaxy.
30+ - N: number of particles
31+ - radius: scale length of the disk
32+ - mass: total mass of the disk
33+ - thickness: vertical Gaussian thickness
34+ """
35+
36+ M = mass
37+ for _ in range (N ):
38+ # Sample radius from exponential disk: p(r) ~ r * exp(-r/R)
39+ u = random .random ()
40+ r = - radius * math .log (1 - u ) # inverse CDF
41+
42+ # Random angle
43+ phi = 2 * math .pi * random .random ()
44+
45+ # Position in the plane
46+ x = r * math .cos (phi )
47+ y = r * math .sin (phi )
48+
49+ # Vertical position (Gaussian)
50+ z = random .gauss (0 , thickness )
51+
52+ # Circular velocity: v = sqrt(GM(r)/r)
53+ # Here G = 1 in your units, and M(r) ~ M * (1 - exp(-r/R)*(1+r/R))
54+ # This is a rough approximation but stable enough for NEXT.
55+ enclosed = M * (1 - math .exp (- r / radius ) * (1 + r / radius ))
56+ v = math .sqrt (enclosed / (r + 1e-6 ))
57+
58+ # Tangential velocity
59+ vx = - v * math .sin (phi )
60+ vy = v * math .cos (phi )
61+
62+ # Small vertical velocity dispersion
63+ vz = random .gauss (0 , 0.05 * v )
64+
65+ particleAdd (x , y , z , vx , vy , vz , mass / N )
66+
0 commit comments