Algorithm Search⌘K

Modelcore

k-epsilon turbulence model

Also called standard k-epsilon model.

Two transport equations, for turbulent kinetic energy k and its dissipation rate epsilon, give the eddy viscosity C k^2/epsilon.

The k-epsilon model is a two-equation closure of the Reynolds-averaged Navier-Stokes equations that solves transport equations for the turbulent kinetic energy kk and its dissipation rate ε\varepsilon, and sets the eddy viscosity to νt=Cμk2/ε\nu_t = C_\mu k^2/\varepsilon. It uses the Boussinesq hypothesis for the stresses, and, unlike the mixing length model, it needs no prescribed length. Its five constants are fitted to simple flows. The k-omega model carries ω=ε/(Cμk)\omega = \varepsilon/(C_\mu k) instead and handles walls better, the SST model blends the two, and the standard form is used with wall functions because it is poor in the viscous sublayer.

The machine

Unknowns. The mean velocity UiU_i and pressure PP, plus two scalar fields: kk (m^2/s^2) and ε\varepsilon (m^2/s^3). The kinematic viscosity is ν\nu (m^2/s).

Equations. With the Boussinesq stresses and the production P=2νtSijSij\mathcal P = 2\nu_t S_{ij}S_{ij},

νt=Cμk2ε,\nu_t = C_\mu \frac{k^2}{\varepsilon},
DkDt=P−ε+∇⋅[(ν+νtσk)∇k],\frac{Dk}{Dt} = \mathcal P - \varepsilon + \nabla\cdot\left[\left(\nu + \frac{\nu_t}{\sigma_k}\right)\nabla k\right],
DεDt=C1εkP−C2ε2k+∇⋅[(ν+νtσε)∇ε],\frac{D\varepsilon}{Dt} = C_1 \frac{\varepsilon}{k}\mathcal P - C_2 \frac{\varepsilon^2}{k} + \nabla\cdot\left[\left(\nu + \frac{\nu_t}{\sigma_\varepsilon}\right)\nabla\varepsilon\right],

where D/DtD/Dt is the derivative following the mean flow.

Parameters. The standard constants of Launder and Sharma (1974) are all fitted, not derived:

constant value fitted to
CμC_\mu 0.09 the ratio −⟨u′v′⟩/k≈0.3-\langle u'v' \rangle/k \approx 0.3 measured in shear layers in equilibrium, which the model gives as Cμ\sqrt{C_\mu}
C2C_2 1.92 the decay of grid turbulence
C1C_1 1.44 the growth of shear flows, chiefly homogeneous shear and free shear layers
σk\sigma_k 1.0 a choice of order one
σε\sigma_\varepsilon 1.3 the log law, through the relation for κ\kappa below

The kk equation is the exact one with its unclosed terms modeled by gradient diffusion. The ε\varepsilon equation is a model built to look like the kk equation, not a model of the exact ε\varepsilon equation term by term (Pope 10.4.2).

Near walls. The standard model is not valid in the viscous sublayer. It is used with wall functions that set kk and ε\varepsilon at the first grid point, or in low Reynolds number forms with damping functions, such as the original Jones and Launder model.

Decaying turbulence. In homogeneous turbulence with no mean gradient, P=0\mathcal P = 0 and the diffusion terms vanish, which leaves two ordinary differential equations. The procedure below integrates them with the classical Runge-Kutta method.

  1. K-EPSILON-DECAY(k_0, ε_0, T, m, C_2)
  2. 1h ← T / m; (k, ε) ← (k_0, ε_0)
  3. 2f(k, ε) = (-ε, -C_2 ε^2 / k)
  4. 3for step ← 1 to m:
  5. 4a ← f(k, ε); b ← f((k, ε) + h a / 2); c ← f((k, ε) + h b / 2); d ← f((k, ε) + h c)
  6. 5(k, ε) ← (k, ε) + h (a + 2b + 2c + d) / 6
  7. 6return k, ε

Each step costs four evaluations of ff, and the error at a fixed TT falls like h4h^4. In a full flow solver the two equations are discretized like the momentum equations, usually by the finite volume method with upwind convection, and the source terms are treated implicitly to keep kk and ε\varepsilon positive.

What it counts

The model gives the mean flow, kk, ε\varepsilon, the eddy viscosity and the Reynolds stresses in the Boussinesq form. From kk and ε\varepsilon it gives a turbulence time scale k/εk/\varepsilon and length scale k3/2/εk^{3/2}/\varepsilon, which are useful for mixing, heat transfer and combustion models.

