src/amuse/ext/orbital_elements.py
def generate_binaries(
        primary_mass,
        secondary_mass,
        semi_major_axis,
        eccentricity=0 | units.rad,
        true_anomaly=0 | units.rad,
        inclination=0 | units.rad,
        longitude_of_the_ascending_node=0 | units.rad,
        argument_of_periapsis=0 | units.rad,
        G=None
        ):
    """
    returns two particlesets, which contain the primaries and the secondaries
    in binary pairs.
    """
    if G is None:
        G=derive_G(primary_mass)
    mass_unit = primary_mass.unit
    try:
        number_of_primaries = len(primary_mass)
    except:
        number_of_primaries = 1
        primary_mass = numpy.array(
                [primary_mass.value_in(mass_unit)]
                ) | mass_unit
    try:
        number_of_secondaries = len(secondary_mass)
    except:
        number_of_secondaries = 1
        secondary_mass = numpy.array(
                [secondary_mass.value_in(mass_unit)]
                ) | mass_unit

    if number_of_primaries==1 and number_of_secondaries:
        number_of_primaries = number_of_secondaries
        primary_mass = primary_mass[0] * numpy.ones(number_of_secondaries)

    # mass arrays need to be the same length
    if number_of_secondaries != number_of_primaries:
        raise Exception("The number of primaries is not the same as the number\
                of secondaries, this is not supported.")

    position_vector, velocity_vector = rel_posvel_arrays_from_orbital_elements(
        primary_mass,
        secondary_mass,
        semi_major_axis,
        eccentricity=eccentricity,
        true_anomaly=true_anomaly,
        inclination=inclination,
        longitude_of_the_ascending_node=longitude_of_the_ascending_node,
        argument_of_periapsis=argument_of_periapsis,
        G=G
        )
    number_of_primaries

    primaries = Particles(number_of_primaries)
    secondaries = Particles(number_of_secondaries)
    primaries.mass = primary_mass
    secondaries.mass = secondary_mass

    centers_of_mass = center_of_mass_array(
            position_vector, primary_mass, secondary_mass)
    centers_of_mass_velocity = center_of_mass_array(
            velocity_vector, primary_mass, secondary_mass)

    primaries.position = - centers_of_mass
    secondaries.position = position_vector - centers_of_mass
    primaries.velocity = - centers_of_mass_velocity
    secondaries.velocity = velocity_vector - centers_of_mass_velocity
    return primaries, secondaries

    returns two particlesets, which contain the primaries and the secondaries
    in binary pairs.
    
returns two particlesets, which contain the primaries and the secondaries
in binary pairs.
returns two particlesets which contain the primaries and the secondaries in binary pairs .
def generate_binaries(
        primary_mass,
        secondary_mass,
        semi_major_axis,
        eccentricity=0 | units.rad,
        true_anomaly=0 | units.rad,
        inclination=0 | units.rad,
        longitude_of_the_ascending_node=0 | units.rad,
        argument_of_periapsis=0 | units.rad,
        G=None
        ):
    if G is None:
        G=derive_G(primary_mass)
    mass_unit = primary_mass.unit
    try:
        number_of_primaries = len(primary_mass)
    except:
        number_of_primaries = 1
        primary_mass = numpy.array(
                [primary_mass.value_in(mass_unit)]
                ) | mass_unit
    try:
        number_of_secondaries = len(secondary_mass)
    except:
        number_of_secondaries = 1
        secondary_mass = numpy.array(
                [secondary_mass.value_in(mass_unit)]
                ) | mass_unit
    if number_of_primaries==1 and number_of_secondaries:
        number_of_primaries = number_of_secondaries
        primary_mass = primary_mass[0] * numpy.ones(number_of_secondaries)
    if number_of_secondaries != number_of_primaries:
        raise Exception("The number of primaries is not the same as the number\
                of secondaries, this is not supported.")
    position_vector, velocity_vector = rel_posvel_arrays_from_orbital_elements(
        primary_mass,
        secondary_mass,
        semi_major_axis,
        eccentricity=eccentricity,
        true_anomaly=true_anomaly,
        inclination=inclination,
        longitude_of_the_ascending_node=longitude_of_the_ascending_node,
        argument_of_periapsis=argument_of_periapsis,
        G=G
        )
    number_of_primaries
    primaries = Particles(number_of_primaries)
    secondaries = Particles(number_of_secondaries)
    primaries.mass = primary_mass
    secondaries.mass = secondary_mass
    centers_of_mass = center_of_mass_array(
            position_vector, primary_mass, secondary_mass)
    centers_of_mass_velocity = center_of_mass_array(
            velocity_vector, primary_mass, secondary_mass)
    primaries.position = - centers_of_mass
    secondaries.position = position_vector - centers_of_mass
    primaries.velocity = - centers_of_mass_velocity
    secondaries.velocity = velocity_vector - centers_of_mass_velocity
    return primaries, secondaries
def generate_binaries ( primary_mass , secondary_mass , semi_major_axis , eccentricity = 0 | units . rad , true_anomaly = 0 | units . rad , inclination = 0 | units . rad , longitude_of_the_ascending_node = 0 | units . rad , argument_of_periapsis = 0 | units . rad , G = None ) : if G is None : G = derive_G ( primary_mass ) mass_unit = primary_mass . unit try : number_of_primaries = len ( primary_mass ) except : number_of_primaries = 1 primary_mass = numpy . array ( [ primary_mass . value_in ( mass_unit ) ] ) | mass_unit try : number_of_secondaries = len ( secondary_mass ) except : number_of_secondaries = 1 secondary_mass = numpy . array ( [ secondary_mass . value_in ( mass_unit ) ] ) | mass_unit if number_of_primaries == 1 and number_of_secondaries : number_of_primaries = number_of_secondaries primary_mass = primary_mass [ 0 ] * numpy . ones ( number_of_secondaries ) if number_of_secondaries != number_of_primaries : raise Exception ( "The number of primaries is not the same as the number\
                of secondaries, this is not supported." ) position_vector , velocity_vector = rel_posvel_arrays_from_orbital_elements ( primary_mass , secondary_mass , semi_major_axis , eccentricity = eccentricity , true_anomaly = true_anomaly , inclination = inclination , longitude_of_the_ascending_node = longitude_of_the_ascending_node , argument_of_periapsis = argument_of_periapsis , G = G ) number_of_primaries primaries = Particles ( number_of_primaries ) secondaries = Particles ( number_of_secondaries ) primaries . mass = primary_mass secondaries . mass = secondary_mass centers_of_mass = center_of_mass_array ( position_vector , primary_mass , secondary_mass ) centers_of_mass_velocity = center_of_mass_array ( velocity_vector , primary_mass , secondary_mass ) primaries . position = - centers_of_mass secondaries . position = position_vector - centers_of_mass primaries . velocity = - centers_of_mass_velocity secondaries . velocity = velocity_vector - centers_of_mass_velocity return primaries , secondaries
returns two particlesets, which contain the primaries and the secondaries
in binary pairs.
returns two particlesets which contain the primaries and the secondaries in binary pairs .
"""
    returns two particlesets, which contain the primaries and the secondaries
    in binary pairs.
    """ # mass arrays need to be the same length
primary_mass
secondary_mass
semi_major_axis
eccentricity
true_anomaly
inclination
longitude_of_the_ascending_node
argument_of_periapsis
G