Ejemplo n.º 1
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()
    timerange = units.day(numpy.arange(0, 120 * 365.25, 12))

    instance = MercuryWayWard()
    instance.initialize_code()
    instance.central_particle.add_particles(sun)
    instance.orbiters.add_particles(planets)
    instance.commit_particles()

    channels = instance.orbiters.new_channel_to(planets)

    for time in timerange:
        err = instance.evolve_model(time)
        channels.copy()
        planets.savepoint(time)

    instance.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')

    native_plot.show()
Ejemplo n.º 2
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()
    timerange = units.day(numpy.arange(0, 120 * 365.25, 12))

    instance = MercuryWayWard()
    instance.initialize_code()
    instance.central_particle.add_particles(sun)
    instance.orbiters.add_particles(planets)
    instance.commit_particles()

    channels = instance.orbiters.new_channel_to(planets)

    for time in timerange:
        err = instance.evolve_model(time)
        channels.copy()
        planets.savepoint(time)

    instance.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')

    native_plot.show()
Ejemplo n.º 3
0
def monitor_density_profile(system, i_step, time, n_steps, memory=Memory()):
    if i_step == 0:
        memory.xlimits = (None, None)
        memory.ylimits = (None, None)
    position = system.gas_particles.position - system.gas_particles.center_of_mass()
    loglog(position.lengths_squared(), system.gas_particles.density, 'gs')
    native_plot.title("{0}: t={1}".format(i_step, time.as_quantity_in(units.yr)))
    native_plot.xlim(memory.xlimits)
    native_plot.ylim(memory.ylimits)
    native_plot.pause(0.0001)
    memory.xlimits = native_plot.gca().get_xlim()
    memory.ylimits = native_plot.gca().get_ylim()
    if i_step == n_steps-1:
        native_plot.show(block=True)
    native_plot.cla()
Ejemplo n.º 4
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time-initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU)
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Ejemplo n.º 5
0
def polyevolve():
    sun, planets = Solarsystem.new_solarsystem()

    gd, se = setup_codes(sun, planets)

    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    prev_mass = sun[0].mass

    massrange = units.MSun(numpy.arange(0.9, 0.89999, -1e-9))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for i, mass in enumerate(massrange):
        time, dummymass = se.evolve_mass(mass)
        if i == 0:
            initialtime = time
        print(time, mass, "evolving gd")
        gdtime = time - initialtime
        print(gdtime)
        err = gd.evolve_model(gdtime)
        channelp.copy()
        planets.savepoint(time)
        channels.copy()
        gd.central_particle.mass = sun[0].mass
        print(sun[0].mass)
        print(
            sun[0].mass.value_in(units.MSun),
            time.value_in(units.Myr),
            planets[4].x.value_in(units.AU),
            planets[4].y.value_in(units.AU),
            planets[4].z.value_in(units.AU),
        )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        t, z = planet.get_timeline_of_attribute_as_vector("z")
        plot3(x, y, z, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Ejemplo n.º 6
0
def polyevolve():
    sun, planets = Solarsystem.new_solarsystem()

    gd, se = setup_codes(sun, planets)

    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    prev_mass = sun[0].mass

    massrange = units.MSun(numpy.arange(0.9, 0.89999, -1e-9))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for i, mass in enumerate(massrange):
        time, dummymass = se.evolve_mass(mass)
        if i == 0:
            initialtime = time
        print time, mass, "evolving gd"
        gdtime = time-initialtime
        print gdtime
        err = gd.evolve_model(gdtime)
        channelp.copy()
        planets.savepoint(time)
        channels.copy()
        gd.central_particle.mass = sun[0].mass
        print sun[0].mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU),
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        t, z = planet.get_timeline_of_attribute_as_vector("z")
        plot3(x, y, z, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Ejemplo n.º 7
0
def monitor_density_profile(system, i_step, time, n_steps, memory=Memory()):
    if i_step == 0:
        memory.xlimits = (None, None)
        memory.ylimits = (None, None)
    position = system.gas_particles.position - system.gas_particles.center_of_mass(
    )
    loglog(position.lengths_squared(), system.gas_particles.density, 'gs')
    native_plot.title("{0}: t={1}".format(i_step,
                                          time.as_quantity_in(units.yr)))
    native_plot.xlim(memory.xlimits)
    native_plot.ylim(memory.ylimits)
    native_plot.pause(0.0001)
    memory.xlimits = native_plot.gca().get_xlim()
    memory.ylimits = native_plot.gca().get_ylim()
    if i_step == n_steps - 1:
        native_plot.show(block=True)
    native_plot.cla()
Ejemplo n.º 8
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time - initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
            (sun[0].mass.value_in(units.MSun), time.value_in(units.Myr),
             planets[4].x.value_in(units.AU), planets[4].y.value_in(units.AU),
             planets[4].z.value_in(units.AU)))

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Ejemplo n.º 9
0
def testsse():
    sse = SSEWithMassEvolve()
    sse.commit_parameters()
    sun, planets = new_solar_system_for_mercury()
    sse.particles.add_particles(sun)
    sse.commit_particles()
    channel = sse.particles.new_channel_to(sun)
    channel.copy()

    massrange = units.MSun(numpy.arange(1, 0.8, -0.001))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for mass in massrange:
        sse.evolve_mass(mass)
        t, m = sse.evolve_mass(mass)
        timerange.append(t)
        channel.copy()
        masses.append(sse.particles[0].mass)

    sse.stop()
    plot(massrange, timerange, '.')
    native_plot.show()