Relation to other models

  • Closure hypothesis. It is a Boussinesq closure, so it shares its limits: equal normal stresses in simple shear and no stress anisotropy.
  • Mixing length. In an equilibrium log layer the model gives νt=κuτy\nu_t = \kappa u_\tau y, which is the mixing length model with ℓm=κy\ell_m = \kappa y.
  • k-omega. The substitution ω=ε/(Cμk)\omega = \varepsilon/(C_\mu k) turns the model into a k-omega model with an extra cross-diffusion term. The Wilcox k-omega model drops that term.
  • SST. The SST model uses k-omega near walls and the transformed k-epsilon model away from them, and limits the shear stress.
  • Variants. The RNG k-epsilon model changes the constants and adds a strain-dependent term to the ε\varepsilon equation, and realizable k-epsilon models make CμC_\mu depend on the strain so that the normal stresses stay nonnegative.
  • K41. The Kolmogorov theory says that ε\varepsilon is set by the large eddies and passed down the cascade, which is why ε\varepsilon, not a viscous quantity, is the second variable.

Known results in the model

Eddy viscosity by hand. With k=1k = 1 m^2/s^2 and ε=10\varepsilon = 10 m^2/s^3, νt=0.09×1/10=0.009\nu_t = 0.09 \times 1/10 = 0.009 m^2/s.

Decay of homogeneous turbulence (exact in the model). The decay equations dk/dt=−εdk/dt = -\varepsilon and dε/dt=−C2ε2/kd\varepsilon/dt = -C_2\varepsilon^2/k have the solution

k=k0(1+tt0)−n,ε=ε0(1+tt0)−n−1,n=1C2−1,t0=nk0ε0.k = k_0\left(1 + \frac{t}{t_0}\right)^{-n}, \qquad \varepsilon = \varepsilon_0\left(1 + \frac{t}{t_0}\right)^{-n-1}, \qquad n = \frac{1}{C_2 - 1}, \quad t_0 = \frac{n k_0}{\varepsilon_0}.

Check by substitution: the first equation gives ε0=nk0/t0\varepsilon_0 = n k_0/t_0, and the second gives (n+1)/t0=C2ε0/k0=C2n/t0(n + 1)/t_0 = C_2\varepsilon_0/k_0 = C_2 n/t_0, so n+1=C2nn + 1 = C_2 n. With C2=1.92C_2 = 1.92, n=1.087n = 1.087. Starting from k0=1k_0 = 1 and ε0=1\varepsilon_0 = 1, t0=1.087t_0 = 1.087 s and k(t0)=2−1.087=0.471k(t_0) = 2^{-1.087} = 0.471 m^2/s^2. The tests check the RK4 solution against this formula and its fourth-order convergence. Measured decay exponents in grid turbulence are of the same size, a little above 1 (Pope 5.4.6), which is how C2C_2 was chosen: the agreement is a fit.

Log layer (exact in the model). In a constant-stress layer with production equal to dissipation and U=(uτ/κ)ln⁡y+constU = (u_\tau/\kappa)\ln y + \text{const}, the model has the solution k=uτ2/Cμk = u_\tau^2/\sqrt{C_\mu}, ε=uτ3/(κy)\varepsilon = u_\tau^3/(\kappa y) and νt=κuτy\nu_t = \kappa u_\tau y, provided

κ2=σεCμ (C2−C1).\kappa^2 = \sigma_\varepsilon\sqrt{C_\mu}\,(C_2 - C_1).

With the standard constants, 0.09=0.3\sqrt{0.09} = 0.3 and k/uτ2=3.33k/u_\tau^2 = 3.33, and κ2=1.3×0.3×0.48=0.1872\kappa^2 = 1.3 \times 0.3 \times 0.48 = 0.1872, so κ=0.433\kappa = 0.433. This is close to the measured 0.41 but not equal: the constants are a compromise among several flows. With uτ=0.5u_\tau = 0.5 m/s at y=0.01y = 0.01 m and κ=0.41\kappa = 0.41, k=0.833k = 0.833 m^2/s^2, ε=30.5\varepsilon = 30.5 m^2/s^3 and νt=0.00205\nu_t = 0.00205 m^2/s.

Agreement with experiment (measurement). The model gives good spreading rates for plane free shear layers and reasonable results for attached boundary layers in weak pressure gradients. Measurements show known failures: it predicts too much kk near stagnation points, the wrong spreading rate for the round jet compared with the plane jet, and too much skin friction and delayed separation in adverse pressure gradients. These are measured shortcomings of the fitted model, not of the averaged equations.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

