Skip to content
Snippets Groups Projects

BHT algorithm and Galaxy Collision Sim improvements

Closed jakut77 requested to merge jt/bhtfin into main
Files
3
+ 23
12
@@ -9,6 +9,12 @@ class MainApp:
def __init__(self):
"""Initialize the MainApp with a root node."""
self.root_x = 0
self.root_y = 0
self.root_z = 0
self.root_width = 100
self.root_height = 100
self.root_depth = 100
self.rootNode = TreeNode(x=0, y=0, z=0, width=100, height=100, depth=100)
def BuildTree(self, particles):
@@ -24,17 +30,21 @@ class MainApp:
def ResetTree(self, particles):
"""Reset the Octtree by reinitializing the root node."""
# Define the size of the rootNode based on the positions of the particles
#min_x = min([particle.x for particle in particles])
#min_y = min([particle.y for particle in particles])
#min_z = min([particle.z for particle in particles])
#max_x = max([particle.x for particle in particles])
#max_y = max([particle.y for particle in particles])
#max_z = max([particle.z for particle in particles])
#root_height = max_y - min_y
#root_width = max_x - min_x
#root_depth = max_z - min_z
#self.rootNode = TreeNode(x=min_x, y=min_y, z=min_z, width=root_width, height=root_height, depth=root_depth)
self.rootNode = TreeNode(x=0, y=0, z=0, width=100, height=100, depth=100)
if not all(self.rootNode.contains(particle) for particle in particles):
# if a particle exits the boundary, increase the size of the boundary
self.root_x -= self.root_width / 2
self.root_y -= self.root_height / 2
self.root_z -= self.root_depth / 2
self.root_width *= 2
self.root_height *= 2
self.root_depth *= 2
self.rootNode = TreeNode(x=self.root_x,
y=self.root_y,
z=self.root_z,
width=self.root_width,
height=self.root_height,
depth=self.root_depth)
class Particle:
@@ -311,6 +321,7 @@ class TreeNode:
"""
#G = 6.674 * (10 ** -11) # Gravitational constant
G = 1
#G = 4 * np.pi**2 # AU^3 / m / yr^2
dx = particle2.x - particle1.x
dy = particle2.y - particle1.y
@@ -363,4 +374,4 @@ class TreeNode:
self.mass = total_mass
else:
self.center_of_mass = np.array([0.0, 0.0, 0.0])
self.mass = 0
\ No newline at end of file
self.mass = 0
Loading