Algorithm Search⌘K

Techniquecore

Wall functions

Also called log-law wall function.

Replace the resolution of the thin near-wall layer by the logarithmic law of the wall, which gives the wall shear stress from the first cell velocity.

Wall functions are boundary conditions for turbulence models that replace the resolution of the viscous sublayer and the buffer layer next to a wall by the logarithmic law of the wall: from the mean velocity at the first grid point they give the wall shear stress and the values of the turbulence variables there. They close the gap between the Reynolds-averaged Navier-Stokes equations with a Boussinesq closure and the wall, mostly for the k-epsilon model, which is not valid in the sublayer. The log law they impose is the one the mixing length model predicts, with constants fitted to measurements. The k-omega, SST and Spalart-Allmaras models can instead be integrated to the wall on a fine grid.

In plain words

Right next to a wall, the flow changes very fast over a very thin layer. Resolving that layer would need many tiny cells, often more than the rest of the domain. Measurements show that the velocity in this layer follows a nearly universal profile, once distance and speed are scaled by the wall friction. A wall function uses that profile as a shortcut. The first grid point is placed outside the thin layer. Its velocity and its distance from the wall are fed into the known profile, which is solved for the friction at the wall. That friction is then applied as a force on the flow. The same profile also gives the turbulence level at the first point. The shortcut is good when the flow is attached and calm along the wall, and poor where it separates.

When it applies

  • The wall-adjacent cell center is in the log layer. Wall units are y+=uτy/νy^+ = u_\tau y/\nu, u+=U/uτu^+ = U/u_\tau, with uτ=τw/ρu_\tau = \sqrt{\tau_w/\rho}, ν\nu the kinematic viscosity (m^2/s) and τw\tau_w the wall shear stress (Pa). The usual range for the first point is 30≲y+≲30030 \lesssim y^+ \lesssim 300; this is a rule of thumb, and the upper limit grows with the Reynolds number because the log layer reaches out to about a tenth or a fifth of the boundary layer thickness.
  • The near-wall flow is close to local equilibrium: production of turbulence about equal to dissipation, a weak pressure gradient, and no separation in the cell.
  • The Reynolds number is high, so that the log layer is wide enough to hold the first point.
  • It does not apply where τw\tau_w changes sign (separation and reattachment), in strong pressure gradients, in low Reynolds number or transitional flows, or where wall heat transfer must be accurate.

The template

Laws (fitted to measurement). The viscous sublayer has u+=y+u^+ = y^+ (exact as y+→0y^+ \to 0). The log layer has

u+=1κln⁡y++B,κ≈0.41,B≈5.0 to 5.2.u^+ = \frac{1}{\kappa}\ln y^+ + B, \qquad \kappa \approx 0.41, \quad B \approx 5.0 \text{ to } 5.2.

The form of the log law follows from matching arguments and from the mixing length model; κ\kappa and BB are measured. The two laws cross at yc+y^+_c with yc+=ln⁡(yc+)/κ+By^+_c = \ln(y^+_c)/\kappa + B, which is 11.0611.06 for κ=0.41\kappa = 0.41 and B=5.2B = 5.2.

Friction velocity from the first point. Given the tangential velocity UPU_P at distance yPy_P, solve UP=uτ u+(yPuτ/ν)U_P = u_\tau\, u^+(y_P u_\tau/\nu) for uτu_\tau. On the log branch f(u)=u(1κln⁡yPuν+B)−UPf(u) = u\left(\frac{1}{\kappa}\ln\frac{y_P u}{\nu} + B\right) - U_P is increasing and convex, so Newton's method started from the laminar value converges after one overshoot.

  1. WALL-FUNCTION(U_P, y_P, ν, κ, B)
  2. 1y_c ← root of y = ln(y)/κ + B
  3. 2u ← sqrt(ν U_P / y_P) (laminar value)
  4. 3if y_P u / ν ≤ y_c: return u (first point in the sublayer)
  5. 4repeat
  6. 5s ← ln(y_P u / ν)/κ + B; f ← u s - U_P
  7. 6u ← u - f / (s + 1/κ)
  8. 7until |f| ≤ tol · U_P
  9. 8return u_τ = u, τ_w = ρ u^2

