Algorithm Search⌘K

Techniqueresearch

Entropy stable schemes

Also called entropy conservative flux.

Schemes whose flux is an entropy conservative flux in Tadmor's sense plus dissipation in the entropy variables, so the discrete solution obeys an entropy inequality for every mesh.

An entropy stable scheme is a conservative scheme for a hyperbolic system ut+f(u)x=0u_t + f(u)_x = 0 that satisfies a discrete form of the entropy inequality U(u)t+q(u)x≤0U(u)_t + q(u)_x \le 0 on every mesh, not only in the limit. The construction, due to Tadmor (1987), has two parts. The first is an entropy conservative two-point flux F∗F^*, defined by the condition (vR−vL)⋅F∗=ψR−ψL(v_R - v_L)\cdot F^* = \psi_R - \psi_L, where v=U′(u)v = U'(u) are the entropy variables and ψ=v⋅f−q\psi = v\cdot f - q is the entropy potential. With F∗F^* the semi-discrete scheme conserves the total entropy exactly. The second part adds dissipation in the entropy variables, F=F∗−12D(vR−vL)F = F^* - \tfrac12 D(v_R - v_L) with DD symmetric positive semidefinite, which makes the total entropy decrease at a known rate. The same idea, with summation-by-parts operators, gives entropy stable DG and spectral element methods of high order.

In plain words

Physical flows with shocks lose a quantity called entropy (in the mathematical sign convention used here) and never gain it. Many good schemes can still gain it in rare cases and then compute a wrong solution or blow up. An entropy stable scheme is built so that this cannot happen. First it uses a special flux between two cells, chosen so that the scheme moves entropy around without creating or destroying any. That flux alone is too clean: at a shock it produces large wiggles, because the entropy has nowhere to go. So a second, small term is added that can only remove entropy, and that is largest where neighbouring cells differ the most. The result is a scheme whose entropy is guaranteed to go down, with a rate you can compute.

When it applies

  • The system has a convex entropy U(u)U(u) with entropy flux q(u)q(u), q′=U′f′q' = U'f'. Most systems from physics have one: the Euler equations (U=−ρs/(γ−1)U = -\rho s/(\gamma - 1) with ss the specific entropy), the shallow water equations (the total energy), MHD and the scalar laws (U=u2/2U = u^2/2 for Burgers).
  • The scheme is in conservation form, so it can be written with face fluxes.
  • You want robustness that does not depend on tuning: under-resolved turbulence, long runs, strong shocks, high order schemes that are unstable because of aliasing.

Entropy stability is a semi-discrete property. A fully discrete scheme keeps it only with an entropy stable time integrator; with explicit Runge-Kutta methods the error in the entropy is O(Δtp)O(\Delta t^{p}) and is usually much smaller than the dissipation.

The template

On a periodic grid with cells CjC_j of width Δx\Delta x and averages uju_j, write vj=U′(uj)v_j = U'(u_j) and ψj=vj⋅f(uj)−q(uj)\psi_j = v_j\cdot f(u_j) - q(u_j).

  1. ENTROPY-STABLE-SCHEME(u, Δx)
  2. 1choose a convex entropy pair (U, q); set v ← U'(u) and ψ ← v·f(u) - q(u)
  3. 2pick an entropy conservative flux F* with (v_R - v_L)·F* = ψ_R - ψ_L
  4. 3F_(j+1/2) ← F*(u_j, u_(j+1)) - ½ D_(j+1/2) (v_(j+1) - v_j), D symmetric, D ≥ 0
  5. 4du_j/dt ← -(F_(j+1/2) - F_(j-1/2)) / Δx; advance in time with an SSP Runge-Kutta method

The key identity is discrete summation by parts. On a periodic grid,

ddt∑jU(uj) Δx=∑jvj⋅dujdt Δx=∑j(vj+1−vj)⋅Fj+1/2.\frac{d}{dt}\sum_j U(u_j)\,\Delta x = \sum_j v_j\cdot\frac{du_j}{dt}\,\Delta x = \sum_j (v_{j+1} - v_j)\cdot F_{j+1/2}.

