Skip to content

Commit 1631918

Browse files
Added even more features to icmaker
1 parent dfb551a commit 1631918

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

tools/icbuilder.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,87 @@ def two_galaxies(
133133
m
134134
))
135135

136-
return particles
136+
return particles
137+
138+
def composite_galaxy(
139+
N_bulge, bulge_scale, bulge_mass,
140+
N_disk, disk_scale, disk_mass, disk_thickness=0.1,
141+
N_halo=0, halo_scale=1.0, halo_mass=0.0
142+
):
143+
"""
144+
Builds a composite galaxy:
145+
- Hernquist bulge
146+
- Exponential disk
147+
- Optional Hernquist halo
148+
"""
149+
150+
particles = []
151+
152+
# Bulge
153+
if N_bulge > 0:
154+
bulge = hernquist(N_bulge, bulge_scale, bulge_mass)
155+
particles.extend(bulge)
156+
157+
# Disk
158+
if N_disk > 0:
159+
disk_p = disk(N_disk, disk_scale, disk_mass, disk_thickness)
160+
particles.extend(disk_p)
161+
162+
# Halo (optional)
163+
if N_halo > 0:
164+
halo = hernquist(N_halo, halo_scale, halo_mass)
165+
particles.extend(halo)
166+
167+
return particles
168+
169+
def uniform_sphere(N, radius=1.0, mass=1.0):
170+
particles = []
171+
for _ in range(N):
172+
# Sample inside sphere with r ∝ u^(1/3)
173+
u = random.random()
174+
r = radius * (u ** (1/3))
175+
176+
theta = math.acos(2*random.random() - 1)
177+
phi = 2 * math.pi * random.random()
178+
179+
x = r * math.sin(theta) * math.cos(phi)
180+
y = r * math.sin(theta) * math.sin(phi)
181+
z = r * math.cos(theta)
182+
183+
particles.append((x, y, z, 0, 0, 0, mass / N))
184+
return particles
185+
186+
def binary_system(separation=1.0, mass1=1.0, mass2=1.0):
187+
M = mass1 + mass2
188+
r1 = -mass2 / M * separation
189+
r2 = mass1 / M * separation
190+
191+
v = math.sqrt(M / separation)
192+
193+
return [
194+
(r1, 0, 0, 0, v, 0, mass1),
195+
(r2, 0, 0, 0, -v, 0, mass2)
196+
]
197+
198+
def three_body_figure_eight(mass=1.0):
199+
"""
200+
Classic equal-mass figure-eight three-body solution.
201+
Positions and velocities are scaled to G = 1.
202+
"""
203+
204+
m = mass
205+
206+
# Standard initial conditions (Chenciner & Montgomery / Moore orbit)
207+
x1, y1 = -0.97000436, 0.24308753
208+
x2, y2 = 0.97000436, -0.24308753
209+
x3, y3 = 0.0, 0.0
210+
211+
vx1, vy1 = 0.4662036850, 0.4323657300
212+
vx2, vy2 = 0.4662036850, 0.4323657300
213+
vx3, vy3 = -0.93240737, -0.86473146
214+
215+
return [
216+
(x1, y1, 0.0, vx1, vy1, 0.0, m),
217+
(x2, y2, 0.0, vx2, vy2, 0.0, m),
218+
(x3, y3, 0.0, vx3, vy3, 0.0, m),
219+
]

0 commit comments

Comments
 (0)