plt.quiver( nbody.particle_mesh.particles.x, nbody.particle_mesh.particles.y, nbody.particle_mesh.acceleration[:, 0], nbody.particle_mesh.acceleration[:, 1], color="forestgreen", ) plt.quiver( nbody.particle_mesh.particles.x, nbody.particle_mesh.particles.y, nbody.particle_mesh.particles.vx, nbody.particle_mesh.particles.vy, color="darkorange", ) plt.text( 0.5 * grid_length, 0.9 * grid_length, f"t = {i * dt * oversamp:.3f}", horizontalalignment="left", ) plt.text( -0.9 * grid_length, 0.9 * grid_length, f"E = {nbody.particle_mesh.total_energy:.3f}", horizontalalignment="left", ) plt.pause(0.0001) plt.close() nbody.save("./test_data_nbody.npz")
# Initializing a System() object via the lattice() function L = lattice(**lattice_kwargs) x1, x2 = (-15, -5), (25, 25) v1, v2 = (100, 90), (-110, -100) w1, w2 = 0, 0 m1, m2 = 1E6, 1E6 q1, q2 = 1E-5, -1E-5 r1, r2 = 0.1, 0.1 # Creating two new Sphere() objects P1 = Sphere(x1, v1, w1, m1, q1, r1) P2 = Sphere(x2, v2, w2, m2, q2, r2) # Adding the new particles to the System L.add(P1) L.add(P2) T = 0.5 dt = 1E-3 # Solving for the given T and dt L.solve(T, dt, collision = True) # Saving the results to file save(L, filename) # Saving an animation of the system animate(L, filename)
filename = "railgun" sign = -1 N = 40 y_top = 4 y_bottom = 2 radii = 0.5 masses = 1E6 charges = 1E-3 particles = [] x0 = -50 for i in range(N): xA = (x0+2*i*radii+0.1, y_top) A = Sphere(xA, (0,0), 0, masses, sign*charges, radii) particles.append(A) xB = (x0+2*i*radii+0.1, y_bottom) B = Sphere(xB, (0,0), 0, masses, sign*charges, radii) particles.append(B) sign *= -1 P = Sphere([x0-3, (y_top + y_bottom)/2], [0.5,0], [0], 1, 1E-3, 0.3) S = lattice((5,5), 10, 0, 0.01, 1) for i in particles: S.add(i) S.add(P) S.solve(0.5, 1E-3) save(S, filename) animate(S, filename)