Skip to content

Commit 60e0a13

Browse files
Update icbuilder.py
1 parent 2df6fdd commit 60e0a13

1 file changed

Lines changed: 47 additions & 39 deletions

File tree

tools/icbuilder.py

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -345,67 +345,75 @@ def random_solar_system(
345345

346346
return particles
347347

348-
def spiral_galaxy_ic(N_disk=3000, N_halo=3000,
349-
disk_mass=1.0, halo_mass=5.0,
350-
_a=10.0,
351-
a=3.0, b=0.3, halo m=2, k=5.0, epsilon=0.07):
348+
def miyamoto_nagai_galaxy(
349+
N_disk=5000,
350+
N_halo=8000,
351+
M_disk=1.0,
352+
M_halo=5.0,
353+
a=3.0,
354+
b=0.5,
355+
halo_scale=20.0
356+
):
352357
"""
353-
Generates a spiral galaxy with:
354-
- Miyamoto–Nagai=0) with spiral arms disk (baryons, type1)
355-
- N_disk: number of disk particles
356-
- Hernquist halo (DM, type=
357-
- N_halo: number of halo particles
358-
- disk_mass mass
359-
- halo: total baryonic_mass: total DM mass height
360-
- halo_a: Hernquist scale radius
361-
- m: number of spiral arms
362-
- k: spiral
363-
- a, b: disk scale length and pitch parameter
364-
- epsilon: spiral
358+
Miyamoto–Nagai disk + Hernquist DM halo.
359+
Returns particles in format:
360+
(x, y, z, vx, vy, vz, mass, type)
361+
type=0 -> disk (baryons)
362+
type=1 -> dark matter
365363
"""
366-
particles perturbation amplitude = []
367364

368-
# --- Disk ---
365+
import random, math
366+
particles = []
367+
368+
# -------------------------
369+
# 1. Disk (Miyamoto–Nagai)
370+
# -------------------------
369371
for _ in range(N_disk):
372+
373+
# Sample radius from exponential-like distribution
370374
u = random.random()
371375
R = -a * math.log(1 - u)
372-
phi = 2 * math.pi * random.random()
373376

374-
# Spiral perturbation
375-
* math.cos(m * phi + k * math.log(R R *= 1 + epsilon + 1e-3))
377+
phi = 2 * math.pi * random.random()
378+
z = random.gauss(0, b)
376379

377380
x = R * math.cos(phi)
378381
y = R * math.sin(phi)
379-
z = random zd = math.gauss(0, b / 2)
380382

381-
.sqrt(z**2 + b**2)
382-
denom = (R**2 + (a + zd.sin(phi)
383-
vy = v_circ * math.cos(phi)
384-
vz = random.gauss)**2)**1.5
385-
v_circ = math.sqrt(disk_mass * R**2 / denom)
383+
# MN circular velocity
384+
B = math.sqrt(z*z + b*b)
385+
denom = math.sqrt(R*R + (a + B)**2)
386+
v_circ = math.sqrt(M_disk * R*R / (denom**3 + 1e-6))
386387

387-
vx = -v_circ * math.append((x, y, z(0, 0.05 * v_circ)
388+
vx = -v_circ * math.sin(phi)
389+
vy = v_circ * math.cos(phi)
390+
vz = random.gauss(0, 0.05 * v_circ)
388391

389-
particles, vx, vy, vz, disk_mass / N_disk, 0))
392+
particles.append((x, y, z, vx, vy, vz, M_disk / N_disk, 0))
390393

391-
# --- Halo ---
394+
# -------------------------
395+
# 2. Halo (Hernquist)
396+
# -------------------------
392397
for _ in range(N_halo):
398+
393399
u = random.random()
394-
theta = math.ac() - 1)
395-
phi r = halo_a * math.sqrt(u) / (1 - math.sqrt(u))
396-
os(2 * random.random = 2 * math.pi * random.random()
400+
r = halo_scale * math.sqrt(u) / (1 - math.sqrt(u))
401+
402+
theta = math.acos(2*random.random() - 1)
403+
phi = 2 * math.pi * random.random()
397404

398405
x = r * math.sin(theta) * math.cos(phi)
399406
y = r * math.sin(theta) * math.sin(phi)
400-
z =)
407+
z = r * math.cos(theta)
401408

402-
M_enc = halo_mass * ( r * math.cos(thetar**2 / (r + halo_a)**2)
403-
sigma / (2 * (r + 1e-6)))
409+
# isotropic dispersion
410+
M_enc = M_halo * (r*r / (r + halo_scale)**2)
411+
sigma = math.sqrt(M_enc / (2 * (r + 1e-6)))
404412

405-
vx = random.gauss( = math.sqrt(M_enc0, sigma)
413+
vx = random.gauss(0, sigma)
406414
vy = random.gauss(0, sigma)
407-
(0, sigma)
415+
vz = random.gauss(0, sigma)
408416

409-
((x, y, z, vx, vy vz = random.gauss particles.append, vz, halo_mass / N_halo, 1))
417+
particles.append((x, y, z, vx, vy, vz, M_halo / N_halo, 1))
410418

411419
return particles

0 commit comments

Comments
 (0)