With F=F∗F = F^* each term is ψj+1−ψj\psi_{j+1} - \psi_j, and the sum telescopes to 00. With the dissipation of L3 the sum is −12∑j(vj+1−vj)TDj+1/2(vj+1−vj)≤0-\tfrac12\sum_j (v_{j+1} - v_j)^{T}D_{j+1/2}(v_{j+1} - v_j) \le 0 (theorem). On a nonperiodic grid the boundary terms remain, and boundary conditions must be chosen so they have the right sign.

Tadmor's path integral gives one entropy conservative flux for any system: F∗=∫01f(u(vL+θ(vR−vL))) dθF^* = \int_0^1 f\big(u(v_L + \theta(v_R - v_L))\big)\,d\theta. It is exact but needs quadrature, so practical schemes use closed forms such as the Ismail-Roe flux for the Euler equations, built from logarithmic means of the density and of ρ/p\rho/p. A common choice for DD is the largest wave speed times the matrix ∂u/∂v\partial u/\partial v, a Rusanov-type dissipation, or a Roe-type matrix R∣Λ∣RTR|\Lambda|R^T with scaled eigenvectors.

Classic examples

  • Godunov's method: its flux is an E-flux, so it is entropy stable, and it can be written as the entropy conservative flux plus a nonnegative dissipation (exercise 2).
  • Burgers' equation: the simplest case, worked out below, with v=uv = u and a quadratic entropy conservative flux.
  • Shallow water equations: the total energy is the entropy, and the entropy conservative flux uses arithmetic means only (exercise 1).
  • Euler equations: the Ismail-Roe flux with logarithmic means, plus matrix dissipation.
  • Discontinuous Galerkin method: flux differencing with a two-point entropy conservative flux on Gauss-Lobatto nodes gives entropy stable DG of any order.

Burgers' equation by hand. For f(u)=u2/2f(u) = u^2/2 take U=u2/2U = u^2/2, so v=uv = u, q=u3/3q = u^3/3 and ψ=u⋅u22−u33=u36\psi = u\cdot\tfrac{u^2}{2} - \tfrac{u^3}{3} = \tfrac{u^3}{6}. The condition (uR−uL)F∗=(uR3−uL3)/6(u_R - u_L)F^* = (u_R^3 - u_L^3)/6 gives

F∗(uL,uR)=uL2+uLuR+uR26,F^*(u_L, u_R) = \frac{u_L^2 + u_Lu_R + u_R^2}{6},

which is also Tadmor's path integral ∫0112(uL+θ(uR−uL))2 dθ\int_0^1 \tfrac12(u_L + \theta(u_R - u_L))^2\,d\theta. For uL=1u_L = 1, uR=0u_R = 0: F∗=16F^* = \tfrac16, and indeed (0−1)⋅16=0−16(0 - 1)\cdot\tfrac16 = \tfrac{0 - 1}{6}. With D=max⁡(∣uL∣,∣uR∣)=1D = \max(|u_L|, |u_R|) = 1 the entropy stable flux is 16+12=23\tfrac16 + \tfrac12 = \tfrac23, and this face removes entropy at the rate 12⋅1⋅12=12\tfrac12\cdot 1\cdot 1^2 = \tfrac12. The arithmetic mean 12(f(uL)+f(uR))=14\tfrac12(f(u_L) + f(u_R)) = \tfrac14 is not entropy conservative: it does not satisfy the condition.

A shock forms (measurement). Burgers with u0=sin⁡2πxu_0 = \sin 2\pi x on [0,1][0, 1], 100 cells, SSP-RK3 with Δt=0.2 Δx\Delta t = 0.2\,\Delta x. A shock forms at t=1/(2π)≈0.16t = 1/(2\pi) \approx 0.16. Total entropy ∑j12uj2 Δx\sum_j \tfrac12 u_j^2\,\Delta x, initially 0.250.25, and the largest ∣uj∣|u_j|:

| tt | EC: entropy | EC: max⁡∣u∣\max|u| | ES: entropy | ES: max⁡∣u∣\max|u| | |---|---|---|---|---| | 0.1 | 0.250000 | 0.9999 | 0.245215 | 0.9813 | | 0.3 | 0.249998 | 1.8220 | 0.170048 | 0.9197 | | 0.5 | 0.249997 | 1.5339 | 0.092046 | 0.7053 |

