Modelcore
Smagorinsky model
Also called Smagorinsky subgrid model.
A subgrid eddy viscosity equal to (C_s Delta)^2 times the magnitude of the resolved strain rate tensor.
The Smagorinsky model is a subgrid-scale closure for large eddy simulation that sets the eddy viscosity of the unresolved scales to , where is the filter width, is the magnitude of the resolved strain rate and is a constant. It is a mixing length model for the subgrid scales, with the length set by the grid instead of the wall distance. The Kolmogorov 1941 theory gives Lilly's estimate ; shear flows need about 0.1, and the dynamic subgrid model computes the coefficient from the resolved field instead. As shrinks toward the Kolmogorov scale, the model fades and LES approaches direct numerical simulation.
The machine
Unknowns. The filtered velocity and pressure of the LES equations, on a grid with filter width (m). The subgrid stress is .
Closure. With the resolved strain rate (1/s),
The trace is absorbed into the filtered pressure. This is the Boussinesq form with the velocity scale and length scale .
Parameters.
- . Lilly's estimate from the K41 spectrum is , about 0.17 for (derived below, given the measured Kolmogorov constant ). In practice it is fitted: about 0.1 in channel flow and other shear flows, after Deardorff.
- . A choice tied to the grid, usually the cell size or on anisotropic grids.
- Near walls, is often multiplied by a van Driest factor with , a rule borrowed from the mixing length model.
Procedure on a periodic 2D grid. With central differences of second order,
SMAGORINSKY-2D(u, v, Δx, Δy, C_s, Δ)- 1
for each grid point (i, j), indices taken modulo the grid size: - 2
S11 ← (u[i+1,j] - u[i-1,j]) / (2Δx); S22 ← (v[i,j+1] - v[i,j-1]) / (2Δy) - 3
S12 ← ((u[i,j+1] - u[i,j-1]) / (2Δy) + (v[i+1,j] - v[i-1,j]) / (2Δx)) / 2 - 4
|S| ← sqrt(2 (S11^2 + S22^2 + 2 S12^2)) - 5
ν_r[i,j] ← (C_s Δ)^2 |S| - 6
return ν_r
Lines L2 and L3 are finite differences with error , and L4 counts and once each. The cost is a constant number of operations per point, for points in the real RAM. In 3D the same lines run over the nine velocity derivatives.
What it counts
The model gives the subgrid eddy viscosity , the modeled subgrid stress, and the subgrid dissipation : the rate at which resolved kinetic energy is drained into the unresolved scales. Inside an LES it fixes the resolved field, and with it every statistic the LES reports.
Relation to other models
- Mixing length. It is Prandtl's mixing length model with and replaced by ; in a pure shear , and the two have the same form.
- Dynamic model. The dynamic model keeps the form and computes in space and time from a second, coarser test filter. It removes the need to fit and lets the viscosity vanish in laminar regions and near walls.
- RANS models. RANS eddy viscosities such as the k-epsilon model model all of the turbulence and are far larger; the Smagorinsky viscosity models only the part below the grid scale and goes to zero as .
- Other subgrid models. Scale-similarity and mixed models, and models designed to vanish in pure shear and near walls, are the main alternatives in LES.
Known results in the model
Lilly's constant (derived under stated assumptions). Assume a sharp spectral cutoff at inside an inertial range with , and replace by . The resolved strain is . Setting the mean model dissipation equal to gives
For , , its 3/4 power is 0.5443, and ; for , . The tests check both. The value depends on the filter and on the approximation of the third moment, so it is an estimate.
No backscatter (theorem in the model). at every point, because . Energy can only go from the resolved scales to the subgrid ones. Filtered DNS data show local backscatter, energy going the other way in parts of the flow, which the model cannot represent (measurement).
Strain cases by hand. A pure shear has . A plane strain , has . A solid-body rotation has , so . In SI units, with cm, 1/s and , m^2/s, about three times the viscosity of air.
Taylor-Green field (exact, checked by the tests). For , on , and , so . A central difference of on spacing gives exactly times , so on a uniform grid the computed is exactly times the true one. With 32 points, and . At with and , in the units of the box.
Known defects (measurement and theorem). In a laminar shear flow the model gives , so it damps disturbances that should grow in transition. At a wall is largest while the true subgrid stress goes to zero, so without damping it gives too much viscosity there. Point by point, the modeled stress correlates poorly with the exact one in filtered DNS data, even when the mean dissipation is right. The best fitted differs from flow to flow: near 0.17 to 0.2 in isotropic turbulence and near 0.1 in channel flow.
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/smagorinsky-model/. The authors are listed in prov/XS6424.jsonl.
"""Smagorinsky subgrid eddy viscosity nu_t = (C_s Delta)^2 |S| on a periodic
2D grid with central differences, a pointwise version from a velocity
gradient, and Lilly's estimate of C_s from the Kolmogorov constant.
Fields are lists of rows: u[i][j] is the value at x = i dx, y = j dy.
"""
import math
from typing import Sequence
Grid = list[list[float]]
def lilly_constant(c_k: float = 1.5) -> float:
"""C_s = (1/pi) (2 / (3 C_K))^(3/4), from matching the dissipation to a k^(-5/3) spectrum."""
return (2.0 / (3.0 * c_k)) ** 0.75 / math.pi
def strain_magnitude_from_gradient(grad: Sequence[Sequence[float]]) -> float:
"""|S| = sqrt(2 S_ij S_ij) for a velocity gradient grad[i][j] = du_i/dx_j in 2D or 3D."""
d = len(grad)
total = 0.0
for i in range(d):
for j in range(d):
s = 0.5 * (grad[i][j] + grad[j][i])
total += s * s
return math.sqrt(2.0 * total)
def eddy_viscosity_from_gradient(grad: Sequence[Sequence[float]], cs: float, delta: float) -> float:
"""nu_t = (C_s Delta)^2 |S| at one point."""
return (cs * delta) ** 2 * strain_magnitude_from_gradient(grad)
def strain_rate_2d(u: Grid, v: Grid, dx: float, dy: float) -> tuple[Grid, Grid, Grid]:
"""S11, S22, S12 by periodic second-order central differences."""
nx, ny = len(u), len(u[0])
s11 = [[0.0] * ny for _ in range(nx)]
s22 = [[0.0] * ny for _ in range(nx)]
s12 = [[0.0] * ny for _ in range(nx)]
for i in range(nx): # @line L1
ip, im = (i + 1) % nx, (i - 1) % nx
for j in range(ny): # @line L1
jp, jm = (j + 1) % ny, (j - 1) % ny
s11[i][j] = (u[ip][j] - u[im][j]) / (2 * dx) # @line L2
s22[i][j] = (v[i][jp] - v[i][jm]) / (2 * dy) # @line L2
dudy = (u[i][jp] - u[i][jm]) / (2 * dy) # @line L3
dvdx = (v[ip][j] - v[im][j]) / (2 * dx) # @line L3
s12[i][j] = 0.5 * (dudy + dvdx) # @line L3
return s11, s22, s12
def smagorinsky_2d(u: Grid, v: Grid, dx: float, dy: float, cs: float, delta: float) -> tuple[Grid, Grid]:
"""Return (nu_t, |S|) on the grid."""
s11, s22, s12 = strain_rate_2d(u, v, dx, dy)
c = (cs * delta) ** 2
nx, ny = len(u), len(u[0])
mag = [[0.0] * ny for _ in range(nx)]
nut = [[0.0] * ny for _ in range(nx)]
for i in range(nx):
for j in range(ny):
m = math.sqrt(2.0 * (s11[i][j] ** 2 + s22[i][j] ** 2 + 2.0 * s12[i][j] ** 2)) # @line L4
mag[i][j] = m
nut[i][j] = c * m # @line L5
return nut, mag # @line L6
def dissipation_2d(u: Grid, v: Grid, dx: float, dy: float, cs: float, delta: float) -> Grid:
"""Subgrid dissipation nu_t |S|^2 = 2 nu_t S_ij S_ij at each point."""
nut, mag = smagorinsky_2d(u, v, dx, dy, cs, delta)
return [[nut[i][j] * mag[i][j] ** 2 for j in range(len(u[0]))] for i in range(len(u))]
def taylor_green(n: int) -> tuple[Grid, Grid, float]:
"""u = -cos x sin y, v = sin x cos y on an n x n grid over [0, 2 pi)^2; returns (u, v, h)."""
h = 2 * math.pi / n
u = [[-math.cos(i * h) * math.sin(j * h) for j in range(n)] for i in range(n)]
v = [[math.sin(i * h) * math.cos(j * h) for j in range(n)] for i in range(n)]
return u, v, h
test_smagorinsky_model.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/smagorinsky-model/. The authors are listed in prov/XS6424.jsonl.
import math
import random
import pytest
from smagorinsky_model import (
dissipation_2d,
eddy_viscosity_from_gradient,
lilly_constant,
smagorinsky_2d,
strain_magnitude_from_gradient,
taylor_green,
)
def test_lilly_constant():
assert lilly_constant(1.5) == pytest.approx(0.17327, abs=1e-5)
assert lilly_constant(1.6) == pytest.approx(0.16508, abs=1e-5)
def test_pointwise_cases():
# pure shear dU/dy = g gives |S| = g
assert strain_magnitude_from_gradient([[0.0, 3.0], [0.0, 0.0]]) == pytest.approx(3.0)
# solid-body rotation has no strain
assert strain_magnitude_from_gradient([[0.0, -2.0], [2.0, 0.0]]) == 0.0
# plane strain du/dx = a, dv/dy = -a gives |S| = 2a
assert strain_magnitude_from_gradient([[1.5, 0.0], [0.0, -1.5]]) == pytest.approx(3.0)
# SI example: Delta = 1 cm, |S| = 50 1/s, C_s = 0.1
assert eddy_viscosity_from_gradient([[0.0, 50.0], [0.0, 0.0]], 0.1, 0.01) == pytest.approx(5e-5)
# 3D gradient: rotation about z plus shear in x-z
g = [[0.0, -1.0, 4.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
assert strain_magnitude_from_gradient(g) == pytest.approx(4.0)
def test_taylor_green_exact_discrete_factor():
n = 32
u, v, h = taylor_green(n)
cs = 0.17
nut, mag = smagorinsky_2d(u, v, h, h, cs, h)
factor = math.sin(h) / h
assert factor == pytest.approx(0.993587, abs=1e-6)
for i in range(n):
for j in range(n):
exact = 2 * abs(math.sin(i * h) * math.sin(j * h))
assert mag[i][j] == pytest.approx(factor * exact, abs=1e-12)
# at x = y = pi/2 (i = j = 8)
assert nut[8][8] == pytest.approx((cs * h) ** 2 * 2 * factor, rel=1e-12)
assert nut[8][8] == pytest.approx(2.2141e-3, abs=1e-7)
def test_second_order_convergence():
errs = []
for n in (16, 32, 64):
u, v, h = taylor_green(n)
_, mag = smagorinsky_2d(u, v, h, h, 0.17, 1.0)
i = j = n // 4
errs.append(abs(mag[i][j] - 2.0))
for a, b in zip(errs, errs[1:]):
assert math.log2(a / b) == pytest.approx(2.0, abs=0.05)
def random_field(n, rng):
h = 2 * math.pi / n
u = [[0.0] * n for _ in range(n)]
v = [[0.0] * n for _ in range(n)]
for _ in range(6):
kx, ky = rng.randint(1, 4), rng.randint(1, 4)
a, ph = rng.uniform(-1, 1), rng.uniform(0, 2 * math.pi)
# stream function a sin(kx x + ky y + ph) gives a divergence-free field
for i in range(n):
for j in range(n):
c = a * math.cos(kx * i * h + ky * j * h + ph)
u[i][j] += ky * c
v[i][j] -= kx * c
return u, v, h
def test_nonnegative_and_galilean_invariant():
rng = random.Random(2024)
u, v, h = random_field(24, rng)
diss = dissipation_2d(u, v, h, h, 0.17, h)
assert min(min(row) for row in diss) >= 0.0
nut, _ = smagorinsky_2d(u, v, h, h, 0.17, h)
shifted = [[x + 3.7 for x in row] for row in u]
nut2, _ = smagorinsky_2d(shifted, v, h, h, 0.17, h)
for a, b in zip(nut, nut2):
for x, y in zip(a, b):
assert x == pytest.approx(y, abs=1e-12)
References
- J. Smagorinsky, General circulation experiments with the primitive equations, I. The basic experiment, Monthly Weather Review 91(3), 1963, 99-164, the lateral eddy viscosity proportional to the square of the grid size times the magnitude of the deformation
- D. K. Lilly, The representation of small-scale turbulence in numerical simulation experiments, Proceedings of the IBM Scientific Computing Symposium on Environmental Sciences, Yorktown Heights, 1966, IBM Form 320-1951, 1967, 195-210, the estimate of the constant from the inertial range spectrum
- James W. Deardorff, A numerical study of three-dimensional turbulent channel flow at large Reynolds numbers, Journal of Fluid Mechanics 41(2), 1970, 453-480, the model in channel flow and the smaller value of the constant needed there
- Stephen B. Pope, Turbulent Flows, Cambridge University Press, 2000, Section 13.4 (the Smagorinsky model, 13.4.2 the behavior in the inertial subrange, 13.4.5 near-wall resolution)
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 XS6424 Edit this page History Report an error Markdown