Use in the solver.

  1. Apply τw\tau_w as the shear force on the wall face of the first cell, in place of ρν ∂U/∂y\rho\nu\,\partial U/\partial y from the grid, which would be far too small.
  2. For the k-epsilon model: set zero flux of kk through the wall, use the wall-function stress in the production term of the first cell, and fix εP=uτ3/(κyP)\varepsilon_P = u_\tau^3/(\kappa y_P). In equilibrium kP=uτ2/Cμk_P = u_\tau^2/\sqrt{C_\mu}.
  3. For the k-omega model: fix ωP=uτ/(CμκyP)\omega_P = u_\tau/(\sqrt{C_\mu}\kappa y_P).
  4. Recompute uτu_\tau every outer iteration of the flow solver, since UPU_P changes.

Launder-Spalding form. Launder and Spalding take the velocity scale from kPk_P instead: u∗=Cμ1/4kP1/2u^* = C_\mu^{1/4}k_P^{1/2}, y∗=u∗yP/νy^* = u^* y_P/\nu, and

τwρ=κ u∗UPln⁡(Ey∗),E=eκB.\frac{\tau_w}{\rho} = \frac{\kappa\, u^* U_P}{\ln(E y^*)}, \qquad E = e^{\kappa B}.

This needs no iteration, and u∗u^* stays positive at separation and reattachment points where UPU_P and uτu_\tau go to zero. In equilibrium u∗=uτu^* = u_\tau and the two forms agree exactly, which the tests check.

Classic examples

Air over a plate (by hand). Take ν=1.5×10−5\nu = 1.5 \times 10^{-5} m^2/s, ρ=1.2\rho = 1.2 kg/m^3, UP=10U_P = 10 m/s at yP=1y_P = 1 mm, with κ=0.41\kappa = 0.41 and B=5.2B = 5.2. The Newton iterates are:

step uu (m/s) y+y^+ ff (m/s)
0 0.387298 25.82 -4.9149
1 0.702992 46.87 0.2522
2 0.688177 45.88 0.00038
3 0.688155 45.877 0.0

So uτ=0.6882u_\tau = 0.6882 m/s, y+=45.9y^+ = 45.9 (inside the 30 to 300 range), τw/ρ=0.4736\tau_w/\rho = 0.4736 m^2/s^2 and τw=0.568\tau_w = 0.568 Pa. Check: ln⁡(45.877)/0.41+5.2=14.532\ln(45.877)/0.41 + 5.2 = 14.532 and 0.688155×14.532=10.0000.688155 \times 14.532 = 10.000. The wall values for k-epsilon are kP=0.4736/0.3=1.579k_P = 0.4736/0.3 = 1.579 m^2/s^2 and εP=0.68823/(0.41×0.001)=795\varepsilon_P = 0.6882^3/(0.41 \times 0.001) = 795 m^2/s^3. The laminar value 0.387 m/s would give a wall stress 3.2 times too small.

Spalding's law. Spalding's formula

y+=u++e−κB(eκu+−1−κu+−(κu+)22−(κu+)36)y^+ = u^+ + e^{-\kappa B}\left(e^{\kappa u^+} - 1 - \kappa u^+ - \frac{(\kappa u^+)^2}{2} - \frac{(\kappa u^+)^3}{6}\right)

gives y+y^+ as an increasing function of u+u^+ that is u+u^+ in the sublayer and tends to the log law far out, with a smooth buffer layer between. With κ=0.41\kappa = 0.41 and B=5.2B = 5.2: u+(1)=1.000u^+(1) = 1.000, u+(11)=8.83u^+(11) = 8.83 (the two-law value is 11.00 from the linear law, since 11<11.0611 < 11.06; the log law alone gives 11.05), u+(30)=12.79u^+(30) = 12.79 and u+(300)=19.07u^+(300) = 19.07 against the log law's 19.11. Inverting it by bisection gives a wall function valid at any y+y^+.