k_epsilon_model.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/k-epsilon-model/. The authors are listed in prov/FJGR38.jsonl.

"""Standard k-epsilon model: eddy viscosity, decay of homogeneous turbulence
and the log-layer relations, with the constants of Launder and Sharma (1974).

Units are SI: k in m^2/s^2, eps in m^2/s^3, nu_t in m^2/s, t in s.
"""

import math

C_MU = 0.09
C_1 = 1.44
C_2 = 1.92
SIGMA_K = 1.0
SIGMA_EPS = 1.3


def eddy_viscosity(k: float, eps: float, c_mu: float = C_MU) -> float:
    """nu_t = C_mu k^2 / eps."""
    if eps <= 0:
        raise ValueError("eps must be positive")
    return c_mu * k * k / eps


def decay_rhs(k: float, eps: float, c2: float = C_2) -> tuple[float, float]:
    """Right side of the model for homogeneous decaying turbulence (no production, no diffusion)."""
    return -eps, -c2 * eps * eps / k  # @line L2


def rk4_decay(k0: float, eps0: float, t_end: float, m: int, c2: float = C_2) -> tuple[float, float]:
    """Integrate dk/dt = -eps, deps/dt = -C_2 eps^2 / k from 0 to t_end with m steps of classical RK4."""
    if m < 1 or k0 <= 0 or eps0 <= 0:
        raise ValueError("need m >= 1 and positive k0, eps0")
    h = t_end / m  # @line L1
    k, e = k0, eps0  # @line L1
    for _ in range(m):  # @line L3
        a = decay_rhs(k, e, c2)  # @line L4
        b = decay_rhs(k + 0.5 * h * a[0], e + 0.5 * h * a[1], c2)  # @line L4
        c = decay_rhs(k + 0.5 * h * b[0], e + 0.5 * h * b[1], c2)  # @line L4
        d = decay_rhs(k + h * c[0], e + h * c[1], c2)  # @line L4
        k += h * (a[0] + 2 * b[0] + 2 * c[0] + d[0]) / 6  # @line L5
        e += h * (a[1] + 2 * b[1] + 2 * c[1] + d[1]) / 6  # @line L5
    return k, e  # @line L6


def decay_exponent(c2: float = C_2) -> float:
    """The power n in k ~ t^(-n) for decaying turbulence: n = 1 / (C_2 - 1)."""
    return 1.0 / (c2 - 1.0)


def exact_decay(k0: float, eps0: float, t: float, c2: float = C_2) -> tuple[float, float]:
    """Exact solution k = k0 (1 + t/t0)^(-n), eps = eps0 (1 + t/t0)^(-n-1), with t0 = n k0 / eps0."""
    n = decay_exponent(c2)
    t0 = n * k0 / eps0
    s = 1.0 + t / t0
    return k0 * s ** (-n), eps0 * s ** (-n - 1.0)


def log_layer_kappa(c_mu: float = C_MU, c1: float = C_1, c2: float = C_2, sigma_eps: float = SIGMA_EPS) -> float:
    """The von Karman constant implied by the model: kappa^2 = sigma_eps sqrt(C_mu) (C_2 - C_1)."""
    return math.sqrt(sigma_eps * math.sqrt(c_mu) * (c2 - c1))


def log_layer_state(u_tau: float, y: float, kappa: float = 0.41, c_mu: float = C_MU) -> tuple[float, float, float]:
    """k, eps and nu_t in an equilibrium log layer: k = u_tau^2 / sqrt(C_mu), eps = u_tau^3 / (kappa y)."""
    k = u_tau * u_tau / math.sqrt(c_mu)
    eps = u_tau**3 / (kappa * y)
    return k, eps, eddy_viscosity(k, eps, c_mu)
test_k_epsilon_model.py 86 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/k-epsilon-model/. The authors are listed in prov/FJGR38.jsonl.

import math
import random

import pytest

from k_epsilon_model import (
    C_1,
    C_2,
    C_MU,
    SIGMA_EPS,
    decay_exponent,
    eddy_viscosity,
    exact_decay,
    log_layer_kappa,
    log_layer_state,
    rk4_decay,
)


def test_eddy_viscosity_example():
    assert eddy_viscosity(1.0, 10.0) == pytest.approx(0.009)
    with pytest.raises(ValueError):
        eddy_viscosity(1.0, 0.0)