The entropy conservative scheme keeps the total entropy to about 3×10−63\times 10^{-6}, the error of the time integrator, so after the shock it has no way to lose the entropy the exact solution loses, and it puts that energy into oscillations with values far outside the initial range. The entropy stable scheme decays as the exact solution does and keeps ∣u∣≤1|u| \le 1. Before the shock, at T=0.2T = 0.2 with u0=12+14sin⁡2πxu_0 = \tfrac12 + \tfrac14\sin 2\pi x on 64 cells, the entropy error of the EC scheme with SSP-RK3 is 1.19×10−81.19\times 10^{-8}, 1.49×10−91.49\times 10^{-9} and 1.86×10−101.86\times 10^{-10} for Δt/Δx=0.4,0.2,0.1\Delta t/\Delta x = 0.4, 0.2, 0.1: a factor 8 per halving, third order in Δt\Delta t.

Euler equations. Ismail and Roe (2009) give an entropy conservative flux for the Euler equations in closed form, with the entropy U=−ρs/(γ−1)U = -\rho s/(\gamma - 1). Adding a matrix dissipation built from the eigenvectors of the Jacobian, scaled so that D=R∣Λ∣RTD = R|\Lambda|R^{T} acts on the entropy variables, gives an entropy stable flux that behaves like the Roe flux but has no entropy violating expansion shocks.

Variations

  • TeCNO schemes (Fjordholm, Mishra and Tadmor 2012). High-order entropy conservative fluxes made from linear combinations of two-point fluxes, plus dissipation applied to ENO reconstructions of the scaled entropy variables. The sign property of ENO makes the dissipation entropy stable at any order.
  • Entropy stable DG and spectral element methods. Flux differencing with a two-point entropy conservative flux inside each element, written with summation-by-parts operators on Gauss-Lobatto nodes, gives a discrete entropy inequality for any polynomial degree.
  • Kinetic energy preserving fluxes, which also keep the discrete kinetic energy balance for the Euler equations and are popular in turbulence simulation.
  • Entropy stable time integration. Relaxation Runge-Kutta methods change the step length slightly so that the fully discrete entropy satisfies the inequality too.
  • Entropy fixes such as the Harten-Hyman fix for the Roe flux are a weaker, local remedy: they remove expansion shocks but do not give a global inequality.

Pitfalls

  • Entropy conservative alone at shocks. Without dissipation the scheme oscillates at every shock, as in the table. The EC flux is the base, not the scheme.
  • Dissipation in the wrong variables. The dissipation must act on the jump of vv with a positive semidefinite matrix. Adding −12λ(uR−uL)-\tfrac12\lambda(u_R - u_L) in conserved variables is entropy stable for Burgers, where v=uv = u, but not in general for systems.
  • Path integral by quadrature. A crude quadrature of Tadmor's integral breaks the identity (vR−vL)⋅F∗=ψR−ψL(v_R - v_L)\cdot F^* = \psi_R - \psi_L. Use a closed form, or enough points for the integrand.
  • Logarithmic means near equal states. The Ismail-Roe flux uses (a−b)/(ln⁡a−ln⁡b)(a - b)/(\ln a - \ln b), which loses accuracy when a≈ba \approx b. Use the series expansion there.
  • Entropy stability is not positivity. An entropy stable Euler scheme can still produce negative density or pressure near vacuum, where the entropy variables are not defined. Combine it with a positivity-preserving limiter.
  • Expecting accuracy. Entropy stability is a stability property. It does not make a first-order scheme accurate, and it does not prevent small oscillations of higher order schemes.

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.

entropy_stable_scheme.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/entropy-stable-scheme/. The authors are listed in prov/0A1T0M.jsonl.

"""Entropy conservative and entropy stable finite volume fluxes for Burgers' equation.

Equation u_t + (u^2 / 2)_x = 0 on a periodic grid of M cells. Entropy pair U(u) = u^2 / 2,
q(u) = u^3 / 3, entropy variable v = U'(u) = u, potential psi = v f(u) - q(u) = u^3 / 6.
Tadmor's entropy conservative flux satisfies (v_R - v_L) F* = psi_R - psi_L; adding the
dissipation -(1/2) D (v_R - v_L) with D >= 0 gives an entropy stable flux. Values may be
floats or fractions.Fraction (exact arithmetic for the entropy identities).

Precondition: M >= 2 cells, dx > 0. Cost: Theta(M) per evaluation of the right side.
"""

from typing import Callable, List