Variations

  • Scalable wall functions. Use max⁡(y∗,yc+)\max(y^*, y^+_c) in place of y∗y^*, so that a first point that falls into the sublayer is treated as if it sat at the crossover. This stops the results from getting worse when the grid is refined.
  • Automatic or blended wall treatment. Blend the sublayer and log-law values of τw\tau_w and ω\omega, or use Spalding's law, so the same boundary condition works for any y+y^+. SST codes often do this.
  • Rough walls. Lower BB by a function ΔB(ks+)\Delta B(k_s^+) of the roughness height in wall units.
  • Thermal wall functions. A log law for the temperature, with a turbulent Prandtl number near 0.85 and an extra term that depends on the molecular Prandtl number, gives the wall heat flux.
  • Non-equilibrium wall functions. Include the pressure gradient and use kPk_P from its own transport equation, to do better near separation.
  • Wall models for LES. Wall-modeled large eddy simulation uses the same idea, with the instantaneous filtered velocity at the first point.

Pitfalls

  • First point in the buffer layer. For 5≲y+≲305 \lesssim y^+ \lesssim 30 neither the linear law nor the log law holds well, and the wall stress is in error.
  • Refining the grid makes it worse. With standard wall functions, a finer near-wall grid pushes y+y^+ into the sublayer, where the log law is wrong. Wall functions are not grid-converged in the usual sense; use scalable or blended forms, or a low Reynolds number model.
  • Separation. Where UP→0U_P \to 0 the log law gives uτ→0u_\tau \to 0 and εP→0\varepsilon_P \to 0, while the real turbulence there is not small. The Launder-Spalding form with u∗u^* from kPk_P avoids the zero but not the error.
  • Wrong production in the first cell. Computing P\mathcal P from the grid velocity gradient in the first cell, instead of from τw\tau_w and the log-law gradient uτ/(κyP)u_\tau/(\kappa y_P), gives too little kk there.
  • Using y+y^+ to choose the grid before the solution exists. Estimate uτu_\tau from a skin-friction correlation, then check y+y^+ after the run.

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.

wall_functions.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/wall-functions/. The authors are listed in prov/7MSEKR.jsonl.

"""Log-law wall functions: the friction velocity from the velocity at the
first grid point, the wall values of k, epsilon and omega, the Launder-Spalding
form and Spalding's single formula for the whole inner layer.

Units are SI. Wall units: y+ = u_tau y / nu, u+ = U / u_tau.
"""

import math

KAPPA = 0.41
B = 5.2
C_MU = 0.09


def log_law(y_plus: float, kappa: float = KAPPA, b: float = B) -> float:
    """u+ = ln(y+) / kappa + B."""
    return math.log(y_plus) / kappa + b


def crossover(kappa: float = KAPPA, b: float = B) -> float:
    """The y+ above 1 where the linear law u+ = y+ meets the log law."""
    y = 11.0
    for _ in range(50):
        g = y - math.log(y) / kappa - b
        dy = g / (1.0 - 1.0 / (kappa * y))
        y -= dy
        if abs(dy) < 1e-14 * y:
            break
    return y


def friction_velocity(u_p: float, y_p: float, nu: float, kappa: float = KAPPA, b: float = B, tol: float = 1e-12) -> float:
    """u_tau such that U_P = u_tau u+(y_P u_tau / nu), with the linear law below the crossover."""
    if u_p <= 0 or y_p <= 0 or nu <= 0:
        raise ValueError("need positive U_P, y_P and nu")
    y_c = crossover(kappa, b)  # @line L1
    u = math.sqrt(nu * u_p / y_p)  # @line L2
    if y_p * u / nu <= y_c:  # @line L3
        return u  # @line L3
    for _ in range(100):  # @line L4
        s = math.log(y_p * u / nu) / kappa + b  # @line L5
        f = u * s - u_p  # @line L5
        u -= f / (s + 1.0 / kappa)  # @line L6
        if abs(f) <= tol * u_p:  # @line L7
            break
    return u  # @line L8


