Exemplo n.º 1
0
def posvel_from_orbital_elements(Mstar, semimajor_axis, eccentricity, kepler, rng = None):
    if rng is None:
        rng = random
        
    mean_anomaly = rng.uniform(0, 2*numpy.pi, 1)
    kepler.initialize_from_elements(
        Mstar, 
        semimajor_axis, 
        eccentricity, 
        mean_anomaly=mean_anomaly)
    position = quantities.as_vector_quantity(kepler.get_separation_vector())
    velocity = quantities.as_vector_quantity(kepler.get_velocity_vector())
    return position, velocity
Exemplo n.º 2
0
def new_distribution(x0, x1, surface_density_factor=1.0, mstar=1 | units.MSun):
    x = x0
    masses = []
    positions = []
    while x < x1:
        mass, orbital_separation = get_mass_and_orbital_separation(
            x, surface_density_factor=surface_density_factor, mstar=mstar)
        masses.append(mass)
        positions.append(x)
        x += orbital_separation

    return (quantities.as_vector_quantity(masses),
            quantities.as_vector_quantity(positions))
Exemplo n.º 3
0
def new_distribution(x0, x1, surface_density_factor = 1.0, mstar = 1 | units.MSun):
    x = x0
    masses = []
    positions = []
    while x < x1:
        mass, orbital_separation = get_mass_and_orbital_separation(x, surface_density_factor = surface_density_factor, mstar = mstar)
        masses.append(mass)
        positions.append(x)
        x += orbital_separation
    
    return (
        quantities.as_vector_quantity(masses),
        quantities.as_vector_quantity(positions)
    )
Exemplo n.º 4
0
def posvel_from_orbital_elements(Mstar,
                                 semimajor_axis,
                                 eccentricity,
                                 kepler,
                                 rng=None):
    if rng is None:
        rng = random

    mean_anomaly = rng.uniform(0, 2 * numpy.pi, 1)
    kepler.initialize_from_elements(Mstar,
                                    semimajor_axis,
                                    eccentricity,
                                    mean_anomaly=mean_anomaly)
    position = quantities.as_vector_quantity(kepler.get_separation_vector())
    velocity = quantities.as_vector_quantity(kepler.get_velocity_vector())
    return position, velocity
Exemplo n.º 5
0
    def xtest_acceleration(self):
        """ Test the wind acceleration """
        star = self.create_star()
        star.position = [1, 1, 1] | units.RSun
        star_wind = stellar_wind.new_stellar_wind(
                        3e-11|units.MSun,
                        mode="accelerate",
                        init_v_wind_ratio = 0.01,
                        r_min_ratio=1.5,
                        r_max_ratio=5
                        )
        star_wind.particles.add_particles(star)

        # unaffected points
        points = [[1,1,1], [1,1,0], [1,4,1], [12,1,1]]|units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)
        zeros = [0,0,0,0]|units.m/units.s**2
        self.assertEqual(ax, zeros)
        self.assertEqual(ay, zeros)
        self.assertEqual(az, zeros)

        # affected points
        points = [[5.1,1,1], [1,1,5.1], [1,7,1], [1,7,8], [-8,1,1]]|units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)
        a = quantities.as_vector_quantity([ax, ay, az]).transpose()
        self.assertAlmostEquals(a[0], [32.64354, 0, 0]|units.m/units.s**2, places=4)
        self.assertAlmostEquals(a[1], [0, 0, 32.64354]|units.m/units.s**2, places=4)
        self.assertAlmostEquals(a[2], [0, 15.24272, 0]|units.m/units.s**2, places=4)
        self.assertAlmostEquals(a[3], [0, 4.20134, 4.90156]|units.m/units.s**2, places=4)
        self.assertAlmostEquals(a[4], [-6.77454, 0, 0]|units.m/units.s**2, places=4)
Exemplo n.º 6
0
    def test_get_gravity_at_point(self):
        star = self.create_star()
        star.position = [1, 1, 1] | units.RSun
        star_wind = stellar_wind.new_stellar_wind(
            3e-11 | units.MSun,
            mode="accelerate",
            acceleration_function="rsquared",
            compensate_gravity=False,
            compensate_pressure=False,
            )
        star_wind.particles.add_particles(star)

        # unaffected points
        points = [[1, 1, -10], [1, 12, 0], [1, -10, 1],
                  [12, 0, 1]] | units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)
        zeros = [0, 0, 0, 0] | units.m/units.s**2
        self.assertEqual(ax, zeros)
        self.assertEqual(ay, zeros)
        self.assertEqual(az, zeros)

        # affected points
        points = [[5.1, 1, 1], [1, 1, 5.1], [1, 7, 1], [1, 7, 8],
                  [-8, 1, 1]] | units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)

        result = quantities.as_vector_quantity([ax, ay, az]).transpose()
        expected = [[2.64618600667e-05, 0.0, 0.0],
                    [0.0, 0.0, 2.64618600667e-05],
                    [0.0, 1.23562185478e-05, 0.0],
                    [0.0, 3.40573571553e-06, 3.97335833479e-06],
                    [-5.49165268791e-06, 0.0, 0.0]] | units.m / units.s**2
        self.assertAlmostEquals(result, expected)
