Algorithm Search⌘K

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 νr=(CsΔ)2∣Sˉ∣\nu_r = (C_s\Delta)^2|\bar S|, where Δ\Delta is the filter width, ∣Sˉ∣|\bar S| is the magnitude of the resolved strain rate and CsC_s 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 Cs≈0.17C_s \approx 0.17; shear flows need about 0.1, and the dynamic subgrid model computes the coefficient from the resolved field instead. As Δ\Delta shrinks toward the Kolmogorov scale, the model fades and LES approaches direct numerical simulation.

The machine

Unknowns. The filtered velocity uˉi\bar u_i and pressure pˉ\bar p of the LES equations, on a grid with filter width Δ\Delta (m). The subgrid stress is τij=uiuj‾−uˉiuˉj\tau_{ij} = \overline{u_i u_j} - \bar u_i\bar u_j.

Closure. With the resolved strain rate Sˉij=12(∂uˉi/∂xj+∂uˉj/∂xi)\bar S_{ij} = \frac{1}{2}(\partial\bar u_i/\partial x_j + \partial\bar u_j/\partial x_i) (1/s),

τij−13τkkδij=−2νrSˉij,νr=(CsΔ)2∣Sˉ∣,∣Sˉ∣=2SˉijSˉij.\tau_{ij} - \frac{1}{3}\tau_{kk}\delta_{ij} = -2\nu_r\bar S_{ij}, \qquad \nu_r = (C_s\Delta)^2|\bar S|, \qquad |\bar S| = \sqrt{2\bar S_{ij}\bar S_{ij}}.

The trace τkk\tau_{kk} is absorbed into the filtered pressure. This is the Boussinesq form with the velocity scale CsΔ∣Sˉ∣C_s\Delta|\bar S| and length scale CsΔC_s\Delta.

Parameters.

  • CsC_s. Lilly's estimate from the K41 spectrum is Cs=1π(23CK)3/4C_s = \frac{1}{\pi}\left(\frac{2}{3C_K}\right)^{3/4}, about 0.17 for CK=1.5C_K = 1.5 (derived below, given the measured Kolmogorov constant CKC_K). In practice it is fitted: about 0.1 in channel flow and other shear flows, after Deardorff.
  • Δ\Delta. A choice tied to the grid, usually the cell size or (Δx Δy Δz)1/3(\Delta x\,\Delta y\,\Delta z)^{1/3} on anisotropic grids.
  • Near walls, CsΔC_s\Delta is often multiplied by a van Driest factor 1−e−y+/A+1 - e^{-y^+/A^+} with A+≈26A^+ \approx 26, a rule borrowed from the mixing length model.

Procedure on a periodic 2D grid. With central differences of second order,

  1. SMAGORINSKY-2D(u, v, Δx, Δy, C_s, Δ)
  2. 1for each grid point (i, j), indices taken modulo the grid size:
  3. 2S11 ← (u[i+1,j] - u[i-1,j]) / (2Δx); S22 ← (v[i,j+1] - v[i,j-1]) / (2Δy)
  4. 3S12 ← ((u[i,j+1] - u[i,j-1]) / (2Δy) + (v[i+1,j] - v[i-1,j]) / (2Δx)) / 2
  5. 4|S| ← sqrt(2 (S11^2 + S22^2 + 2 S12^2))
  6. 5ν_r[i,j] ← (C_s Δ)^2 |S|
  7. 6return ν_r

