alpha = 0.0001 #adaptive time step parameter
N = 500

bodies, distribution = nb.icc.plummer(N, d)

def mass_colors(snapshots, time_step):
    curr_masses = snapshots[time_step, :, 6]
    norm_mass = (curr_masses - curr_masses.min()) / (curr_masses.max() - curr_masses.min())

    cmap = cm.get_cmap("RdBu")
    return [cmap(abs(1.0 - norm_mass[i])) for i in range(norm_mass.shape[0])] 

snapshot_storage = SnapshotStorage()
snapshot_storage.append(bodies)

snapshot_renderer = SnapshotRenderer.for_clusters(snapshot_storage, recoloring_func=mass_colors, bounds=[-2e14, 2e14], verbose=1, angle=[45, 45])
#snapshot_renderer.display_step()

for i, current_t in enumerate(nb.leapfrog_adaptive.simulate_step(bodies, G=nb.constants.G, epsilon=epsilon, dt_output=dt_output, alpha=alpha, max_dt_bins=5)):
    if current_t >= total_time:
        break

    print "{}/{}".format(current_t/nb.constants.YR, total_time/nb.constants.YR)

    snapshot_storage.append(bodies)
    #snapshot_renderer.display_step()

#nb.constants.G, nb.constants.SOLAR_MASS, nb.constants.YR = nb.constants.codetounits() #Back to SI units
name = "{:s}_N{:d}_T{:d}_E{:.0e}_d{:.0e}_color00".format(distribution, N, int(total_time/nb.constants.YR), epsilon, d)
snapshot_renderer.run(name + ".mp4")
snapshot_storage.save("nbody/" + name + ".pkl")
示例#2
0
dt_min = 0.000001 * nb.constants.YR
epsilon = 0.2
alpha = 0.001  #adaptive time step parameter
dt_output = 1.0 * nb.constants.YR

bodies_phys = bodies.clone()
conversion_params = nb.constants.convert_to_sim_units(bodies)

space_coeff = nb.constants.space_coeff(*conversion_params)
time_coeff = nb.constants.time_coeff(*conversion_params)

snapshot_storage = SnapshotStorage()
snapshot_storage.append(bodies_phys)

snapshot_renderer = SnapshotRenderer.for_orbits(snapshot_storage,
                                                bounds=(-nb.constants.AU,
                                                        nb.constants.AU))
snapshot_renderer.display_step()

for i, current_t in enumerate(
        nb.leapfrog_adaptive.simulate_step(bodies,
                                           epsilon=epsilon / space_coeff,
                                           dt_output=dt_output / space_coeff,
                                           alpha=alpha,
                                           max_dt_bins=5)):
    if current_t >= total_time / time_coeff:
        break

    print "{}/{}".format(current_t * time_coeff / nb.constants.YR,
                         total_time / nb.constants.YR)
示例#3
0
        [1 * nb.constants.AU, 0.0, 0.0]])

bodies.m = np.array([nb.constants.SOLAR_MASS, 3.3e23, 4.86e24, 5.97e24])
bodies.v = np.array([
        [0.0, 0.0, 0.0],
        [0.0, 47362, 0.0],
        [0.0, -35020, 0.0],
        [0.0, 29780, 0.0]])

total_time = 10 * nb.constants.YR
dt_min = 0.000001 * nb.constants.YR
epsilon = 0.2
alpha = 0.001 #adaptive time step parameter
dt_output = 0.01 * nb.constants.YR

snapshot_storage = SnapshotStorage()
snapshot_storage.append(bodies.r)

snapshot_renderer = SnapshotRenderer.for_orbits(snapshot_storage, 
                                                bounds=(-nb.constants.AU, nb.constants.AU))
snapshot_renderer.display_step()

for i, current_t in enumerate(leapfrog_adaptive.simulate_step(bodies, dt_min, G=nb.constants.G, epsilon=epsilon, dt_output=dt_output, alpha=alpha)):
    if current_t >= total_time:
        break

    print "{}/{}".format(current_t, total_time)
    
    snapshot_storage.append(bodies.r)
    snapshot_renderer.display_step()
def mass_colors(snapshots, time_step):
    curr_masses = snapshots[time_step, :, 6]
    norm_mass = (curr_masses - curr_masses.min()) / (curr_masses.max() -
                                                     curr_masses.min())

    cmap = cm.get_cmap("RdBu")
    return [cmap(abs(1.0 - norm_mass[i])) for i in range(norm_mass.shape[0])]


snapshot_storage = SnapshotStorage()
snapshot_storage.append(bodies_phys)

space_coeff = nb.constants.space_coeff(*conversion_params)
snapshot_renderer = SnapshotRenderer.for_clusters(snapshot_storage,
                                                  recoloring_func=mass_colors,
                                                  bounds=[-2e14, 2e14],
                                                  verbose=1,
                                                  angle=[45, 45])
#snapshot_renderer.display_step()

time_coeff = nb.constants.time_coeff(*conversion_params)
for i, current_t in enumerate(
        nb.leapfrog_adaptive.simulate_step(bodies,
                                           epsilon=epsilon / space_coeff,
                                           alpha=alpha,
                                           dt_output=dt_output / time_coeff,
                                           max_dt_bins=5)):
    if current_t >= total_time / time_coeff:
        break

    print "{}/{}".format(current_t * time_coeff / nb.constants.YR,