def entropy(u):
    """U(u) = u^2 / 2, v(u) = u and psi(u) = u^3 / 6 for Burgers."""
    return u * u / 2, u, u ** 3 / 6                          # @line L1


def ec_flux(ul, ur):
    """Tadmor's entropy conservative flux (ul^2 + ul ur + ur^2) / 6."""
    return (ul * ul + ul * ur + ur * ur) / 6                 # @line L2


def es_flux(ul, ur):
    """Entropy conservative flux plus Rusanov-type dissipation in the entropy variable."""
    d = max(abs(ul), abs(ur))
    return ec_flux(ul, ur) - d * (ur - ul) / 2               # @line L3


def central_flux(ul, ur):
    """Arithmetic mean of f, for comparison (neither entropy conservative nor stable)."""
    return (ul * ul + ur * ur) / 4


def residual(u: List, dx, flux: Callable) -> List:
    """R_j = -(F_{j+1/2} - F_{j-1/2}) / dx on a periodic grid."""
    M = len(u)
    F = [flux(u[j], u[(j + 1) % M]) for j in range(M)]
    return [-(F[j] - F[j - 1]) / dx for j in range(M)]       # @line L4


def entropy_rate(u: List, dx, flux: Callable):
    """d/dt of the total entropy sum_j U(u_j) dx for the semi-discrete scheme."""
    return sum(v * r for v, r in zip(u, residual(u, dx, flux))) * dx


def total_entropy(u: List, dx):
    return sum(x * x / 2 for x in u) * dx


def solve(u: List[float], dx: float, dt: float, T: float, flux: Callable) -> List[float]:
    """SSP-RK3 in time from 0 to T; the last step is shortened."""
    if not dx > 0 or not dt > 0:
        raise ValueError("dx and dt must be positive")
    t = 0.0
    while t < T - 1e-14:
        h = min(dt, T - t)
        a = [x + h * r for x, r in zip(u, residual(u, dx, flux))]
        b = [0.75 * x + 0.25 * (y + h * r) for x, y, r in zip(u, a, residual(a, dx, flux))]
        u = [x / 3 + 2 / 3 * (y + h * r) for x, y, r in zip(u, b, residual(b, dx, flux))]
        t += h
    return u
test_entropy_stable_scheme.py 101 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/entropy-stable-scheme/. The authors are listed in prov/0A1T0M.jsonl.

import math
import random
from fractions import Fraction as Fr

import pytest

from entropy_stable_scheme import (
    central_flux, ec_flux, entropy, entropy_rate, es_flux, residual, solve, total_entropy,
)


def rand_fr(rng):
    return Fr(rng.randint(-40, 40), rng.randint(1, 12))


def test_tadmor_condition_holds_exactly():
    rng = random.Random(1)
    for _ in range(200):
        ul, ur = rand_fr(rng), rand_fr(rng)
        _, vl, pl = entropy(ul)
        _, vr, pr = entropy(ur)
        assert (vr - vl) * ec_flux(ul, ur) == pr - pl


def test_ec_flux_is_tadmors_path_integral():
    # F* = integral over theta in [0, 1] of f(u(v_L + theta (v_R - v_L))); Simpson is exact here.
    rng = random.Random(2)
    f = lambda u: u * u / 2
    for _ in range(50):
        ul, ur = rand_fr(rng), rand_fr(rng)
        mid = (ul + ur) / 2
        simpson = (f(ul) + 4 * f(mid) + f(ur)) / 6
        assert ec_flux(ul, ur) == simpson


def test_fluxes_are_consistent():
    for u in (Fr(-3, 2), Fr(0), Fr(7, 5)):
        assert ec_flux(u, u) == u * u / 2
        assert es_flux(u, u) == u * u / 2


def test_hand_example():
    assert ec_flux(Fr(1), Fr(0)) == Fr(1, 6)
    assert es_flux(Fr(1), Fr(0)) == Fr(2, 3)


def test_semi_discrete_entropy_rate_is_exactly_zero_for_the_ec_flux():
    rng = random.Random(3)
    for M in (2, 5, 17):
        u = [rand_fr(rng) for _ in range(M)]
        assert entropy_rate(u, Fr(1, M), ec_flux) == 0
        assert sum(residual(u, Fr(1, M), ec_flux)) == 0          # conservation


