increasing performances

explicit for loop instead of sum in Node.get_force
This commit is contained in:
Crizomb 2023-02-15 13:38:55 +01:00 committed by GitHub
parent e93cae162b
commit 8b2b2a9c34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -117,7 +117,13 @@ class Node:
if self.is_external or self.width*self.width / dist_squared < THETA_SQUARED:
return newton_law(self.mass, star.mass, self.center - star.pos)
else:
return sum((child.get_force(star) for child in self.children), Vec3.zero())
acc = Vec3.zero()
for child in self.children:
acc += child.get_force(star)
return acc
#return sum((child.get_force(star) for child in self.children), Vec3.zero()) #slower
"""Init simulation"""