示例#1
0
def evolve_cluster_in_galaxy(options_file):
    opt = options_reader(options_file)

    timestep = opt.options['timestep']  # in Myr
    tend = opt.options['tend']  # in Myr
    times = np.arange(0.0, tend, timestep) | units.Myr

    cluster = oc_code(opt)
    cluster_code = cluster.code
    galaxy_code = gizmo_interface(opt)

    snap_reader = snapshot_reader(opt, galaxy_code)

    stars = cluster_code.particles.copy()

    if opt.options['axisymmetric']:
        import astropy.units as u
        import gala.dynamics as gd
        import gala.potential as gp

        pos = [opt.options['axi_Rinit'], 0, 0] * u.kpc
        vel = [0, 0, 0] * u.km / u.s
        mw = gp.MilkyWayPotential()
        phase = gd.PhaseSpacePosition(pos, vel)
        vc = mw.circular_velocity(phase).to_value(u.km / u.s) | units.kms

        stars = cluster_code.particles.copy()
        stars.x += opt.options['axi_Rinit'] | units.kpc
        stars.vy += vc
        stars.z += opt.options['axi_zinit'] | units.kpc

    else:
        pos = galaxy_code.chosen_position_z0
        vel = galaxy_code.chosen_velocity_z0
        stars.x += pos[0] | units.kpc
        stars.y += pos[1] | units.kpc
        stars.z += pos[2] | units.kpc
        stars.vx += vel[0] | units.kms
        stars.vy += vel[1] | units.kms
        stars.vz += vel[2] | units.kms

    channel = stars.new_channel_to(cluster_code.particles)
    channel.copy_attributes(["x", "y", "z", "vx", "vy", "vz"])

    system = Bridge(timestep=timestep, use_threading=False)
    system.add_system(cluster_code, (galaxy_code, ))
    system.add_system(galaxy_code)

    converter = cluster_code.unit_converter

    for i, t in enumerate(tqdm(times)):
        system.evolve_model(t, timestep=timestep | units.Myr)

        bound_com = bound.center_of_mass().value_in(units.kpc)

        snap_reader.process_snapshot(system, galaxy_code, bound_com, i, t)

    snap_reader.finish_sim()

    cluster_code.stop()
示例#2
0
 def __init__(self, options_file, interface):
     self.opt = options_reader(options_file)
     self.interface = interface
                                              == ss_id)[0]
                        print('pos: ', pos[chosen_one])
                        print('vel: ', vel[chosen_one])
                        print('chosen_one: ', chosen_one)
                        print('ss_id: ', ss_id)
                        return pos[chosen_one][0], vel[chosen_one][0], int(chosen_one), ss_id

            chosen_one = np.random.choice(keys)
            chosen_id = self.first_snapshot['star']['id'][chosen_one]
            # return pos[chosen_one], vel[chosen_one], chosen_one, chosen_id
            return pos[chosen_one], chosen_one, chosen_id

    def __getstate__(self):
        self_dict = self.__dict__.copy()
        del self_dict['acc_pool']
        return self_dict

    def __setstate__(self, state):
        self.__dict__.update(state)


if __name__ == '__main__':
    options_file = sys.argv[1]
    opt = options_reader(options_file)

    if len(sys.argv) == 3:
        snap_index = int(sys.argv[2])
        g = gizmo_interface(opt, snap_index)
    else:
        g = gizmo_interface(opt)
示例#4
0
                     np.cos(theta[1])]])
    R_z = np.array([[np.cos(theta[2]), -np.sin(theta[2]), 0],
                    [np.sin(theta[2]), np.cos(theta[2]), 0], [0, 0, 1]])
    R = np.dot(R_x, np.dot(R_y, R_z))

    # this is the real one
    # R = np.dot(R_z, np.dot( R_y, R_x ))
    return R


def euler_rotate(theta, vec):
    mat = euler_matrix(theta)
    return np.transpose(np.tensordot(mat, np.transpose(vec), axes=1))


opt = options_reader('../options_m12i')
ac = snapshot_action_calculator(opt, snapshot_file='cluster_snapshots_m12i.p')

cluster = dill.load(open('cluster_snapshots_m12i.p', 'rb'))
npart = len(cluster[0]['position'])
nsnap = len(cluster)

pos = np.array([cl['position'] for cl in cluster])
vel = np.array([cl['velocity'] for cl in cluster])
time = np.array([cl['time'] for cl in cluster])

pos_flat = np.reshape(pos, (npart * nsnap, 3))
vel_flat = np.reshape(vel, (npart * nsnap, 3))
actions = ac.all_actions(pos=pos_flat, vel=vel_flat)