def test_semi_discrete_entropy_rate_of_the_es_flux_is_the_dissipation():
    rng = random.Random(4)
    for M in (3, 8, 20):
        u = [rand_fr(rng) for _ in range(M)]
        dx = Fr(1, M)
        diss = -sum(max(abs(u[j]), abs(u[(j + 1) % M])) * (u[(j + 1) % M] - u[j]) ** 2
                    for j in range(M)) / 2
        rate = entropy_rate(u, dx, es_flux)
        assert rate == diss
        assert rate <= 0


def test_central_flux_is_not_entropy_conservative():
    u = [Fr(1), Fr(0), Fr(-1), Fr(2)]
    assert entropy_rate(u, Fr(1, 4), central_flux) != 0


def test_fully_discrete_ec_entropy_drift_is_small_and_shrinks_with_dt():
    M = 64
    dx = 1.0 / M
    u0 = [0.5 + 0.25 * math.sin(2 * math.pi * (j + 0.5) * dx) for j in range(M)]
    s0 = total_entropy(u0, dx)
    drift = []
    for c in (0.4, 0.2):
        u = solve(list(u0), dx, c * dx, 0.2, ec_flux)
        drift.append(abs(total_entropy(u, dx) - s0))
    assert drift[0] < 1e-6 and drift[1] < drift[0] / 4


def test_es_scheme_captures_a_shock_without_new_extrema_but_ec_oscillates():
    M = 100
    dx = 1.0 / M
    u0 = [math.sin(2 * math.pi * (j + 0.5) * dx) for j in range(M)]
    es = solve(list(u0), dx, 0.2 * dx, 0.3, es_flux)
    ec = solve(list(u0), dx, 0.2 * dx, 0.3, ec_flux)
    assert max(abs(x) for x in es) <= 1.0
    assert total_entropy(es, dx) < total_entropy(u0, dx) - 0.05
    assert max(abs(x) for x in ec) > 1.5
    assert abs(total_entropy(ec, dx) - total_entropy(u0, dx)) < 1e-4


def test_rejects_bad_steps():
    with pytest.raises(ValueError):
        solve([0.0, 1.0], 0.5, 0.0, 1.0, es_flux)

Exercises

  1. For the shallow water equations with entropy U=12hu2+12gh2U = \tfrac12 hu^2 + \tfrac12 gh^2, compute vv and ψ\psi and check that F∗=(hˉuˉ, hˉuˉ2+g2h2‾)F^* = \big(\bar h\bar u,\ \bar h\bar u^2 + \tfrac{g}{2}\overline{h^2}\big), with bars for arithmetic means of the two states, is entropy conservative.
  2. Show that for a scalar law with U=u2/2U = u^2/2 every flux of the form F=F∗−12d (uR−uL)F = F^* - \tfrac12 d\,(u_R - u_L) with d≥0d \ge 0 is entropy stable, and that Godunov's flux for Burgers is of this form with d≥0d \ge 0.
  3. Prove that the semi-discrete entropy conservative scheme on a periodic grid also conserves ∑juj Δx\sum_j u_j\,\Delta x, and explain why both conservation laws together force oscillations after a shock forms.

References

  1. Eitan Tadmor, The numerical viscosity of entropy stable schemes for systems of conservation laws. I, Mathematics of Computation 49(179) (1987) 91-103, entropy conservative fluxes, the comparison of numerical viscosities, entropy stability of three-point schemes
  2. Eitan Tadmor, Entropy stability theory for difference approximations of nonlinear conservation laws and related time-dependent problems, Acta Numerica 12 (2003) 451-512, the survey of the theory, entropy variables, the path integral form of the entropy conservative flux
  3. Ulrik S. Fjordholm, Siddhartha Mishra and Eitan Tadmor, Arbitrarily high-order accurate entropy stable essentially nonoscillatory schemes for systems of conservation laws, SIAM Journal on Numerical Analysis 50(2) (2012) 544-573, high-order entropy conservative fluxes, the sign property of ENO reconstruction, the TeCNO schemes
  4. Farzad Ismail and Philip L. Roe, Affordable, entropy-consistent Euler flux functions II: entropy production at shocks, Journal of Computational Physics 228(15) (2009) 5410-5436, an entropy conservative flux for the Euler equations in closed form, with logarithmic means

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)
WritingW3 standard
  • five exercises