Skip to content

Commit f392cb0

Browse files
Update icbuilder.py
1 parent 987d99f commit f392cb0

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tools/icbuilder.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,36 @@ def random_solar_system(
344344
particles.append((mx, my, mz, mvx, mvy, mvz, mm, 0))
345345

346346
return particles
347+
348+
def spiral_ic(N, A=1.0, B=1.0, arms=2, mass=1.0, noise=0.02):
349+
"""
350+
Generates particles along the logarithmic spiral:
351+
r(phi) = A * log( B * tan(phi / (2*arms)) )
352+
- N: number of particles
353+
- A, B: spiral parameters
354+
- arms: number of spiral arms (N in your formula)
355+
- mass: total mass
356+
- noise: random positional jitter
357+
type = 0 (baryons)
358+
"""
359+
import math, random
360+
particles = []
361+
362+
for i in range(N):
363+
# angle along spiral
364+
phi = random.uniform(0.1, math.pi * 2 * arms - 0.1)
365+
366+
# radius from your formula
367+
r = A * math.log(B * math.tan(phi / (2 * arms)))
368+
369+
# convert to Cartesian
370+
x = r * math.cos(phi) + noise * (random.random() - 0.5)
371+
y = r * math.sin(phi) + noise * (random.random() - 0.5)
372+
z = noise * (random.random() - 0.5)
373+
374+
# no initial velocity (cold start)
375+
vx = vy = vz = 0.0
376+
377+
particles.append((x, y, z, vx, vy, vz, mass / N, 0))
378+
379+
return particles

0 commit comments

Comments
 (0)