Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbulence kinetic energy calculation #3756

Closed
mer1993 opened this issue Feb 12, 2025 · 1 comment · Fixed by #3757
Closed

Turbulence kinetic energy calculation #3756

mer1993 opened this issue Feb 12, 2025 · 1 comment · Fixed by #3757
Labels
Type: Bug Something is not working like it should
Milestone

Comments

@mer1993
Copy link

mer1993 commented Feb 12, 2025

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

@mer1993 mer1993 added the Type: Bug Something is not working like it should label Feb 12, 2025
@lesserwhirls
Copy link
Contributor

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.

dopplershift added a commit that referenced this issue Feb 12, 2025
BUG: Fix turbulence kinetic energy calculation (Fixes #3756)
@dopplershift dopplershift added this to the 1.7.0 milestone Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants