def test2(self): seed(1) particles=new_plummer_model(10000) instance = Agama(type="Multipole", particles=particles) result=instance.get_potential_at_point( 0.|generic_unit_system.length, 0.|generic_unit_system.length, 0.|generic_unit_system.length, 0.|generic_unit_system.length) self.assertLess(abs(result/(-16./3/3.1416| generic_unit_system.length**2/generic_unit_system.time**2) - 1), 0.04) scaleM=1234|units.MSun scaleR=5.6 |units.parsec converter=nbody_system.nbody_to_si(scaleM,scaleR) particles=new_plummer_model(20000, convert_nbody=converter) instance = Agama(converter, type="Multipole", particles=particles) x=3.|units.parsec y=4.|units.parsec z=5.|units.parsec r=(x*x+y*y+z*z)**0.5 result=instance.get_gravity_at_point(0|units.parsec, x, y, z) expected=-constants.G*scaleM/(r*r+(3*3.1416/16*scaleR)**2)**1.5*x self.assertLess(abs(result[0]/expected-1), 0.03) self.assertLess(abs(result[2]/result[0]-z/x), 0.03) instance.stop()
def test1(self): M=10. a=2. x=1. y=2. z=3. r=(x*x+y*y+z*z)**0.5 instance = Agama(type="Dehnen", mass=M|generic_unit_system.mass, scaleRadius=a|generic_unit_system.length) result=instance.get_potential_at_point( 0.|generic_unit_system.length, x |generic_unit_system.length, y |generic_unit_system.length, z |generic_unit_system.length) self.assertAlmostEqual(result.value_in( generic_unit_system.length**2/generic_unit_system.time**2), -M/(r+a), places=14) result=instance.get_gravity_at_point( 0.|generic_unit_system.length, x |generic_unit_system.length, y |generic_unit_system.length, z |generic_unit_system.length) self.assertAlmostEqual(result[0].value_in( generic_unit_system.length/generic_unit_system.time**2), -M/(r+a)**2 * x/r, places=14) self.assertAlmostEqual(result[0],result[2]/3, places=14) scaleM=2.345678|units.MSun scalea=7.654321|units.parsec converter=nbody_system.nbody_to_si(scaleM, scalea) instance = Agama(converter, type="Dehnen", mass=M*scaleM, scaleradius=a*scalea) result=instance.get_gravity_at_point( 0.|generic_unit_system.length, x*scalea, y*scalea, z*scalea) scale=M/(r+a)**2 *scaleM/scalea**2*constants.G self.assertAlmostEqual(result[0], scale * x/r, places=10) instance.stop()
def test1(self): M=10. a=2. x=1. y=2. z=3. r=(x*x+y*y+z*z)**0.5 instance = Agama(type="Dehnen", mass=M|generic_unit_system.mass, scaleRadius=a|generic_unit_system.length) result=instance.get_potential_at_point( 0.|generic_unit_system.length, x |generic_unit_system.length, y |generic_unit_system.length, z |generic_unit_system.length) self.assertAlmostEqual(result.value_in(generic_unit_system.length**2/generic_unit_system.time**2), -M/(r+a), places=14) result=instance.get_gravity_at_point( 0.|generic_unit_system.length, x |generic_unit_system.length, y |generic_unit_system.length, z |generic_unit_system.length) self.assertAlmostEqual(result[0].value_in(generic_unit_system.length/generic_unit_system.time**2), -M/(r+a)**2 * x/r, places=14) self.assertAlmostEqual(result[0],result[2]/3, places=14) scaleM=2.345678|units.MSun scalea=7.654321|units.parsec converter=nbody_system.nbody_to_si(scaleM, scalea) instance = Agama(converter, type="Dehnen", mass=M*scaleM, scaleradius=a*scalea) result=instance.get_gravity_at_point( 0.|generic_unit_system.length, x*scalea, y*scalea, z*scalea) scale=M/(r+a)**2 *scaleM/scalea**2*constants.G self.assertAlmostEqual(result[0], scale * x/r, places=10) instance.stop()
cluster.particles.add_particles(particles) # set up bridge; cluster is evolved under influence of the galaxy sys = bridge(verbose=False) sys.add_system(cluster, (galaxy, ), False) # evolve and make plots times = units.Myr([0., 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4]) f = pyplot.figure(figsize=(16, 8)) for i, t in enumerate(times): sys.evolve_model(t, timestep=timestep) print("Evolved the system to time %f" % t) x = sys.particles.x.value_in(units.parsec) y = sys.particles.y.value_in(units.parsec) subplot = f.add_subplot(2, 4, i + 1) subplot.plot(x, y, 'r .') subplot.plot([0.], [0.], 'b +') subplot.set_xlim(-60, 60) subplot.set_ylim(-60, 60) subplot.set_title(t) if i == 7: subplot.set_xlabel('parsec') cluster.stop() galaxy.stop() pyplot.show() # pyplot.savefig('test.eps')
# set up bridge; cluster is evolved under influence of the galaxy sys = bridge(verbose=False) sys.add_system(cluster, (galaxy,), False) # evolve and make plots times = units.Myr([0.,0.2,0.4,0.6,0.8,1.0,1.2,1.4]) f = pyplot.figure(figsize=(8,16)) for i,t in enumerate(times): sys.evolve_model(t, timestep=timestep) print "Evolved the system to time",t x=sys.particles.x.value_in(units.parsec) y=sys.particles.y.value_in(units.parsec) subplot=f.add_subplot(4,2,i+1) subplot.plot(x,y,'r .') subplot.plot([0.],[0.],'b +') subplot.set_xlim(-60,60) subplot.set_ylim(-60,60) subplot.set_title(t) if i==7: subplot.set_xlabel('parsec') cluster.stop() galaxy.stop() pyplot.show() # pyplot.savefig('test.eps')
channel_from_stellar_to_gravity.copy() channel_from_gravity_to_framework.copy() print("Evolved the system to time %.1f Myr" % t.value_in(units.Myr) + ", total mass=%.1f Msun" % particles.mass.sum().value_in(units.MSun) + ", Ekin=%.4g Msun*(km/s)^2" % cluster.kinetic_energy.value_in(units.MSun * units.kms**2) + ", Etot=%.4g Msun*(km/s)^2" % (cluster.potential_energy + cluster.kinetic_energy).value_in(units.MSun * units.kms**2)) x = particles.x.value_in(units.parsec) y = particles.y.value_in(units.parsec) plt.figure(figsize=(6, 6)) plt.scatter(x, y, marker='.', s=5 * particles.mass.value_in(units.MSun)**0.5, edgecolors=None, c='k', alpha=0.2) plt.xlim(-5, 5) plt.ylim(-5, 5) plt.title("t=%.1f Myr" % t.value_in(units.Myr)) basename = 'example_amuse_raga' if useRaga else 'example_amuse_nbody' plt.savefig('%s_%i.png' % (basename, i)) plt.close() cluster.stop() stellarevol.stop()