Skip to content

Turbulence kinetic energy calculation #3756

Closed

Description

@mer1993

What went wrong?

The tke function in turbulence.py returns the turbulent kinetic energy as: 0.5 * np.sqrt(u_cont + v_cont + w_cont)
​
However, with the square root applied, wouldn’t the unit be in m/s rather than m²/s²? My question is: wouldn't the final output be more similar to a velocity rather than an energy (in m²/s²)? Would the formula be: 0.5 * (u_cont + v_cont + w_cont)

Also, the calculation of perturbation velocities (u_prime, v_prime, and w_prime) uses the mean over the entire time dimension of the dataset. Would there be an option to choose the frequency? Currently, if the dataset spans 20 years, the script calculates perturbation velocities based on a 20-year mean, which would remove all variability and fluctuations, which might cause issues with the representation of perturbation velocity components.

Your guidance on the TKE formula and perturbation velocity calculations would be greatly appreciated.

Regards,

Operating System

Linux

Version

v1.6

Python Version

3.10.13

Code to Reproduce

def tke(u, v, w, perturbation=False, axis=-1):
    r"""Compute turbulence kinetic energy.

    Compute the turbulence kinetic energy (e) from the time series of the
    velocity components.

    Parameters
    ----------
    u : array-like
        The wind component along the x-axis
    v : array-like
        The wind component along the y-axis
    w : array-like
        The wind component along the z-axis
    perturbation : bool, optional
                   True if the `u`, `v`, and `w` components of wind speed
                   supplied to the function are perturbation velocities.
                   If False, perturbation velocities will be calculated by
                   removing the mean value from each component.

    Returns
    -------
    array-like
        The corresponding turbulence kinetic energy value

    Other Parameters
    ----------------
    axis : int
           The index of the time axis. Default is -1

    See Also
    --------
    get_perturbation : Used to compute perturbations if `perturbation`
                       is False.

    Notes
    -----
    Turbulence Kinetic Energy is computed as:

    .. math:: e = 0.5 \sqrt{\overline{u^{\prime2}} +
                            \overline{v^{\prime2}} +
                            \overline{w^{\prime2}}},

    where the velocity components

    .. math:: u^{\prime}, v^{\prime}, u^{\prime}

    are perturbation velocities. For more information on the subject, please
    see [Garratt1994]_.

    """
    if not perturbation:
        u = get_perturbation(u, axis=axis)
        v = get_perturbation(v, axis=axis)
        w = get_perturbation(w, axis=axis)

    u_cont = np.mean(u**2, axis=axis)
    v_cont = np.mean(v**2, axis=axis)
    w_cont = np.mean(w**2, axis=axis)

    return 0.5 * np.sqrt(u_cont + v_cont + w_cont)

Errors, Traceback, and Logs

Activity

  1. lesserwhirls commented on Feb 12, 2025

    @lesserwhirls
    Member

    Hello @mer1993! Yes, that is a bug. It should be 0.5 * (u_cont + v_cont + w_cont). I will get that fixed asap.

    For your second question regarding the perturbations, what you could do is compute the perturbation velocities and pass those into the tke function along with the perturbation=True parameter.

  2. added a commit that references this issue on Feb 12, 2025
    c3737e3
  3. added a commit that references this issue on Feb 12, 2025
    ca236e5
  4. added this to the 1.7.0 milestone on Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions