def richardson_error(body_list, h, G, thetamax=0, n_steps=1, epsilon=0, DM_mass=0): h1_bodies = copy.copy(body_list) h2_bodies = copy.copy(body_list) h4_bodies = copy.copy(body_list) cs.LeapFrogC(h1_bodies, h, 4 * n_steps, thetamax, G, epsilon, DM_mass) cs.LeapFrogC(h2_bodies, 2 * h, 2 * n_steps, thetamax, G, epsilon, DM_mass) cs.LeapFrogC(h4_bodies, 4 * h, n_steps, thetamax, G, epsilon, DM_mass) pos_h1, vel_h1, _ = utils.unzip_bodylist(h1_bodies) pos_h2, vel_h2, _ = utils.unzip_bodylist(h2_bodies) pos_h4, vel_h4, _ = utils.unzip_bodylist(h4_bodies) pos_h1 = pos_h1[:, 0:1].flatten() vel_h1 = vel_h1[:, 0:1].flatten() pos_h2 = pos_h2[:, 0:1].flatten() vel_h2 = vel_h2[:, 0:1].flatten() pos_h4 = pos_h4[:, 0:1].flatten() vel_h4 = vel_h4[:, 0:1].flatten() return np.log2(richardson_fraction(pos_h1, pos_h2, pos_h4)), np.log2( richardson_fraction(vel_h1, vel_h2, vel_h4))
velocities = [np.zeros(3)] masses = [m_BH] for r in np.arange(1, 30)*25: # add stars in rings around black hole for theta in np.linspace(0, 2*np.pi, int(3*r/25))[:-1]: positions.append(np.array([r*np.sin(theta), r*np.cos(theta), 0])) velocities.append(np.array([np.cos(theta), -np.sin(theta), 0])*np.sqrt(G*m_BH/r)) masses.append(10) positions = np.array(positions) velocities = np.array(velocities) N = len(positions) all_pos = np.concatenate((positions + center1, positions + center2)) all_vel = np.concatenate((velocities + v1, velocities + v2)) all_m = masses + masses total_bodylist = utils.zip_to_bodylist(all_pos, all_vel, all_m) total_bodylist.check_integrity() print("Benchmarking collision of 2 galaxies with parameters: ") print(f"""\ Number of objects: {N} dt: {dt} thetamax: {thetamax} n_steps: {n_steps} G: {G} """) begin = time.time() cs.LeapFrogC(total_bodylist, dt, n_steps, thetamax, G) end = time.time() print(f"Simulation finished after {end-begin} s")
-np.sum(velocities * m_star, axis=0) / m_bh, 0) print("-----") print('\n'.join([str((var, getsizeof(a))) for var, a in locals().items()])) # print(velocities) # print(velocities*np.expand_dims(masses, axis=0).T) # print(np.sum(velocities*np.expand_dims(masses, axis=0).T, axis=0)) return positions, velocities, masses thetamax = 0.7 n_steps = 2001 m_star = sc.Msol # 3.181651515706176e+30 n_star = int(1e5) pos, vel, mass = genStableGalaxy(n_star, m_star * 10, sc.Msgra) galaxy1 = make_body_array(pos, vel, mass) galaxy2 = utils.zip_to_bodylist(pos, vel, mass) del pos, vel, mass # t1 = time() # result = g.LeapFrog(galaxy1, dt=1e12, n_steps=n_steps, G=sc.G) # t2 = time() # print(f"GPU: {t2-t1} s") t1 = time() cs.LeapFrogC(galaxy2, dt=1e12, n_steps=n_steps, G=sc.G, thetamax=0.7) t2 = time() print(f"CPU: {t2-t1} s")
def run_CPU(galaxy): galaxy_b = utils.zip_to_bodylist(*galaxy) t1 = time() cs.LeapFrogC(galaxy_b, dt=1e12, n_steps=n_steps, G=sc.G, thetamax=0.7) t2 = time() return t2-t1
v_unit_vec_DM.append( np.array([1, 1, factor**(1 - attenuation_z)]) * (np.cos(gamma[i]) * b1 + np.sin(gamma[i]) * b2)) v_unit_vec_DM = np.array(v_unit_vec_DM) velocities_DM = v_norm_DM.reshape((n_DM_particles, 1)) * v_unit_vec_DM plt.subplot(121) plt.hist(np.linalg.norm(velocities, axis=1)) plt.subplot(122) plt.hist(np.linalg.norm(velocities, axis=1)) galaxy = gen_galaxy(posarray, posarrayDM, m_stars, m_DM, velocities, velocities_DM) print("Done with step 1") result = cs.LeapFrogC(galaxy, dt=1e12, n_steps=n_steps, thetamax=thetamax, G=sc.G, epsilon=4e16) result = cs.LeapFrogSaveC(galaxy, dt=1e12, n_steps=save_steps, thetamax=thetamax, G=sc.G, save_every=10, epsilon=4e16) result.save("bolletjes_test.binv") print("Done saving") #PQ.speedcurve(result.numpy(), -1)