def wall_shear_stress(u_p: float, y_p: float, nu: float, rho: float, kappa: float = KAPPA, b: float = B) -> float:
    """tau_w = rho u_tau^2 in Pa."""
    u = friction_velocity(u_p, y_p, nu, kappa, b)
    return rho * u * u  # @line L8


def wall_values(u_tau: float, y_p: float, kappa: float = KAPPA, c_mu: float = C_MU) -> tuple[float, float, float]:
    """Equilibrium k, epsilon and omega at the first point: u_tau^2/sqrt(C_mu), u_tau^3/(kappa y), u_tau/(sqrt(C_mu) kappa y)."""
    k = u_tau * u_tau / math.sqrt(c_mu)
    eps = u_tau**3 / (kappa * y_p)
    omega = u_tau / (math.sqrt(c_mu) * kappa * y_p)
    return k, eps, omega


def launder_spalding_stress(u_p: float, k_p: float, y_p: float, nu: float, kappa: float = KAPPA, b: float = B, c_mu: float = C_MU) -> float:
    """tau_w / rho = kappa u* U_P / ln(E y*), with u* = C_mu^(1/4) sqrt(k_P), y* = u* y_P / nu, E = exp(kappa B)."""
    u_star = c_mu**0.25 * math.sqrt(k_p)
    y_star = u_star * y_p / nu
    e = math.exp(kappa * b)
    return kappa * u_star * u_p / math.log(e * y_star)


def spalding_y_plus(u_plus: float, kappa: float = KAPPA, b: float = B) -> float:
    """Spalding's law: y+ = u+ + exp(-kappa B) (exp(kappa u+) - 1 - kappa u+ - (kappa u+)^2/2 - (kappa u+)^3/6)."""
    x = kappa * u_plus
    return u_plus + math.exp(-kappa * b) * (math.exp(x) - 1.0 - x - x * x / 2.0 - x**3 / 6.0)


def spalding_u_plus(y_plus: float, kappa: float = KAPPA, b: float = B) -> float:
    """Invert Spalding's law by bisection; y+ is increasing in u+."""
    lo, hi = 0.0, max(1.0, y_plus)
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if spalding_y_plus(mid, kappa, b) < y_plus:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)
test_wall_functions.py 104 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/wall-functions/. The authors are listed in prov/7MSEKR.jsonl.

import math
import random

import pytest

from wall_functions import (
    B,
    C_MU,
    KAPPA,
    crossover,
    friction_velocity,
    launder_spalding_stress,
    log_law,
    spalding_u_plus,
    spalding_y_plus,
    wall_shear_stress,
    wall_values,
)

NU_AIR = 1.5e-5


def bisect_u_tau(u_p, y_p, nu):
    lo, hi = 1e-6, u_p
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if mid * log_law(y_p * mid / nu) < u_p:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)


def test_crossover():
    y = crossover()
    assert y == pytest.approx(11.0623, abs=1e-4)
    assert log_law(y) == pytest.approx(y, abs=1e-12)


def test_air_example():
    u = friction_velocity(10.0, 1e-3, NU_AIR)
    assert u == pytest.approx(0.688155, abs=1e-6)
    assert 1e-3 * u / NU_AIR == pytest.approx(45.877, abs=1e-3)
    assert wall_shear_stress(10.0, 1e-3, NU_AIR, 1.2) == pytest.approx(0.56827, abs=1e-5)
    k, eps, omega = wall_values(u, 1e-3)
    assert k == pytest.approx(1.57852, abs=1e-5)
    assert eps == pytest.approx(794.83, abs=1e-2)
    # omega = eps / (C_mu k)
    assert omega == pytest.approx(eps / (C_MU * k))


def test_round_trip_and_bisection():
    rng = random.Random(7)
    for _ in range(50):
        u_p = rng.uniform(0.5, 50.0)
        y_p = 10 ** rng.uniform(-4, -1)
        u = friction_velocity(u_p, y_p, NU_AIR)
        y_plus = y_p * u / NU_AIR
        if y_plus > crossover():
            assert u * log_law(y_plus) == pytest.approx(u_p, rel=1e-10)
            assert u == pytest.approx(bisect_u_tau(u_p, y_p, NU_AIR), rel=1e-9)
        else:
            assert u * y_plus == pytest.approx(u_p, rel=1e-12)