Lines L2 and L3 are finite differences with error O(Δx2)O(\Delta x^2), and L4 counts S12S_{12} and S21S_{21} once each. The cost is a constant number of operations per point, O(N)O(N) for NN 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 νr\nu_r, the modeled subgrid stress, and the subgrid dissipation εsgs=−τijSˉij=νr∣Sˉ∣2\varepsilon_{sgs} = -\tau_{ij}\bar S_{ij} = \nu_r|\bar S|^2: 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 ℓ=CsΔ\ell = C_s\Delta and ∣dU/dy∣|dU/dy| replaced by ∣Sˉ∣|\bar S|; in a pure shear dU/dydU/dy, ∣Sˉ∣=∣dU/dy∣|\bar S| = |dU/dy| and the two have the same form.
  • Dynamic model. The dynamic model keeps the form and computes (Cs)2(C_s)^2 in space and time from a second, coarser test filter. It removes the need to fit CsC_s 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 Δ→0\Delta \to 0.
  • 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 kc=π/Δk_c = \pi/\Delta inside an inertial range with E(k)=CKε2/3k−5/3E(k) = C_K\varepsilon^{2/3}k^{-5/3}, and replace ⟨∣Sˉ∣3⟩\langle|\bar S|^3\rangle by ⟨∣Sˉ∣2⟩3/2\langle|\bar S|^2\rangle^{3/2}. The resolved strain is ⟨∣Sˉ∣2⟩=2∫0kck2E(k) dk=32CKε2/3kc4/3\langle|\bar S|^2\rangle = 2\int_0^{k_c}k^2E(k)\,dk = \frac{3}{2}C_K\varepsilon^{2/3}k_c^{4/3}. Setting the mean model dissipation equal to ε\varepsilon gives

ε=(CsΔ)2(32CK)3/2ε kc2⟹Cs=1π(23CK)3/4.\varepsilon = (C_s\Delta)^2\left(\tfrac{3}{2}C_K\right)^{3/2}\varepsilon\, k_c^2 \quad\Longrightarrow\quad C_s = \frac{1}{\pi}\left(\frac{2}{3C_K}\right)^{3/4}.

For CK=1.5C_K = 1.5, 2/(3×1.5)=0.44442/(3 \times 1.5) = 0.4444, its 3/4 power is 0.5443, and Cs=0.173C_s = 0.173; for CK=1.6C_K = 1.6, Cs=0.165C_s = 0.165. 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). εsgs=νr∣Sˉ∣2≥0\varepsilon_{sgs} = \nu_r|\bar S|^2 \ge 0 at every point, because νr≥0\nu_r \ge 0. 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 ∂uˉ/∂y=γ\partial\bar u/\partial y = \gamma has ∣Sˉ∣=γ|\bar S| = \gamma. A plane strain ∂uˉ/∂x=a\partial\bar u/\partial x = a, ∂vˉ/∂y=−a\partial\bar v/\partial y = -a has ∣Sˉ∣=2a|\bar S| = 2a. A solid-body rotation has Sˉij=0\bar S_{ij} = 0, so νr=0\nu_r = 0. In SI units, with Δ=1\Delta = 1 cm, ∣Sˉ∣=50|\bar S| = 50 1/s and Cs=0.1C_s = 0.1, νr=(0.001)2×50=5×10−5\nu_r = (0.001)^2 \times 50 = 5 \times 10^{-5} m^2/s, about three times the viscosity of air.

Taylor-Green field (exact, checked by the tests). For u=−cos⁡xsin⁡yu = -\cos x\sin y, v=sin⁡xcos⁡yv = \sin x\cos y on [0,2π)2[0, 2\pi)^2, Sˉ11=sin⁡xsin⁡y=−Sˉ22\bar S_{11} = \sin x\sin y = -\bar S_{22} and Sˉ12=0\bar S_{12} = 0, so ∣Sˉ∣=2∣sin⁡xsin⁡y∣|\bar S| = 2|\sin x\sin y|. A central difference of sin⁡\sin on spacing hh gives exactly cos⁡\cos times sin⁡(h)/h\sin(h)/h, so on a uniform grid the computed ∣Sˉ∣|\bar S| is exactly sin⁡hh\frac{\sin h}{h} times the true one. With 32 points, h=0.19635h = 0.19635 and sin⁡(h)/h=0.993587\sin(h)/h = 0.993587. At x=y=π/2x = y = \pi/2 with Cs=0.17C_s = 0.17 and Δ=h\Delta = h, νr=(0.17×0.19635)2×2×0.993587=2.214×10−3\nu_r = (0.17 \times 0.19635)^2 \times 2 \times 0.993587 = 2.214 \times 10^{-3} in the units of the box.

Known defects (measurement and theorem). In a laminar shear flow the model gives νr=(CsΔ)2γ>0\nu_r = (C_s\Delta)^2\gamma > 0, so it damps disturbances that should grow in transition. At a wall ∣Sˉ∣|\bar S| 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 CsC_s 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.

smagorinsky_model.pyI0RawGitHub
# 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

  1. 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
  2. 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
  3. 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
  4. 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.

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/XS6424/text.yaml