示例#1
0
    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()
示例#2
0
 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
示例#3
0
    def test_radius_from_number(self):
        self.skip_no_scipy()

        star = Particle(
            initial_wind_velocity=200. | units.kms, mass=20. | units.MSun,
            radius=10. | units.RSun, terminal_wind_velocity=1000. | units.kms)
        star.acc_cutoff = 5. * star.radius
        r_max = 24.2642526438 | units.RSun
        x = 0.1

        func = stellar_wind.RSquaredAcceleration()
        radius = func.radius_from_number(x, r_max, star)
        self.assertAlmostEquals(radius,  10.6029030808 | units.RSun)
    def test_radius_from_number(self):
        self.skip_no_scipy()

        star = Particle(initial_wind_velocity=200. | units.kms,
                        mass=20. | units.MSun,
                        radius=10. | units.RSun,
                        terminal_wind_velocity=1000. | units.kms)
        star.acc_cutoff = 5. * star.radius
        r_max = 24.2642526438 | units.RSun
        x = 0.1

        func = stellar_wind.RSquaredAcceleration()
        radius = func.radius_from_number(x, r_max, star)
        self.assertAlmostEquals(radius, 10.6029030808 | units.RSun)
    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
示例#7
0
    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")
示例#8
0
def nbodies(centralmass, *orbiting):
    """
    Parameters
    ----------
    centralmass: mass of the central body
    orbiting: dictionary with args/kwargs to create binary from elements

    """
    bodies = Particles()

    centralbody = Particle(mass=centralmass)
    bodies.add_particle(centralbody)

    for body in orbiting:
        mass = body['mass']
        elements = body['elements']
        twobody = new_binary_from_elements(centralmass, mass, **elements)
        bodies.add_particle(twobody[1])

    return bodies
    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")
示例#10
0
class TestSinkAccretion(TestWithMPI):
    converter = nbody_system.nbody_to_si(2 | units.pc, 10000 | units.MSun)
    gas = new_plummer_gas_model(100000, converter)
    gas.h_smooth = 0.1 | units.pc
    gas.u = temperature_to_u(10 | units.K)
    origin_gas = Particle()
    origin_gas.x = 0 | units.pc
    origin_gas.y = 0 | units.pc
    origin_gas.z = 0 | units.pc
    origin_gas.vx = 0 | units.kms
    origin_gas.vy = 0 | units.kms
    origin_gas.vz = 0 | units.kms
    origin_gas.mass = gas[0].mass
    origin_gas.h_smooth = 0.03 | units.pc
    origin_gas.u = 100 | units.kms**2

    def test_forming(self):
        """
        Tests if this cloud indeed forms a sink from origin particle
        """
        result, message = should_a_sink_form(
            self.origin_gas,
            self.gas,
            check_thermal=True,
            accretion_radius=0.1 | units.pc,
        )
        self.assertEqual([True], result)

    def test_divergence(self):
        self.skip("Not yet implemented")

    def test_smoothing_length_too_large(self):
        """
        Tests if this cloud fails to form a sink from origin particle because
        its smoothing length is too large
        """
        h_smooth = 0.05 | units.pc
        origin_gas = self.origin_gas.copy()
        origin_gas.h_smooth = h_smooth
        result, message = should_a_sink_form(
            origin_gas,
            self.gas,
            check_thermal=True,
            accretion_radius=1.99 * h_smooth,
        )
        self.assertEqual([False], result)
        self.assertEqual(["smoothing length too large"], message)

    def test_too_hot(self):
        """
        Tests if this cloud fails to form a sink from origin particle because
        its thermal energy is too high
        """
        gas = self.gas.copy()
        gas.u = temperature_to_u(20 | units.K)
        result, message = should_a_sink_form(
            self.origin_gas,
            gas,
            check_thermal=True,
            accretion_radius=0.1 | units.pc,
        )
        self.assertEqual([False], result)
        self.assertEqual(["e_th/e_pot > 0.5"], message)

    def test_expanding(self):
        """
        Tests if this cloud fails to form a sink from origin particle because
        its kinetic energy is too high
        """
        gas = self.gas.copy()
        gas.vx = gas.x / (10 | units.kyr)
        gas.vy = gas.y / (10 | units.kyr)
        gas.vz = gas.z / (10 | units.kyr)
        result, message = should_a_sink_form(
            self.origin_gas,
            gas,
            check_thermal=True,
            accretion_radius=0.1 | units.pc,
        )
        self.assertEqual([False], result)
        self.assertEqual(["e_tot < 0"], message)

    def test_rotating(self):
        """
        Tests if this cloud fails to form a sink from origin particle because
        it is rotating
        """
        gas = self.gas.copy()
        gas.vx = gas.y / (10 | units.kyr)
        gas.vy = -gas.x / (10 | units.kyr)
        result, message = should_a_sink_form(
            self.origin_gas,
            gas,
            check_thermal=True,
            accretion_radius=0.1 | units.pc,
        )
        self.assertEqual(["e_rot too big"], message)
        self.assertEqual([False], result)