def test_laminar_branch_and_continuity():
    u = friction_velocity(0.1, 1e-3, NU_AIR)
    assert u == pytest.approx(math.sqrt(NU_AIR * 0.1 / 1e-3))
    # at the crossover both laws give the same u_tau
    y_c = crossover()
    u_tau = 0.2
    y_p = y_c * NU_AIR / u_tau
    u_p = u_tau * y_c
    assert friction_velocity(u_p * (1 - 1e-9), y_p, NU_AIR) == pytest.approx(u_tau, rel=1e-6)
    assert friction_velocity(u_p * (1 + 1e-9), y_p, NU_AIR) == pytest.approx(u_tau, rel=1e-6)


def test_launder_spalding_agrees_in_equilibrium():
    for u_p, y_p in ((10.0, 1e-3), (3.0, 5e-3), (40.0, 2e-4)):
        u = friction_velocity(u_p, y_p, NU_AIR)
        k, _, _ = wall_values(u, y_p)
        assert launder_spalding_stress(u_p, k, y_p, NU_AIR) == pytest.approx(u * u, rel=1e-10)


def test_spalding_law_limits():
    assert spalding_u_plus(1.0) == pytest.approx(1.0, abs=1e-3)
    for y in (300.0, 1000.0):
        assert spalding_u_plus(y) == pytest.approx(log_law(y), abs=0.05)
    for up in (0.5, 5.0, 15.0, 25.0):
        assert spalding_u_plus(spalding_y_plus(up)) == pytest.approx(up, abs=1e-9)
    prev = 0.0
    for i in range(1, 200):
        cur = spalding_y_plus(0.15 * i)
        assert cur > prev
        prev = cur
    assert math.exp(-KAPPA * B) == pytest.approx(0.11860, abs=1e-5)


def test_bad_input():
    with pytest.raises(ValueError):
        friction_velocity(0.0, 1e-3, NU_AIR)

Exercises

  1. Water (ν=10−6\nu = 10^{-6} m^2/s) has uτ=0.05u_\tau = 0.05 m/s. Where must the first cell center be to lie at y+=50y^+ = 50? (Answer: y=50×10−6/0.05=1y = 50 \times 10^{-6}/0.05 = 1 mm.)
  2. For κ=0.41\kappa = 0.41 and B=5.2B = 5.2, show that y+=11.06y^+ = 11.06 is where the linear law and the log law meet. (Answer: ln⁡(11.06)/0.41+5.2=2.4034/0.41+5.2=11.06\ln(11.06)/0.41 + 5.2 = 2.4034/0.41 + 5.2 = 11.06.)
  3. Show that the Launder-Spalding stress equals ρuτ2\rho u_\tau^2 when kP=uτ2/Cμk_P = u_\tau^2/\sqrt{C_\mu} and UPU_P follows the log law. (Answer: then u∗=uτu^* = u_\tau, y∗=y+y^* = y^+, and κUP/uτ=ln⁡y++κB=ln⁡(Ey+)\kappa U_P/u_\tau = \ln y^+ + \kappa B = \ln(E y^+).)

References

  1. 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 wall functions for the momentum, k and epsilon equations, with u* = C_mu^(1/4) k^(1/2)
  2. D. B. Spalding, A single formula for the law of the wall, Journal of Applied Mechanics 28(3), 1961, 455-458, the formula for y+ as a function of u+ that covers the sublayer, the buffer layer and the log layer
  3. Stephen B. Pope, Turbulent Flows, Cambridge University Press, 2000, Section 7.1.4 (mean velocity profiles, the viscous sublayer and the log law), Section 7.3 (boundary layers) and Section 11.7.6 (wall functions)
  4. David C. Wilcox, Turbulence Modeling for CFD, third edition, DCW Industries, 2006, Chapter 4 (two-equation models, the surface boundary conditions and wall functions)

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)
WritingW2 basic
  • three classic examples