def test_radius_from_time(self): self.skip_no_scipy() func = stellar_wind.RSquaredAcceleration() star = Particle() star.radius = 312. | units.RSun star.acc_cutoff = 312*5. | units.RSun star.initial_wind_velocity = 2 | units.kms star.terminal_wind_velocity = 20 | units.kms times = [0., 25., 100.] | units.yr print "times", times radii = func.radius_from_time(times, star) print "radii", radii self.assertAlmostEquals(radii[0], 312. | units.RSun) self.assertAlmostEquals(radii[1], 22644.6086263 | units.RSun) self.assertAlmostEquals(radii[2], 90704.1183516 | units.RSun) return times = numpy.linspace(0., 1, 100) | units.yr radii = func.radius_from_time(times, star) print radii from matplotlib import pyplot from amuse import plot as aplot aplot.plot(times, radii/star.radius) pyplot.show()
def create_star(self): star = Particle() star.radius = 2 | units.RSun star.acc_cutoff = 10 | units.RSun star.initial_wind_velocity = 4 | units.kms star.terminal_wind_velocity = 12 | units.kms return star
def test_radius_from_time(self): self.skip_no_scipy() func = stellar_wind.RSquaredAcceleration() star = Particle() star.radius = 312. | units.RSun star.acc_cutoff = 312 * 5. | units.RSun star.initial_wind_velocity = 2 | units.kms star.terminal_wind_velocity = 20 | units.kms times = [0., 25., 100.] | units.yr print "times", times radii = func.radius_from_time(times, star) print "radii", radii self.assertAlmostEquals(radii[0], 312. | units.RSun) self.assertAlmostEquals(radii[1], 22644.6086263 | units.RSun) self.assertAlmostEquals(radii[2], 90704.1183516 | units.RSun) return times = numpy.linspace(0., 1, 100) | units.yr radii = func.radius_from_time(times, star) print radii from matplotlib import pyplot from amuse import plot as aplot aplot.plot(times, radii / star.radius) pyplot.show()
def test_alternate_radius_function(self): numpy.random.seed(123) gen = stellar_wind.PositionGenerator() # func = stellar_wind.LogisticVelocityAcceleration().radius_from_number func = stellar_wind.ConstantVelocityAcceleration().radius_from_number N = 100000 rmin = 2 | units.RSun rmax = 6 | units.RSun star = Particle() star.radius = rmin star.acc_cutoff = 10 | units.RSun star.initial_wind_velocity = 4 | units.kms star.terminal_wind_velocity = 12 | units.kms p, _ = gen.generate_positions(N, rmin, rmax, func, star) r = p.lengths() self.assertEquals(len(r), N) self.assertGreaterEqual(r.min(), rmin) self.assertLessEqual(r.max(), rmax) print r.mean() self.assertAlmostEquals(r.mean(), 4.00196447056 | units.RSun) return r = r.value_in(units.RSun) n_bins = 50 n, bins = numpy.histogram(r, n_bins) bin_volume = 4./3. * numpy.pi * (bins[1:]**3 - bins[:-1]**3) dens = n / bin_volume bin_means = (bins[1:] + bins[:-1])/2. from matplotlib import pyplot pyplot.plot(bin_means, dens, '*') pyplot.savefig("dens.pdf")
def test_alternate_radius_function(self): numpy.random.seed(123) gen = stellar_wind.PositionGenerator() # func = stellar_wind.LogisticVelocityAcceleration().radius_from_number func = stellar_wind.ConstantVelocityAcceleration().radius_from_number N = 100000 rmin = 2 | units.RSun rmax = 6 | units.RSun star = Particle() star.radius = rmin star.acc_cutoff = 10 | units.RSun star.initial_wind_velocity = 4 | units.kms star.terminal_wind_velocity = 12 | units.kms p, _ = gen.generate_positions(N, rmin, rmax, func, star) r = p.lengths() self.assertEquals(len(r), N) self.assertGreaterEqual(r.min(), rmin) self.assertLessEqual(r.max(), rmax) print r.mean() self.assertAlmostEquals(r.mean(), 4.00196447056 | units.RSun) return r = r.value_in(units.RSun) n_bins = 50 n, bins = numpy.histogram(r, n_bins) bin_volume = 4. / 3. * numpy.pi * (bins[1:]**3 - bins[:-1]**3) dens = n / bin_volume bin_means = (bins[1:] + bins[:-1]) / 2. from matplotlib import pyplot pyplot.plot(bin_means, dens, '*') pyplot.savefig("dens.pdf")