Exemplo n.º 7
0
def update_dynamical_binaries_from_stellar(stellar, multiples_code, converter):
    kep = new_kepler(converter)
    #    kep.set_longitudinal_unit_vector(1.0,0.0, 0.0)
    #    kep.set_transverse_unit_vector(0.0, 1.0, 0)
    # THIS NEEDS TO BE CHECKED
    print "++++++++++++ THIS NEEDS TO BE CHECKED ++++++++++++++++++++"
    print "Number of binaries=", len(stellar.binaries)
    for bi in stellar.binaries:
        bs = bi.as_particle_in_set(multiples_code.binaries)
        total_mass = bi.child1.mass + bi.child2.mass
        kep.initialize_from_elements(total_mass, bi.semi_major_axis,
                                     bi.eccentricity)
        rel_position = as_vector_quantity(kep.get_separation_vector())
        rel_velocity = as_vector_quantity(kep.get_velocity_vector())
        mu = bi.child1.mass / total_mass
        bs.child1.position = mu * rel_position
        bs.child2.position = -(1 - mu) * rel_position
        bs.child1.velocity = mu * rel_velocity
        bs.child2.velocity = -(1 - mu) * rel_velocity
        print "semi_major_axis=", bi.semi_major_axis, total_mass, bi.child1.mass, bi.child2.mass, bi.eccentricity
    kep.stop()
Exemplo n.º 8
0
    def get_gravity_at_point(self, eps, x, y, z):
        total_acceleration = numpy.zeros(shape=(len(x), 3))|units.m/units.s**2

        positions = quantities.as_vector_quantity(numpy.transpose([x, y, z]))
        for star in self.particles:
            relative_position = positions - star.position
            distance = relative_position.lengths()
            acceleration = self.wind_accelation_formula(star, distance)
            direction = relative_position / as_three_vector(distance)
            # Correct for directionless vectors with length 0
            direction[numpy.isnan(direction)] = 0
            total_acceleration += direction * as_three_vector(acceleration)

        return total_acceleration.transpose()
Exemplo n.º 9
0
def cellsize(grid):
    """Returns the lenght of each direction in the grid.
    Works for regular and cartesian grids.
    """
    result = []
    Ndim = len(grid.shape)
    cell1 = grid[(0, ) * Ndim]
    for i in range(
            len(grid[grid.get_minimum_index()].position)
    ):  # shape of position not necessarily same as shape of the grid?
        if grid.shape[i] > 1:
            cell2 = grid[(0, ) * i + (1, ) + (0, ) * (Ndim - 1 - i)]
            result.append((cell2.position - cell1.position)[i])
    return as_vector_quantity(result)
Exemplo n.º 10
0
    def get_gravity_at_point(self, eps, x, y, z):
        total_acceleration = (numpy.zeros(shape=(len(x), 3))
                              | units.m / units.s**2)

        positions = quantities.as_vector_quantity(numpy.transpose([x, y, z]))
        for star in self.particles:
            relative_position = positions - star.position
            distance = relative_position.lengths()
            acceleration = self.acceleration(star, distance)
            direction = relative_position / self.as_three_vector(distance)
            # Correct for directionless vectors with length 0
            direction[numpy.isnan(direction)] = 0
            total_acceleration += direction * self.as_three_vector(
                acceleration)

        return total_acceleration.transpose()
Exemplo n.º 11
0
    def get_gravity_at_point(self, eps, x, y, z):
        total_acceleration = (
            numpy.zeros(shape=(len(x), 3)) | units.m/units.s**2)

        positions = quantities.as_vector_quantity([x, y, z]).transpose()
        for star in self.particles:
            relative_position = positions - star.position
            distance = relative_position.lengths()
            acceleration = self.acceleration(star, distance)

            direction = relative_position / self.as_three_vector(distance)
            direction = numpy.nan_to_num(direction)

            acc_vector = self.as_three_vector(acceleration)
            total_acceleration += direction * acc_vector

        return total_acceleration.transpose()
    def test_get_gravity_at_point(self):
        star = self.create_star()
        star.position = [1, 1, 1] | units.RSun
        star_wind = stellar_wind.new_stellar_wind(
            3e-11 | units.MSun,
            mode="accelerate",
            acceleration_function="rsquared",
            compensate_gravity=False,
            compensate_pressure=False,
            r_out_ratio=5,
        )
        star_wind.particles.add_particles(star)

        # unaffected points
        points = [[1, 1, -10], [1, 12, 0], [1, -10, 1], [12, 0, 1]
                  ] | units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)
        zeros = [0, 0, 0, 0] | units.m / units.s**2
        self.assertEqual(ax, zeros)
        self.assertEqual(ay, zeros)
        self.assertEqual(az, zeros)

        # affected points
        points = [[5.1, 1, 1], [1, 1, 5.1], [1, 7, 1], [1, 7, 8], [-8, 1, 1]
                  ] | units.RSun
        x, y, z = points.transpose()
        ax, ay, az = star_wind.get_gravity_at_point(1, x, y, z)

        result = quantities.as_vector_quantity([ax, ay, az]).transpose()
        expected = [[2.64618600667e-05, 0.0, 0.0], [
            0.0, 0.0, 2.64618600667e-05
        ], [0.0, 1.23562185478e-05, 0.0],
                    [0.0, 3.40573571553e-06, 3.97335833479e-06],
                    [-5.49165268791e-06, 0.0, 0.0]] | units.m / units.s**2
        self.assertAlmostEquals(result, expected)
Exemplo n.º 13
0
Arquivo: sink.py Projeto: Ingwar/amuse
 def __init__(self, radius, height, **kwargs):
     dimensions = quantities.as_vector_quantity([radius, radius, height])
     Spheroid.__init__(self, dimensions, **kwargs)
Exemplo n.º 14
0
 def __init__(self, radius, height, **kwargs):
     dimensions = quantities.as_vector_quantity([radius, radius, height])
     Spheroid.__init__(self, dimensions, **kwargs)