def test_decay_exponent():
    assert decay_exponent() == pytest.approx(1.086957, abs=1e-6)
    assert decay_exponent(2.0) == pytest.approx(1.0)


def test_exact_decay_satisfies_the_odes():
    k0, e0 = 1.0, 1.0
    t, d = 0.7, 1e-6
    k, e = exact_decay(k0, e0, t)
    kp, ep = exact_decay(k0, e0, t + d)
    km, em = exact_decay(k0, e0, t - d)
    assert (kp - km) / (2 * d) == pytest.approx(-e, rel=1e-7)
    assert (ep - em) / (2 * d) == pytest.approx(-C_2 * e * e / k, rel=1e-7)
    # at t = t0 = n k0 / eps0 the energy has dropped by 2^(-n)
    n = decay_exponent()
    assert exact_decay(k0, e0, n)[0] == pytest.approx(2.0 ** (-n))
    assert exact_decay(k0, e0, n)[0] == pytest.approx(0.47076, abs=1e-5)


def test_rk4_matches_exact_for_random_starts():
    rng = random.Random(41)
    for _ in range(5):
        k0 = rng.uniform(0.1, 5.0)
        e0 = rng.uniform(0.1, 5.0)
        t = rng.uniform(1.0, 10.0)
        k, e = rk4_decay(k0, e0, t, 400)
        ke, ee = exact_decay(k0, e0, t)
        assert k == pytest.approx(ke, rel=1e-8)
        assert e == pytest.approx(ee, rel=1e-8)


def test_rk4_is_fourth_order():
    ke, _ = exact_decay(1.0, 1.0, 2.0)
    errs = [abs(rk4_decay(1.0, 1.0, 2.0, m)[0] - ke) for m in (40, 80, 160)]
    for a, b in zip(errs, errs[1:]):
        assert abs(math.log2(a / b) - 4.0) < 0.2


def test_late_time_slope_is_minus_n():
    t1, t2 = 1e3, 2e3
    k1, _ = rk4_decay(1.0, 1.0, t1, 4000)
    k2, _ = rk4_decay(1.0, 1.0, t2, 8000)
    slope = math.log(k2 / k1) / math.log(t2 / t1)
    assert slope == pytest.approx(-decay_exponent(), abs=2e-3)


def test_log_layer():
    assert log_layer_kappa() == pytest.approx(0.43267, abs=1e-5)
    # the eddy viscosity of the log layer is kappa u_tau y, as in the mixing length model
    k, eps, nut = log_layer_state(0.5, 0.01)
    assert k == pytest.approx(0.25 / 0.3)
    assert nut == pytest.approx(0.41 * 0.5 * 0.01)
    # production equals dissipation: nu_t (dU/dy)^2 with dU/dy = u_tau / (kappa y)
    dudy = 0.5 / (0.41 * 0.01)
    assert nut * dudy * dudy == pytest.approx(eps)
    # -<u'v'> / k = sqrt(C_mu)
    assert 0.25 / k == pytest.approx(math.sqrt(C_MU))
    assert SIGMA_EPS * math.sqrt(C_MU) * (C_2 - C_1) == pytest.approx(log_layer_kappa() ** 2)

References

  1. W. P. Jones and B. E. Launder, The prediction of laminarization with a two-equation model of turbulence, International Journal of Heat and Mass Transfer 15(2), 1972, 301-314, the transport equations for k and epsilon, with damping terms for low Reynolds numbers
  2. B. E. Launder and B. I. Sharma, Application of the energy-dissipation model of turbulence to the calculation of flow near a spinning disc, Letters in Heat and Mass Transfer 1(2), 1974, 131-137, the standard constants C_mu = 0.09, C_1 = 1.44, C_2 = 1.92, sigma_k = 1.0, sigma_eps = 1.3
  3. B. E. Launder and D. B. Spalding, The numerical computation of turbulent flows, Computer Methods in Applied Mechanics and Engineering 3(2), 1974, 269-289, the model with its constants and the wall functions used with it
  4. Stephen B. Pope, Turbulent Flows, Cambridge University Press, 2000, Section 5.4.6 (grid turbulence), Section 10.3 (turbulent kinetic energy models) and Section 10.4 (the k-epsilon model, 10.4.2 the model equation for epsilon)
  5. David C. Wilcox, Turbulence Modeling for CFD, third edition, DCW Industries, 2006, Chapter 4 (two-equation models, the k-epsilon model and its closure coefficients)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/FJGR38/text.yaml