Skip to content

Commit 7f3ed13

Browse files
Update icbuilder.py
1 parent 5c23b6c commit 7f3ed13

1 file changed

Lines changed: 47 additions & 14 deletions

File tree

tools/icbuilder.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,72 @@ def diskNoDM(N, radius=10.0, mass=1.0, thickness=0.1):
8383

8484
return particles
8585

86-
def disk(N, radius=10.0, mass=1.0, thickness=0.1, dm_fraction=0.9):
86+
def disk(N_disk=1000, N_halo=2000,
87+
radius=10.0, mass_disk=1.0,
88+
mass_halo=5.0, thickness=0.1, halo_scale=20.0):
8789
"""
88-
Exponential disk with DM halo.
90+
Exponential disk + Hernquist DM halo, with velocities.
91+
- N_disk: number of disk particles
92+
- N_halo: number of halo particles
93+
- radius: disk scale length
94+
- mass_disk: total baryonic disk mass
95+
- mass_halo: total DM halo mass
96+
- thickness: vertical Gaussian thickness
97+
- halo_scale: Hernquist scale radius for halo
8998
"""
99+
90100
particles = []
91-
M_b = mass * (1 - dm_fraction)
92-
M_dm = mass * dm_fraction
93101

94-
# baryonic disk
95-
for _ in range(N):
102+
# --- Disk (baryons, type=0) ---
103+
for _ in range(N_disk):
104+
# Sample radius from exponential disk
96105
u = random.random()
97106
r = -radius * math.log(1 - u)
98107
phi = 2 * math.pi * random.random()
108+
109+
# Position
99110
x = r * math.cos(phi)
100111
y = r * math.sin(phi)
101112
z = random.gauss(0, thickness)
102-
enclosed = M_b * (1 - math.exp(-r / radius) * (1 + r / radius))
103-
v = math.sqrt(enclosed / (r + 1e-6))
113+
114+
# Enclosed mass: disk + halo contribution
115+
M_disk_enclosed = mass_disk * (1 - math.exp(-r / radius) * (1 + r / radius))
116+
M_halo_enclosed = mass_halo * (r**2 / (r + halo_scale)**2) # Hernquist cumulative
117+
M_enclosed = M_disk_enclosed + M_halo_enclosed
118+
119+
# Circular velocity
120+
v = math.sqrt(M_enclosed / (r + 1e-6))
121+
122+
# Tangential velocity
104123
vx = -v * math.sin(phi)
105124
vy = v * math.cos(phi)
106-
vz = random.gauss(0, 0.05 * v)
107-
particles.append((x, y, z, vx, vy, vz, M_b / N, 0))
125+
vz = random.gauss(0, 0.05 * v) # vertical dispersion
108126

109-
# DM halo (simple Hernquist sphere)
110-
for _ in range(N):
127+
particles.append((x, y, z, vx, vy, vz, mass_disk / N_disk, 0))
128+
129+
# --- DM Halo (type=1) ---
130+
for _ in range(N_halo):
131+
# Sample Hernquist radius
111132
u = random.random()
112-
r = radius * math.sqrt(u) / (1 - math.sqrt(u))
133+
r = halo_scale * math.sqrt(u) / (1 - math.sqrt(u))
113134
theta = math.acos(2*random.random() - 1)
114135
phi = 2 * math.pi * random.random()
136+
137+
# Position
115138
x = r * math.sin(theta) * math.cos(phi)
116139
y = r * math.sin(theta) * math.sin(phi)
117140
z = r * math.cos(theta)
118-
particles.append((x, y, z, 0, 0, 0, M_dm / N, 1))
141+
142+
# Approximate isotropic velocity dispersion for Hernquist halo
143+
# sigma^2 ~ GM(r)/(2r)
144+
M_halo_enclosed = mass_halo * (r**2 / (r + halo_scale)**2)
145+
sigma = math.sqrt(M_halo_enclosed / (2 * (r + 1e-6)))
146+
147+
vx = random.gauss(0, sigma)
148+
vy = random.gauss(0, sigma)
149+
vz = random.gauss(0, sigma)
150+
151+
particles.append((x, y, z, vx, vy, vz, mass_halo / N_halo, 1))
119152

120153
return particles
121154

0 commit comments

Comments
 (0)