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 and its dissipation rate , and sets the eddy viscosity to . 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 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 and pressure , plus two scalar fields: (m^2/s^2) and (m^2/s^3). The kinematic viscosity is (m^2/s).
Equations. With the Boussinesq stresses and the production ,
where 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 |
|---|---|---|
| 0.09 | the ratio measured in shear layers in equilibrium, which the model gives as | |
| 1.92 | the decay of grid turbulence | |
| 1.44 | the growth of shear flows, chiefly homogeneous shear and free shear layers | |
| 1.0 | a choice of order one | |
| 1.3 | the log law, through the relation for below |
The equation is the exact one with its unclosed terms modeled by gradient diffusion. The equation is a model built to look like the equation, not a model of the exact 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 and 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, and the diffusion terms vanish, which leaves two ordinary differential equations. The procedure below integrates them with the classical Runge-Kutta method.
K-EPSILON-DECAY(k_0, ε_0, T, m, C_2)- 1
h ← T / m; (k, ε) ← (k_0, ε_0) - 2
f(k, ε) = (-ε, -C_2 ε^2 / k) - 3
for step ← 1 to m: - 4
a ← f(k, ε); b ← f((k, ε) + h a / 2); c ← f((k, ε) + h b / 2); d ← f((k, ε) + h c) - 5
(k, ε) ← (k, ε) + h (a + 2b + 2c + d) / 6 - 6
return k, ε
Each step costs four evaluations of , and the error at a fixed falls like . 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 and positive.
What it counts
The model gives the mean flow, , , the eddy viscosity and the Reynolds stresses in the Boussinesq form. From and it gives a turbulence time scale and length scale , 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 , which is the mixing length model with .
- k-omega. The substitution 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 equation, and realizable k-epsilon models make depend on the strain so that the normal stresses stay nonnegative.
- K41. The Kolmogorov theory says that is set by the large eddies and passed down the cascade, which is why , not a viscous quantity, is the second variable.
Known results in the model
Eddy viscosity by hand. With m^2/s^2 and m^2/s^3, m^2/s.
Decay of homogeneous turbulence (exact in the model). The decay equations and have the solution
Check by substitution: the first equation gives , and the second gives , so . With , . Starting from and , s and 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 was chosen: the agreement is a fit.
Log layer (exact in the model). In a constant-stress layer with production equal to dissipation and , the model has the solution , and , provided
With the standard constants, and , and , so . This is close to the measured 0.41 but not equal: the constants are a compromise among several flows. With m/s at m and , m^2/s^2, m^2/s^3 and 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 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.
# 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
- 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
- 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
- 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
- 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)
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag FJGR38 Edit this page History Report an error Markdown