Skip to content

Commit 7613bd2

Browse files
Update icbuilder.py
1 parent 583b592 commit 7613bd2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

tools/icbuilder.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import random
2+
import math
3+
14
_particles = []
25

36
def particleAdd(x, y, z, vx, vy, vz, m):
@@ -6,4 +9,17 @@ def particleAdd(x, y, z, vx, vy, vz, m):
69
def save(filename):
710
with open(filename, "w") as f:
811
for p in _particles:
9-
f.write(" ".join(str(v) for v in p) + "\n")
12+
13+
f.write(" ".join(str(v) for v in p) + "\n")
14+
15+
def plummer(N, scale=1.0, mass=1.0):
16+
for _ in range(N):
17+
r = scale / math.sqrt(random.random()**(-2/3) - 1)
18+
theta = math.acos(2*random.random() - 1)
19+
phi = 2 * math.pi * random.random()
20+
21+
x = r * math.sin(theta) * math.cos(phi)
22+
y = r * math.sin(theta) * math.sin(phi)
23+
z = r * math.cos(theta)
24+
25+
particleAdd(x, y, z, 0, 0, 0, mass / N)

0 commit comments

Comments
 (0)