Skip to content

Commit 801ab57

Browse files
Update icbuilder.py
1 parent d252e21 commit 801ab57

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tools/icbuilder.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,48 @@ def coldPlummer(N, scale=1.0, mass=1.0, dm_fraction=0.9):
4141

4242
return particles
4343

44+
def disk(N, radius=10.0, mass=1.0, thickness=0.1):
45+
"""
46+
Generates a simple equilibrium-ish exponential disk galaxy.
47+
- N: number of particles
48+
- radius: scale length of the disk
49+
- mass: total mass of the disk
50+
- thickness: vertical Gaussian thickness
51+
"""
52+
53+
particles = []
54+
M = mass
55+
56+
for _ in range(N):
57+
# Sample radius from exponential disk: p(r) ~ r * exp(-r/R)
58+
u = random.random()
59+
r = -radius * math.log(1 - u)
60+
61+
# Random angle
62+
phi = 2 * math.pi * random.random()
63+
64+
# Position in the plane
65+
x = r * math.cos(phi)
66+
y = r * math.sin(phi)
67+
68+
# Vertical position (Gaussian)
69+
z = random.gauss(0, thickness)
70+
71+
# Circular velocity
72+
enclosed = M * (1 - math.exp(-r / radius) * (1 + r / radius))
73+
v = math.sqrt(enclosed / (r + 1e-6))
74+
75+
# Tangential velocity
76+
vx = -v * math.sin(phi)
77+
vy = v * math.cos(phi)
78+
79+
# Small vertical velocity dispersion
80+
vz = random.gauss(0, 0.05 * v)
81+
82+
particles.append((x, y, z, vx, vy, vz, mass / N, 0))
83+
84+
return particles
85+
4486
def disk(N, radius=10.0, mass=1.0, thickness=0.1, dm_fraction=0.9):
4587
"""
4688
Exponential disk with DM halo.

0 commit comments

Comments
 (0)