Ejemplo n.º 10
0
def testsse():
    sse = SSEWithMassEvolve()
    sse.commit_parameters()
    sun, planets = new_solar_system_for_mercury()
    sse.particles.add_particles(sun)
    sse.commit_particles()
    channel = sse.particles.new_channel_to(sun)
    channel.copy()

    massrange = units.MSun(numpy.arange(1, 0.8, -0.001))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for mass in massrange:
        sse.evolve_mass(mass)
        t, m = sse.evolve_mass(mass)
        timerange.append(t)
        channel.copy()
        masses.append(sse.particles[0].mass)

    sse.stop()
    plot(massrange, timerange, '.')
    native_plot.show()
Ejemplo n.º 11
0
    y1 = quantities.new_quantity(
        np.sin(np.arange(0, 1.5, 0.03)), 1e50*units.erg)
    y2 = -(1e43 | units.J) - y1
    native_plot.subplot(2, 2, 2)
    plot(x, y1, label='$E_\mathrm{kin}$')
    plot(x, y2, label='$E_\mathrm{pot}$')
    xlabel('t')
    ylabel('E')
    native_plot.legend()

    x = range(7) | units.day
    y1 = [0, 4, 2, 3, 2, 5, 1]
    y2 = [3, 0, 2, 2, 3, 0, 4]
    native_plot.subplot(2, 2, 3)
    plot(x, y1, 'ks', label='coffee')
    plot(x, y2, 'yo', label='tea')
    xlabel('time')
    ylabel('consumption / day')
    native_plot.legend()

    y1 = units.N.new_quantity(np.random.normal(0.0, 1.0, 100))
    x = units.N.new_quantity(np.arange(-3, 3, 0.1))
    y2 = np.exp(-np.arange(-3, 3, 0.1)**2)/np.sqrt(np.pi)
    native_plot.subplot(2, 2, 4)
    plot(x, y2, 'y--', label='model')
    hist(y1, bins=12, range=(-3, 3), normed=True, label='data')
    xlabel('force')
    ylabel('pdf')
    native_plot.legend()
    native_plot.show()
Ejemplo n.º 12
0
    def test4(self):
        random.seed(1001)
        print "Test 4: complicated density field."

        # A separate group below peak_density_threshold -> should be dropped
        particles0 = new_plummer_model(90,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           0.9 | units.MSun, 1.0 | units.RSun))

        # A nearby group below peak_density_threshold -> should be attached to proper group
        particles1 = new_plummer_model(80,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           0.8 | units.MSun, 1.0 | units.RSun))
        particles1.x += 10 | units.RSun

        # A proper group very nearby other proper group -> groups should merge
        particles2a = new_plummer_model(200,
                                        convert_nbody=nbody_system.nbody_to_si(
                                            2.0 | units.MSun,
                                            1.0 | units.RSun))
        particles2b = new_plummer_model(300,
                                        convert_nbody=nbody_system.nbody_to_si(
                                            3.0 | units.MSun,
                                            1.0 | units.RSun))
        particles2a.x += 11.0 | units.RSun
        particles2b.x += 11.2 | units.RSun

        # A separate proper group other proper group -> groups should be preserved
        particles3 = new_plummer_model(400,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           4.0 | units.MSun, 1.0 | units.RSun))
        particles3.x += 20 | units.RSun

        hop = Hop(
            unit_converter=nbody_system.nbody_to_si(10.7 | units.MSun, 1.0
                                                    | units.RSun))
        hop.parameters.number_of_neighbors_for_local_density = 100
        hop.parameters.saddle_density_threshold_factor = 0.5
        hop.parameters.relative_saddle_density_threshold = True
        hop.commit_parameters()

        for set in [
                particles0, particles1, particles2a, particles2b, particles3
        ]:
            hop.particles.add_particles(set)

        hop.calculate_densities()
        hop.parameters.outer_density_threshold = 0.1 * hop.particles.density.mean(
        )
        hop.parameters.peak_density_threshold = hop.particles.density.amax(
        ) / 4.0
        hop.recommit_parameters()
        hop.do_hop()
        groups = list(hop.groups())

        self.assertEquals(len(hop.particles), 1070)
        self.assertEquals(len(groups), 2)
        self.assertEquals(
            hop.particles.select(lambda x: x < 5 | units.RSun, "x").group_id,
            -1)
        self.assertEquals(hop.get_number_of_particles_outside_groups(), 299)
        self.assertEquals(1070 - len(groups[0]) - len(groups[1]), 299)

        expected_size = [
            477, 294
        ]  # Less than [580, 400], because particles below outer_density_threshold are excluded
        expected_average_x = [11.0, 20] | units.RSun
        for index, group in enumerate(groups):
            self.assertEquals(group.id_of_group(), index)
            self.assertAlmostEquals(group.center_of_mass()[0],
                                    expected_average_x[index], 1)
            self.assertEquals(len(group), expected_size[index])

        if False:  # Make a plot
            original = hop.particles.copy()
            from amuse.plot import scatter, native_plot
            colors = ["r", "g", "b", "y", "k", "w"] * 100
            for group, color in zip(hop.groups(), colors):
                scatter(group.x, group.y, c=color)
                original -= group
            scatter(original.x, original.y, c="m", marker="s")
            native_plot.show()

        hop.stop()
