Esempio n. 1
0
def _gravitationally_bound(clump,
                           use_thermal_energy=True,
                           use_particles=True,
                           truncate=True):
    "True if clump is gravitationally bound."

    use_particles &= \
      ("all", "particle_mass") in clump.data.ds.field_info

    bulk_velocity = clump.quantities.bulk_velocity(use_particles=use_particles)

    kinetic = 0.5 * (clump["gas", "cell_mass"] * (
        (bulk_velocity[0] - clump["gas", "velocity_x"])**2 +
        (bulk_velocity[1] - clump["gas", "velocity_y"])**2 +
        (bulk_velocity[2] - clump["gas", "velocity_z"])**2)).sum()

    if use_thermal_energy:
        kinetic += (clump["gas", "cell_mass"] *
                    clump["gas", "thermal_energy"]).sum()

    if use_particles:
        kinetic += 0.5 * (clump["all", "particle_mass"] * (
            (bulk_velocity[0] - clump["all", "particle_velocity_x"])**2 +
            (bulk_velocity[1] - clump["all", "particle_velocity_y"])**2 +
            (bulk_velocity[2] - clump["all", "particle_velocity_z"])**2)
                          ).sum()

    potential = clump.data.ds.quan(
        G * gravitational_binding_energy(
            clump["gas", "cell_mass"].in_cgs(), clump["index", "x"].in_cgs(),
            clump["index", "y"].in_cgs(), clump["index", "z"].in_cgs(),
            truncate, (kinetic / G).in_cgs()),
        kinetic.in_cgs().units)

    if truncate and potential >= kinetic:
        return True

    if use_particles:
        potential += clump.data.ds.quan(
            G * gravitational_binding_energy(
                clump["all", "particle_mass"].in_cgs(),
                clump["all", "particle_position_x"].in_cgs(),
                clump["all", "particle_position_y"].in_cgs(),
                clump["all", "particle_position_z"].in_cgs(), truncate,
                ((kinetic - potential) / G).in_cgs()),
            kinetic.in_cgs().units)

    return potential >= kinetic
Esempio n. 2
0
def _future_bound(
        clump,
        use_thermal_energy=True,
        truncate=True,
        include_cooling=True):
    """
    True if clump has negative total energy. This considers gas kinetic
    energy, thermal energy, and radiative losses over a free-fall time
    against gravitational potential energy of the gas and collisionless
    particle system.
    """

    num_threads = int(os.environ.get('OMP_NUM_THREADS', 1))

    if clump["gas", "cell_mass"].size <= 1:
        mylog.info("Clump has only one cell.")
        return False

    bulk_velocity = clump.quantities.bulk_velocity(
        use_particles=False)

    kinetic = 0.5 * (clump["gas", "cell_mass"] *
        ((bulk_velocity[0] - clump["gas", "velocity_x"])**2 +
         (bulk_velocity[1] - clump["gas", "velocity_y"])**2 +
         (bulk_velocity[2] - clump["gas", "velocity_z"])**2)).sum()

    mylog.info("Kinetic energy: %e erg." %
               kinetic.in_units("erg"))

    if use_thermal_energy:
        cooling_loss = clump.data.ds.quan(0.0, "erg")
        thermal = (clump["gas", "cell_mass"] *
                   clump["gas", "thermal_energy"]).sum()
        mylog.info("Thermal energy: %e erg." %
                   thermal.in_units("erg"))

        if include_cooling:
            # divide by sqrt(2) since t_ff = t_dyn / sqrt(2)
            cooling_loss = \
                (clump["gas", "cell_mass"] *
                 clump["gas", "dynamical_time"] *
                 clump["gas", "thermal_energy"] /
                 clump["gas", "cooling_time"]).sum() / np.sqrt(2)
            mylog.info("Cooling loss: %e erg." %
                       cooling_loss.in_units("erg"))

        thermal -= np.abs(cooling_loss)
        kinetic += thermal
        kinetic = max(kinetic, clump.data.ds.quan(0.0, "erg"))

    mylog.info("Available energy: %e erg." %
               kinetic.in_units("erg"))

    m = np.concatenate([clump["gas", "cell_mass"].in_cgs(),
                        clump["all", "particle_mass"].in_cgs()])
    px = np.concatenate([clump["index", "x"].in_cgs(),
                         clump["all", "particle_position_x"].in_cgs()])
    py = np.concatenate([clump["index", "y"].in_cgs(),
                         clump["all", "particle_position_y"].in_cgs()])
    pz = np.concatenate([clump["index", "z"].in_cgs(),
                         clump["all", "particle_position_z"].in_cgs()])

    potential = clump.data.ds.quan(
        G * gravitational_binding_energy(
            m, px, py, pz,
            truncate, (kinetic / G).in_cgs(),
            num_threads=num_threads),
        kinetic.in_cgs().units)

    mylog.info("Potential energy: %e erg." %
               potential.to('erg'))

    return potential >= kinetic
Esempio n. 3
0
def _gravitationally_bound(clump,
                           use_thermal_energy=True,
                           use_particles=True,
                           truncate=True,
                           num_threads=0):
    "True if clump is gravitationally bound."

    use_particles &= ("all", "particle_mass") in clump.data.ds.field_info

    bulk_velocity = clump.quantities.bulk_velocity(use_particles=use_particles)

    kinetic = (0.5 *
               (clump["gas", "cell_mass"] *
                ((bulk_velocity[0] - clump["gas", "velocity_x"])**2 +
                 (bulk_velocity[1] - clump["gas", "velocity_y"])**2 +
                 (bulk_velocity[2] - clump["gas", "velocity_z"])**2)).sum())

    if use_thermal_energy:
        kinetic += (clump["gas", "cell_mass"] *
                    clump["gas", "thermal_energy"]).sum()

    if use_particles:
        kinetic += (0.5 * (clump["all", "particle_mass"] * (
            (bulk_velocity[0] - clump["all", "particle_velocity_x"])**2 +
            (bulk_velocity[1] - clump["all", "particle_velocity_y"])**2 +
            (bulk_velocity[2] - clump["all", "particle_velocity_z"])**2)
                           ).sum())

    if use_particles:
        m = np.concatenate([
            clump["gas", "cell_mass"].in_cgs(),
            clump["all", "particle_mass"].in_cgs()
        ])
        px = np.concatenate([
            clump["index", "x"].in_cgs(),
            clump["all", "particle_position_x"].in_cgs()
        ])
        py = np.concatenate([
            clump["index", "y"].in_cgs(),
            clump["all", "particle_position_y"].in_cgs()
        ])
        pz = np.concatenate([
            clump["index", "z"].in_cgs(),
            clump["all", "particle_position_z"].in_cgs()
        ])
    else:
        m = clump["gas", "cell_mass"].in_cgs()
        px = clump["index", "x"].in_cgs()
        py = clump["index", "y"].in_cgs()
        pz = clump["index", "z"].in_cgs()

    potential = clump.data.ds.quan(
        G * gravitational_binding_energy(m,
                                         px,
                                         py,
                                         pz,
                                         truncate, (kinetic / G).in_cgs(),
                                         num_threads=num_threads),
        kinetic.in_cgs().units,
    )

    if truncate and potential >= kinetic:
        return True

    return potential >= kinetic