How to use the plonk.utils.math.norm function in plonk

To help you get started, we’ve selected a few plonk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmentipl / plonk / plonk / analysis / particles.py View on Github external
pos = snap['position']
        vel = snap['velocity']

    origin = np.array(origin)
    pos = pos - origin

    mu = gravitational_parameter
    if not isinstance(pos, Quantity):
        mu = (mu * snap.units['time'] ** 2 / snap.units['length'] ** 3).magnitude

    radius = norm(pos, axis=1)

    _specific_angular_momentum = cross(pos, vel)
    specific_angular_momentum_magnitude = norm(_specific_angular_momentum, axis=1)

    _specific_kinetic_energy = 1 / 2 * norm(vel, axis=1) ** 2
    specific_potential_energy = -mu / radius
    specific_energy = _specific_kinetic_energy + specific_potential_energy

    term = specific_energy * (specific_angular_momentum_magnitude / mu) ** 2
    return np.sqrt(1 + 2 * term)
github dmentipl / plonk / plonk / analysis / particles.py View on Github external
if ignore_accreted:
        h: ndarray = snap['smoothing_length']
        pos: ndarray = snap['position'][h > 0]
        vel: ndarray = snap['velocity'][h > 0]
    else:
        pos = snap['position']
        vel = snap['velocity']

    origin = np.array(origin)
    pos = pos - origin

    mu = gravitational_parameter
    if not isinstance(pos, Quantity):
        mu = (mu * snap.units['time'] ** 2 / snap.units['length'] ** 3).magnitude

    radius = norm(pos, axis=1)

    _specific_angular_momentum = cross(pos, vel)
    specific_angular_momentum_magnitude = norm(_specific_angular_momentum, axis=1)

    _specific_kinetic_energy = 1 / 2 * norm(vel, axis=1) ** 2
    specific_potential_energy = -mu / radius
    specific_energy = _specific_kinetic_energy + specific_potential_energy

    term = specific_energy * (specific_angular_momentum_magnitude / mu) ** 2
    return np.sqrt(1 + 2 * term)
github dmentipl / plonk / plonk / snap / snap.py View on Github external
return self._get_family_subsnap(inp)
        if inp in self.available_arrays(sinks):
            return self._get_array(inp, sinks)
        if inp in self._array_name_mapper.keys():
            return self._get_array(inp, sinks)
        if inp in self._array_split_mapper.keys():
            return self._get_array(inp, sinks)
        if inp_root in self._vector_arrays:
            if inp_suffix == 'x':
                return self._get_array(inp_root, sinks)[:, 0]
            if inp_suffix == 'y':
                return self._get_array(inp_root, sinks)[:, 1]
            if inp_suffix == 'z':
                return self._get_array(inp_root, sinks)[:, 2]
            if inp_suffix == 'magnitude':
                return norm(self._get_array(inp_root, sinks), axis=1)
        if inp_root in self._dust_arrays:
            if _str_is_int(inp_suffix):
                return self._get_array(inp_root)[:, int(inp_suffix) - 1]
            if inp_suffix == 'total':
                return self._get_array(inp_root).sum(axis=1)

        if self._extra_quantities:
            raise ValueError('Cannot determine item to return.')
        raise ValueError(
            'Cannot determine item to return. Extra quantities are available via\n'
            'snap.extra_quantities().'
github dmentipl / plonk / plonk / analysis / total.py View on Github external
calculated with respect to the center of mass.

    Parameters
    ----------
    snap
        The Snap object.
    ignore_accreted : optional
        Ignore accreted particles. Default is True.

    Returns
    -------
    float
        The mean inclination.
    """
    angmom = angular_momentum(snap=snap, ignore_accreted=ignore_accreted)
    return np.arccos(angmom[2] / norm(angmom))
github dmentipl / plonk / plonk / analysis / particles.py View on Github external
h: ndarray = snap['smoothing_length']
        mass: ndarray = snap['mass'][h > 0]
        pos: ndarray = snap['position'][h > 0]
        vel: ndarray = snap['velocity'][h > 0]
    else:
        mass = snap['mass']
        pos = snap['position']
        vel = snap['velocity']

    origin = (mass[:, np.newaxis] * pos).sum(axis=0) / mass.sum()
    pos = pos - origin

    _specific_angular_momentum = cross(pos, vel)

    return np.arccos(
        _specific_angular_momentum[:, 2] / norm(_specific_angular_momentum, axis=1)
    )
github dmentipl / plonk / plonk / analysis / particles.py View on Github external
pos = snap['position']
        vel = snap['velocity']

    origin = np.array(origin)
    pos = pos - origin

    mu = gravitational_parameter
    if not isinstance(pos, Quantity):
        mu = (mu * snap.units['time'] ** 2 / snap.units['length'] ** 3).magnitude

    radius = norm(pos, axis=1)

    _specific_angular_momentum = cross(pos, vel)
    specific_angular_momentum_magnitude = norm(_specific_angular_momentum, axis=1)

    _specific_kinetic_energy = 1 / 2 * norm(vel, axis=1) ** 2
    specific_potential_energy = -mu / radius
    specific_energy = _specific_kinetic_energy + specific_potential_energy

    term = specific_energy * (specific_angular_momentum_magnitude / mu) ** 2

    _eccentricity = np.sqrt(1 + 2 * term)

    return specific_angular_momentum_magnitude ** 2 / (mu * (1 - _eccentricity ** 2))
github dmentipl / plonk / plonk / analysis / particles.py View on Github external
if ignore_accreted:
        h: ndarray = snap['smoothing_length']
        pos: ndarray = snap['position'][h > 0]
        t_s: ndarray = snap['stopping_time'][h > 0]
    else:
        pos = snap['position']
        t_s = snap['stopping_time']

    origin = np.array(origin)
    pos = pos - origin

    mu = gravitational_parameter
    if not isinstance(pos, Quantity):
        mu = (mu * snap.units['time'] ** 2 / snap.units['length'] ** 3).magnitude

    radius = norm(pos, axis=1)
    Omega_k = np.sqrt(mu / radius ** 3)

    Stokes = t_s * Omega_k[:, np.newaxis]
    return Stokes
github dmentipl / plonk / plonk / analysis / particles.py View on Github external
vel: ndarray = snap['velocity'][h > 0]
    else:
        pos = snap['position']
        vel = snap['velocity']

    origin = np.array(origin)
    pos = pos - origin

    mu = gravitational_parameter
    if not isinstance(pos, Quantity):
        mu = (mu * snap.units['time'] ** 2 / snap.units['length'] ** 3).magnitude

    radius = norm(pos, axis=1)

    _specific_angular_momentum = cross(pos, vel)
    specific_angular_momentum_magnitude = norm(_specific_angular_momentum, axis=1)

    _specific_kinetic_energy = 1 / 2 * norm(vel, axis=1) ** 2
    specific_potential_energy = -mu / radius
    specific_energy = _specific_kinetic_energy + specific_potential_energy

    term = specific_energy * (specific_angular_momentum_magnitude / mu) ** 2

    _eccentricity = np.sqrt(1 + 2 * term)

    return specific_angular_momentum_magnitude ** 2 / (mu * (1 - _eccentricity ** 2))