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 , , with , the kinematic viscosity (m^2/s) and the wall shear stress (Pa). The usual range for the first point is ; 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 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 (exact as ). The log layer has
The form of the log law follows from matching arguments and from the mixing length model; and are measured. The two laws cross at with , which is for and .
Friction velocity from the first point. Given the tangential velocity at distance , solve for . On the log branch is increasing and convex, so Newton's method started from the laminar value converges after one overshoot.
WALL-FUNCTION(U_P, y_P, ν, κ, B)- 1
y_c ← root of y = ln(y)/κ + B - 2
u ← sqrt(ν U_P / y_P) (laminar value) - 3
if y_P u / ν ≤ y_c: return u (first point in the sublayer) - 4
repeat - 5
s ← ln(y_P u / ν)/κ + B; f ← u s - U_P - 6
u ← u - f / (s + 1/κ) - 7
until |f| ≤ tol · U_P - 8
return u_τ = u, τ_w = ρ u^2
Use in the solver.
- Apply as the shear force on the wall face of the first cell, in place of from the grid, which would be far too small.
- For the k-epsilon model: set zero flux of through the wall, use the wall-function stress in the production term of the first cell, and fix . In equilibrium .
- For the k-omega model: fix .
- Recompute every outer iteration of the flow solver, since changes.
Launder-Spalding form. Launder and Spalding take the velocity scale from instead: , , and
This needs no iteration, and stays positive at separation and reattachment points where and go to zero. In equilibrium and the two forms agree exactly, which the tests check.
Classic examples
Air over a plate (by hand). Take m^2/s, kg/m^3, m/s at mm, with and . The Newton iterates are:
| step | (m/s) | (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 m/s, (inside the 30 to 300 range), m^2/s^2 and Pa. Check: and . The wall values for k-epsilon are m^2/s^2 and 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
gives as an increasing function of that is in the sublayer and tends to the log law far out, with a smooth buffer layer between. With and : , (the two-law value is 11.00 from the linear law, since ; the log law alone gives 11.05), and against the log law's 19.11. Inverting it by bisection gives a wall function valid at any .
Variations
- Scalable wall functions. Use in place of , 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 and , or use Spalding's law, so the same boundary condition works for any . SST codes often do this.
- Rough walls. Lower by a function 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 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 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 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 the log law gives and , while the real turbulence there is not small. The Launder-Spalding form with from avoids the zero but not the error.
- Wrong production in the first cell. Computing from the grid velocity gradient in the first cell, instead of from and the log-law gradient , gives too little there.
- Using to choose the grid before the solution exists. Estimate from a skin-friction correlation, then check 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.
# 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
- Water ( m^2/s) has m/s. Where must the first cell center be to lie at ? (Answer: mm.)
- For and , show that is where the linear law and the log law meet. (Answer: .)
- Show that the Launder-Spalding stress equals when and follows the log law. (Answer: then , , and .)
References
- 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)
- 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
- 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)
- 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.
| 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 | W2 basic |
|
Tag 7MSEKR Edit this page History Report an error Markdown