Ejemplo n.º 13
0
    instance.particles.add_particles(particles)

    channelp = instance.particles.new_channel_to(particles)

    start = 0 | units.yr
    end = 150 | units.yr
    step = 10 | units.day

    timerange = VectorQuantity.arange(start, end, step)

    masses = [] | units.MSun

    for i, time in enumerate(timerange):
        instance.evolve_model(time)
        channelp.copy()
        particles.savepoint(time)
        if (i % 220 == 0):
            instance.particles[0].mass = simulate_massloss(time)
        masses.append(instance.particles[0].mass)

    instance.stop()

    particle = particles[1]

    t, pos = particle.get_timeline_of_attribute_as_vector("position")
    distances = pos.lengths().as_quantity_in(units.AU)

    plot(timerange, distances, timerange, masses)

    native_plot.show()
Ejemplo n.º 14
0
 def test4(self):
     random.seed(1001)
     print "Test 4: complicated density field."
     
     # A separate group below peak_density_threshold -> should be dropped
     particles0 = new_plummer_model(90, convert_nbody=nbody_system.nbody_to_si(0.9 | units.MSun, 1.0 | units.RSun))
     
     # A nearby group below peak_density_threshold -> should be attached to proper group
     particles1 = new_plummer_model(80, convert_nbody=nbody_system.nbody_to_si(0.8 | units.MSun, 1.0 | units.RSun))
     particles1.x += 10 | units.RSun
     
     # A proper group very nearby other proper group -> groups should merge
     particles2a = new_plummer_model(200, convert_nbody=nbody_system.nbody_to_si(2.0 | units.MSun, 1.0 | units.RSun))
     particles2b = new_plummer_model(300, convert_nbody=nbody_system.nbody_to_si(3.0 | units.MSun, 1.0 | units.RSun))
     particles2a.x += 11.0 | units.RSun
     particles2b.x += 11.2 | units.RSun
     
     # A separate proper group other proper group -> groups should be preserved
     particles3 = new_plummer_model(400, convert_nbody=nbody_system.nbody_to_si(4.0 | units.MSun, 1.0 | units.RSun))
     particles3.x += 20 | units.RSun
     
     hop = Hop(unit_converter=nbody_system.nbody_to_si(10.7 | units.MSun, 1.0 | units.RSun))
     hop.parameters.number_of_neighbors_for_local_density = 100
     hop.parameters.saddle_density_threshold_factor = 0.5
     hop.parameters.relative_saddle_density_threshold = True
     hop.commit_parameters()
     
     for set in [particles0, particles1, particles2a, particles2b, particles3]:
         hop.particles.add_particles(set)
     
     hop.calculate_densities()
     hop.parameters.outer_density_threshold = 0.1 * hop.particles.density.mean()
     hop.parameters.peak_density_threshold = hop.particles.density.amax() / 4.0
     hop.recommit_parameters()
     hop.do_hop()
     groups = list(hop.groups())
     
     self.assertEquals(len(hop.particles), 1070)
     self.assertEquals(len(groups), 2)
     self.assertEquals(hop.particles.select(lambda x: x < 5|units.RSun, "x").group_id, -1)
     self.assertEquals(hop.get_number_of_particles_outside_groups(), 299)
     self.assertEquals(1070 - len(groups[0]) - len(groups[1]), 299)
     
     expected_size = [477, 294] # Less than [580, 400], because particles below outer_density_threshold are excluded
     expected_average_x = [11.0, 20] | units.RSun
     for index, group in enumerate(groups):
         self.assertEquals(group.id_of_group(), index)
         self.assertAlmostEquals(group.center_of_mass()[0], expected_average_x[index], 1)
         self.assertEquals(len(group), expected_size[index])
     
     if False: # Make a plot
         original = hop.particles.copy()
         from amuse.plot import scatter, native_plot
         colors = ["r", "g", "b", "y", "k", "w"]*100
         for group, color in zip(hop.groups(), colors):
             scatter(group.x, group.y, c=color)
             original -= group
         scatter(original.x, original.y, c="m", marker="s")
         native_plot.show()
     
     hop.stop()