G = 6.63784e-11 cm_to_m = 1. / 100. msun_to_g = 1.988e33 pc_to_m = 3.08567758128e16 gcm_to_msunpc = 5.03e-34 * (3.086e18)**2 def print_log(time, gravity, particles, total_energy_at_t0): kinetic_energy = gravity.kinetic_energy potential_energy = gravity.potential_energy total_energy_at_this_time = kinetic_energy + potential_energy print "time : " , time print "energy error : " , (total_energy_at_this_time - total_energy_at_t0) / total_energy_at_t0 def simulate_small_cluster( number_of_stars = 1000., end_time = 40 | nbody_system.time, number_of_workers = 1 ): #convert_nbody = nbody_system.nbody_to_si(number_of_stars | units.MSun, 1. | units.parsec)
f.close() return def gasvel_potential(sigma_cl, mstars, eps, k_rho, k_P=1., f_g=1., phi_Pc=4./3., phi_Pbar=1.32, R=None): #R = 0.05 * np.power(A / (k_P**2 * eps**2 * phi_Pc * phi_Pbar), 1./4.) * np.power(np.sum(mstars) / 30., 1./2.) * sigma_cl**(-1./2.) * pc_to_m if R is None: R = clump_radius(mstars, sigma_cl, eps, k_rho, k_P, f_g, phi_Pc, phi_Pbar) * pc_to_m #return G / (2. * (5. - 2. * k_rho)) / R * (np.sum(mstars) * msun_to_g / 1000.)**2 return - 3. / 5. * (1. - k_rho / 3.) / (1. - 2. * k_rho / 5.) * G * (np.sum(mstars) * msun_to_g / 1000.)**2. / R def gasvel_ke(mstars, sigma_cl, eps, phi_b, k_rho, k_P=1., f_g=1., phi_Pc=4./3., phi_Pbar=1.32, R=None): """ Calculates the kinetic energy expected for a cluster with stars moving using a mass-averaged velocity dispersion. mstars: array_like Masses of the stars in solar masses sigma: float Mass-averaged velocity dispersion in km/s """ sigma = gasveldisp(mstars, sigma_cl, eps, phi_b, k_rho, k_P, f_g, phi_Pc, phi_Pbar)# * 7./6. print(sigma) #R = 0.05 * np.power(A / (k_P**2 * eps**2 * phi_Pc * phi_Pbar), 1./4.) * np.power(np.sum(mstars) / 30., 1./2.) * sigma_cl**(-1./2.) if R is None: R = clump_radius(mstars, sigma_cl, eps, k_rho, k_P, f_g, phi_Pc, phi_Pbar) rho_s = (3. - k_rho) / (4. * np.pi) / R**3. #print(sigma) #print(rho_s) #print(R_s) return 3./2. * (np.sum(mstars) * msun_to_g / 1000.) * (sigma * 1000.)**2. #return 2. * np.pi * (rho_s * np.sum(mstars) * msun_to_g / 1000) * (np.sqrt(3.) * sigma * 1000)**2. * R**3. / (5. - 2. * k_rho) def radii(pos): return np.sqrt((pos[ : , 0].value_in(units.parsec))**2 + (pos[ : , 1].value_in(units.parsec))**2 +(pos[ : , 2].value_in(units.parsec))**2) def convert_to_nbody(mass, cluster): """ Converts a cluster to nbody units using the prescription of Heggie & Mathieu 1986 """ Gun = G | units.m**3 * units.kg**-1. * units.s**-2. mtot = np.sum(mass) ke = cluster.kinetic_energy() pe = cluster.potential_energy() etot = ke + pe if etot > 0 | units.m**2 * units.kg * units.s**-2: etot *= -1.
subplot.scatter( positions[...,0].value_in(nbody_system.length), positions[...,1].value_in(nbody_system.length), s = 1, edgecolors = 'red', facecolors = 'red' ) subplot.set_xlim(-4.0,4.0) subplot.set_ylim(-4.0,4.0) subplot.set_aspect(1.) title = 'time = {0:.2f}'.format(time.value_in(nbody_system.time)) subplot.set_title(title)#, fontsize=12) spines = [] if index % plot_matrix_size == 0: spines.append('left') if index >= ((number_of_rows - 1)*plot_matrix_size): spines.append('bottom') adjust_spines(subplot, spines,np.arange(-4.0,4.1, 1.0)) if index % plot_matrix_size == 0: subplot.set_ylabel('y') if index >= ((number_of_rows - 1)*plot_matrix_size): subplot.set_xlabel('x') plt.savefig('simple_cluster_powerlaw.png', clobber=True) def write_init_file(m, pos, vel, fname): """ Writes the initial masses, positions, and velocities of a cluster to a file. """ f = open(fname, 'w') for i in np.arange(np.size(m)): f.write(str(m[i]) + '\t' + str(pos[i,0]) + '\t' + str(pos[i,1]) + '\t' + str(pos[i,2]) + '\t' + str(vel[i,0]) + '\t' + '\t' + str(vel[i,1]) + '\t' + str(vel[i,2]) + '\n')