Examples

Energy measurement

_images/energy.png
import numpy as np
import astrohut as ah
import matplotlib.pyplot as plt

G = 1.0
m = 1.0

pos = np.random.normal(size=(100, 2))

speeds = ah.generateSpeeds(pos, G, m)
system = ah.createArray(pos, speeds)

sim = ah.Simulation(system, dim = 2, dt = 1e-4, G = G, mass_unit = m)

sim.start(10000, save_to_array_every = 250, print_progress = True)

plt.plot(sim.getEnergies())
plt.xlabel("Saved instants of time")
plt.ylabel("Energy")

# plt.savefig("energy.png")
plt.show()

2d examples

random2d

_images/random2d.gif
import numpy as np
import astrohut as ah
import matplotlib.pyplot as plt

G = 1.0
m = 1.0

pos = np.random.normal(size=(100, 2))

speeds = ah.generateSpeeds(pos, G, m)
system = ah.createArray(pos, speeds)

sim = ah.Simulation(system, dim = 2, dt = 1e-4, G = G, mass_unit = m)

sim.start(1000, save_to_array_every = 25)

# if boxes are wanted: boxed = True, else: boxed = False
ani = sim.makeAnimation(boxed = True)

# ani.save("random2d.gif", writer="imagemagick", dpi = 72, fps = 12)
plt.show()

3d examples

random3d

_images/random3d.gif
import numpy as np
import astrohut as ah
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

G = 1.0
m = 1.0

pos = np.random.normal(size=(25, 3))
speeds = ah.generateSpeeds(pos, G, m)

system = ah.createArray(pos, speeds)

sim = ah.Simulation(system, dim = 3, dt = 1e-3, G = G, mass_unit = m)

sim.start(1000, save_to_array_every = 25)

# if boxes are wanted: boxed = True, else: boxed = False
ani = sim.makeAnimation(boxed = True)

# ani.save("random3d.gif", writer="imagemagick", dpi = 72, fps = 12)
plt.show()

disk3d

_images/disk3d.gif
import numpy as np
import astrohut as ah
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

G = 1.0
m = 1.0

pos = np.zeros((25, 3))
pos[:, :2] = np.random.normal(size=(pos.shape[0], 2))
speeds = ah.generateSpeeds(pos, G, m)

system = ah.createArray(pos, speeds)

sim = ah.Simulation(system, dim = 3, dt = 1e-3, G = G, mass_unit = m)

sim.start(1000, save_to_array_every = 25)

# if boxes are wanted: boxed = True, else: boxed = False
ani = sim.makeAnimation(boxed = True)

# ani.save("disk3d.gif", writer="imagemagick", dpi = 72, fps = 12)
plt.show()

collision3d

_images/collision3d.gif
import numpy as np
import astrohut as ah
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

G = 1.0
m = 1.0
N = 50

pos1 = np.zeros((N, 3))
pos2 = np.zeros_like(pos1)

pos1[:, :2] = np.random.normal(size = (N, 2))

pos2[:, :2] = np.random.normal(loc = 3.0, size = (N, 2))
pos2[:, 2] = 5.0

speeds1 = ah.generateSpeeds(pos1, G, m)
speeds2 = ah.generateSpeeds(pos2, G, m)

pos = np.vstack((pos1, pos2))
speeds = np.vstack((speeds1, speeds2))

system = ah.createArray(pos, speeds)

sim = ah.Simulation(system, dim = 3, dt = 1e-3, G = G, mass_unit = m, epsilon = 1e-2)

sim.start(5000, save_to_array_every = 125, print_progress = True)

# if boxes are wanted: boxed = True
ani = sim.makeAnimation()

sim.ax.set_xlim(-3, 5)
sim.ax.set_ylim(-3, 5)

# ani.save("collision3d.gif", writer="imagemagick", dpi = 72, fps = 12)
plt.show()