Techniqueadvanced
Rhie-Chow interpolation
Also called momentum interpolation.
Interpolates face velocities on a collocated grid with a pressure-gradient correction, which removes checkerboard pressure modes.
Rhie-Chow interpolation, also called momentum interpolation, computes the velocity on the faces of a collocated finite volume grid, where all unknowns sit at the cell centers. Simple linear interpolation of the cell velocities lets a pressure field that alternates from cell to cell, the checkerboard, pass through the continuity equation unseen, because the central pressure difference over two cells does not see it. Rhie and Chow (1983) built the face velocity from the discrete momentum equation instead: the face velocity is the interpolated velocity without its pressure gradient, plus a pressure gradient taken directly across the face. The two gradients differ only for rough pressure fields, so the change is small for smooth flow, but it couples neighboring cells and removes the checkerboard. It made collocated grids practical for SIMPLE type solvers on general meshes, and it is widely used in collocated finite volume codes. A known defect is that the converged result can depend on the under-relaxation factor and the time step; Majumdar (1988) showed how to remove the dependence on under-relaxation.
In plain words
Store the pressure and the velocity at the center of each cell. To know how much fluid passes between two cells you need the velocity on the wall between them. The easy guess is the average of the two neighboring velocities. But each cell velocity was pushed by a pressure difference that skips over the cell itself and compares the cells on both sides. A pressure that goes high, low, high, low then pushes nothing anywhere, and the solver cannot remove it. Rhie and Chow take the average velocity, remove the push that came from the skipping pressure difference, and put back the push from the pressure on the two sides of this very wall. For smooth pressure this changes almost nothing. For the high, low pattern it gives a strong push, so the pattern is removed.
When it applies
- Collocated grids. All variables at cell centers, as on unstructured and curvilinear meshes, where a staggered grid like the MAC grid is hard to build.
- Pressure-based solvers. SIMPLE, PISO and their relatives, which build a pressure or pressure-correction equation from the face mass fluxes.
- Low-order equal-order discretizations. The checkerboard is the finite volume form of the instability that equal-order finite elements show when they fail the inf-sup condition; Rhie-Chow plays the role of a pressure stabilization.
The template
Notation. In the momentum equation of cell , discretized and under-relaxed,
so , where is the central gradient over the two neighbors. For a face between cells and at distance , write for linear interpolation. The Rhie-Chow face velocity is
The second form shows that it is linear interpolation plus a term that compares the compact pressure difference across the face with the interpolated cell gradients. On a uniform grid, for smooth , a Taylor series gives , so the change is of the order . In SIMPLE the face velocities, not the cell velocities, enter continuity, and the pressure correction equation becomes the compact Laplacian.
SIMPLE-ITERATION-WITH-RHIE-CHOW(u, u_f, p)- 1
û_P ← (Σ a_nb u_nb + b_P) / a_P ▷ relaxed momentum without the pressure - 2
u*_P ← û_P - d_P (∇p)_P ▷ cell velocity - 3
u*_f ← avg(û)_f - d_f (p_E - p_P) / h ▷ Rhie-Chow face velocity - 4
solve Σ_f d_f (p'_E - p'_P) / h · A_f = Σ_f u*_f A_f for p' - 5
u_f ← u*_f - d_f (p'_E - p'_P) / h; u ← u* - d (∇p')_P; p ← p + α_p p' - 6
return (u, u_f, p)
Majumdar's correction. With under-relaxation factor , the relaxed coefficients are , so and contains . At a fixed point the cell velocities solve the steady equations for every , but the face velocity is , so its pressure term, and with it the converged pressure, depends on . Adding to in line L3 gives, at the fixed point, , which is free of . The same algebra applies to a transient solver, where contains and contains : the plain formula makes the result depend on , and its smoothing term vanishes as .
Classic examples
The checkerboard by hand. On a periodic 1D grid of width with , let . The central gradient is 0 in every cell, so the cell velocities and linear face velocities do not change, and continuity cannot see this pressure. The compact difference across a face is , so the Rhie-Chow face velocities change by , alternating from face to face, and their divergence is in each cell. The test file checks in exact fractions that on 8 cells the continuity operator of linear interpolation has rank 6 (null space: constants and the checkerboard) and the Rhie-Chow operator has rank 7 (constants only).
Relaxation dependence. The 1D periodic model with , and , solved by SIMPLE with to a tolerance of . The table gives the largest difference between the converged pressure and the one for :
| cells | , plain | , plain | with Majumdar's term |
|---|---|---|---|
| 16 | 2.05e-3 | 5.20e-3 | below 1e-15 |
| 32 | 1.79e-4 | 4.21e-4 | below 1e-15 |
| 64 | 1.15e-5 | 2.69e-5 | below 2e-15 |
The face velocities are equal to 1 (the mean of divided by ) to in every case, and the cell momentum equations hold. The dependence falls with the grid size: here about as , because the viscous term makes grow like , so is of order and the added term of order . These are measurements from the implementation on this page.
Variations
- Majumdar's relaxation-independent form (above), and similar terms that remove the time step dependence in transient solvers.
- Different interpolations of . Linear or harmonic means of and ; on nonuniform and skewed grids the face gradient needs a non-orthogonal correction.
- Body forces and sharp pressure jumps. Buoyancy or surface tension forces at faces must be treated in the same way as the pressure gradient (a balanced force formulation), or spurious velocities appear.
- Other pressure stabilizations. Staggered grids avoid the problem from the start, and in finite elements, stable pairs such as the Taylor-Hood element or pressure stabilized formulations do the same job.
Pitfalls
- Dependence on relaxation and time step. With the plain formula the converged answer changes with and ; the change is of the order of the discretization error, but it means that two runs of the same problem can disagree.
- Small time steps. Since scales like in transient runs, very small steps weaken the smoothing term and checkerboard modes can return.
- Inconsistent . The used in the face velocity must be the one of the pressure correction equation, or mass is not conserved at convergence.
- Forces other than pressure. A body force that is interpolated linearly while the pressure is treated in the Rhie-Chow way breaks the balance between them in hydrostatic or capillary equilibrium.
- Not a cure for everything. It removes the checkerboard of the pressure; it does not fix the velocity checkerboard of central advection at high cell Reynolds number.
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/rhie-chow-interpolation/. The authors are listed in prov/SYEY5V.jsonl.
"""Rhie-Chow momentum interpolation on a periodic 1D collocated grid.
n cells of width h = 1 / n; u[i] and p[i] live at the cell centers, and face i
is between the cells i and i + 1 (indices wrap). The model momentum equation
c u - nu u_xx = s - p_x
is discretized as a_P u_i - a_N (u_{i-1} + u_{i+1}) = s_i - G_i(p) with
a_N = nu / h^2, a_P = c + 2 a_N and the central cell gradient
G_i(p) = (p_{i+1} - p_{i-1}) / (2 h). Continuity says that the face
velocities are equal: (u_f[i] - u_f[i-1]) / h = 0.
simple() runs SIMPLE with momentum under-relaxation alpha and pressure
under-relaxation alpha_p. The face velocity is the Rhie-Chow formula
u_f = avg(uhat) - d_f (p_{i+1} - p_i) / h with uhat = H / a_P and d = 1 / a_P
of the relaxed equation; majumdar=True adds Majumdar's term
(1 - alpha) (u_f_old - avg(u_old)), which makes the fixed point independent of alpha.
"""
from scisparse import cg
def cell_gradient(p, h):
n = len(p)
return [(p[(i + 1) % n] - p[i - 1]) / (2 * h) for i in range(n)]
def avg(x):
"""Linear interpolation of a cell field to the faces."""
n = len(x)
return [(x[i] + x[(i + 1) % n]) / 2 for i in range(n)]
def face_difference(p, h):
n = len(p)
return [(p[(i + 1) % n] - p[i]) / h for i in range(n)]
def face_divergence(uf, h):
return [(uf[i] - uf[i - 1]) / h for i in range(len(uf))]
def linear_continuity_operator(p, h, a):
"""Continuity of linearly interpolated cell velocities: the pressure part, -div(avg(G p / a))."""
return [-x for x in face_divergence(avg([g / a for g in cell_gradient(p, h)]), h)]
def rhie_chow_continuity_operator(p, h, a):
"""Continuity of Rhie-Chow face velocities: the pressure part, -div(d_f dp / h), the compact stencil."""
return [-x for x in face_divergence([g / a for g in face_difference(p, h)], h)]
def _compact_matrix(n, h, d):
w = d / (h * h)
return [{i: 2 * w, (i - 1) % n: -w, (i + 1) % n: -w} for i in range(n)]
def simple(s, c, nu, alpha=0.7, alpha_p=0.3, majumdar=False, tol=1e-12, maxit=20000):
"""Returns (u, uf, p, iterations); p has mean 0."""
n = len(s)
h = 1.0 / n
an = nu / (h * h)
ap = (c + 2 * an) / alpha # relaxed diagonal
d = 1 / ap
A = _compact_matrix(n, h, d)
u = [0.0] * n
uf = [0.0] * n
p = [0.0] * n
for it in range(1, maxit + 1):
G = cell_gradient(p, h)
hh = [an * (u[i - 1] + u[(i + 1) % n]) + s[i] + (1 - alpha) * ap * u[i] for i in range(n)]
uhat = [x / ap for x in hh] # @line L1
ustar = [uhat[i] - d * G[i] for i in range(n)] # @line L2
ufs = [a - d * b for a, b in zip(avg(uhat), face_difference(p, h))] # @line L3
if majumdar:
ufs = [ufs[i] + (1 - alpha) * (uf[i] - au) for i, au in enumerate(avg(u))]
rhs = [-x for x in face_divergence(ufs, h)]
pc, _ = cg(A, rhs, tol=1e-13) # @line L4
mean = sum(pc) / n
pc = [x - mean for x in pc]
Gc = cell_gradient(pc, h)
uf = [a - d * b for a, b in zip(ufs, face_difference(pc, h))] # @line L5
unew = [ustar[i] - d * Gc[i] for i in range(n)]
p = [p[i] + alpha_p * pc[i] for i in range(n)]
change = max(abs(unew[i] - u[i]) for i in range(n))
u = unew
if change < tol and max(map(abs, pc)) < tol:
return u, uf, p, it # @line L6
raise RuntimeError("SIMPLE did not converge")
def momentum_residual(u, p, s, c, nu):
n = len(u)
h = 1.0 / n
an = nu / (h * h)
G = cell_gradient(p, h)
return max(abs((c + 2 * an) * u[i] - an * (u[i - 1] + u[(i + 1) % n]) - s[i] + G[i]) for i in range(n))
scisparse.py 189 lines
# SPDX-License-Identifier: MIT
# Shared helper of the scientific-computing pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Tridiagonal solvers, sparse matrices and simple iterative solvers.
A vector is a list. A sparse matrix is a list of rows, and each row is a
dict that maps a column index to a value. Entries may be int, float or
fractions.Fraction. thomas, thomas_periodic, spmatvec, from_dense and
to_dense keep Fraction entries exact. cg takes square roots and works in
float.
API (fixed; other pages copy this file byte for byte):
thomas(a, b, c, d) solve a tridiagonal system. Row i reads
a[i] x[i-1] + b[i] x[i] + c[i] x[i+1] = d[i];
a[0] and c[n-1] are not used.
thomas_periodic(a, b, c, d) solve a cyclic tridiagonal system: as
thomas, but a[0] multiplies x[n-1] and
c[n-1] multiplies x[0]. Uses the
Sherman-Morrison formula. n >= 3.
from_dense(A) sparse copy of a dense matrix (drops zeros)
to_dense(A, ncols=None) dense copy of a sparse matrix
spmatvec(A, x) A times x
poisson2d(nx, ny, dx, dy, bc="dirichlet")
the matrix of MINUS the 5-point Laplacian
on nx by ny unknowns, numbered
k = i + nx * j (i along x, j along y).
bc = "dirichlet": unknowns at the interior
nodes ((i + 1) dx, (j + 1) dy) with zero
values outside; the matrix is symmetric
positive definite.
bc = "periodic": the grid wraps around in
both directions; the matrix is symmetric
positive semidefinite, and its null space
is the constant vectors.
bc = "neumann": unknowns at cell centers,
zero normal derivative at the walls (a
missing neighbor drops out of the
stencil); null space as for "periodic".
cg(A, b, tol=1e-10, maxit=None, x0=None)
conjugate gradient for a symmetric
positive (semi)definite A. Stops when
||b - A x||_2 <= tol * ||b||_2. Returns
(x, iterations). For a singular A, b must
be in the range of A (for the Poisson
matrices above: sum(b) = 0).
gauss_seidel(A, b, iters, x0=None)
iters forward Gauss-Seidel sweeps; every
row needs a nonzero diagonal entry.
"""
import math
def thomas(a, b, c, d):
n = len(d)
if n == 0:
return []
cp = [0] * n
dp = [0] * n
cp[0] = c[0] / b[0] if n > 1 else 0
dp[0] = d[0] / b[0]
for i in range(1, n):
m = b[i] - a[i] * cp[i - 1]
if i < n - 1:
cp[i] = c[i] / m
dp[i] = (d[i] - a[i] * dp[i - 1]) / m
x = [0] * n
x[n - 1] = dp[n - 1]
for i in range(n - 2, -1, -1):
x[i] = dp[i] - cp[i] * x[i + 1]
return x
def thomas_periodic(a, b, c, d):
"""Cyclic tridiagonal solve. A = T + u v^T with u = (gamma, 0, .., 0, c[n-1])
and v = (1, 0, .., 0, a[0] / gamma), so T is tridiagonal."""
n = len(d)
if n < 3:
raise ValueError("thomas_periodic needs n >= 3")
gamma = -b[0]
bb = list(b)
bb[0] = b[0] - gamma
bb[n - 1] = b[n - 1] - c[n - 1] * a[0] / gamma
y = thomas(a, bb, c, d)
u = [0] * n
u[0] = gamma
u[n - 1] = c[n - 1]
z = thomas(a, bb, c, u)
vy = y[0] + a[0] * y[n - 1] / gamma
vz = z[0] + a[0] * z[n - 1] / gamma
f = vy / (1 + vz)
return [y[i] - f * z[i] for i in range(n)]
def from_dense(A):
return [{j: v for j, v in enumerate(row) if v != 0} for row in A]
def to_dense(A, ncols=None):
if ncols is None:
ncols = len(A)
out = []
for row in A:
r = [0] * ncols
for j, v in row.items():
r[j] = v
out.append(r)
return out
def spmatvec(A, x):
return [sum(v * x[j] for j, v in row.items()) for row in A]
def poisson2d(nx, ny, dx, dy, bc="dirichlet"):
if bc not in ("dirichlet", "periodic", "neumann"):
raise ValueError("bc must be dirichlet, periodic or neumann")
cx = 1 / (dx * dx)
cy = 1 / (dy * dy)
A = []
for j in range(ny):
for i in range(nx):
row = {}
k = i + nx * j
for (ii, jj, w) in ((i - 1, j, cx), (i + 1, j, cx), (i, j - 1, cy), (i, j + 1, cy)):
inside = 0 <= ii < nx and 0 <= jj < ny
if bc == "periodic":
ii %= nx
jj %= ny
inside = True
if bc == "neumann" and not inside:
continue
row[k] = row.get(k, 0) + w
if inside:
m = ii + nx * jj
row[m] = row.get(m, 0) - w
A.append({m: v for m, v in row.items() if v != 0})
return A
def cg(A, b, tol=1e-10, maxit=None, x0=None):
n = len(b)
if maxit is None:
maxit = 10 * n
x = [0.0] * n if x0 is None else [float(v) for v in x0]
if x0 is None:
r = [float(v) for v in b]
else:
ax = spmatvec(A, x)
r = [b[i] - ax[i] for i in range(n)]
bnorm = math.sqrt(sum(float(v) * float(v) for v in b))
stop = tol * bnorm
rr = sum(v * v for v in r)
if math.sqrt(rr) <= stop:
return x, 0
p = list(r)
for it in range(1, maxit + 1):
ap = spmatvec(A, p)
pap = sum(p[i] * ap[i] for i in range(n))
if pap <= 0:
return x, it
alpha = rr / pap
for i in range(n):
x[i] += alpha * p[i]
r[i] -= alpha * ap[i]
rr_new = sum(v * v for v in r)
if math.sqrt(rr_new) <= stop:
return x, it
beta = rr_new / rr
rr = rr_new
p = [r[i] + beta * p[i] for i in range(n)]
return x, maxit
def gauss_seidel(A, b, iters, x0=None):
n = len(b)
x = [0] * n if x0 is None else list(x0)
for _ in range(iters):
for i in range(n):
row = A[i]
s = b[i]
diag = 0
for j, v in row.items():
if j == i:
diag = v
else:
s -= v * x[j]
x[i] = s / diag
return x
test_rhie_chow_interpolation.py 78 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/rhie-chow-interpolation/. The authors are listed in prov/SYEY5V.jsonl.
import math
from fractions import Fraction
from rhie_chow_interpolation import (avg, cell_gradient, face_difference, linear_continuity_operator, momentum_residual,
rhie_chow_continuity_operator, simple)
def _rank(rows):
rows = [list(r) for r in rows]
rank, col, m = 0, 0, len(rows[0])
while rank < len(rows) and col < m:
piv = next((r for r in range(rank, len(rows)) if rows[r][col] != 0), None)
if piv is None:
col += 1
continue
rows[rank], rows[piv] = rows[piv], rows[rank]
for r in range(len(rows)):
if r != rank and rows[r][col] != 0:
f = rows[r][col] / rows[rank][col]
rows[r] = [a - f * b for a, b in zip(rows[r], rows[rank])]
rank += 1
col += 1
return rank
def _matrix(op, n, h, a):
cols = [op([Fraction(int(i == k)) for i in range(n)], h, a) for k in range(n)]
return [[cols[k][i] for k in range(n)] for i in range(n)]
def test_checkerboard_is_invisible_to_linear_interpolation_only():
n, h, a = 8, Fraction(1, 8), Fraction(3)
chk = [Fraction((-1) ** i) for i in range(n)]
assert all(x == 0 for x in cell_gradient(chk, h))
assert all(x == 0 for x in linear_continuity_operator(chk, h, a))
assert rhie_chow_continuity_operator(chk, h, a) == [4 * (-1) ** i / (a * h * h) for i in range(n)]
# null spaces: constants and the checkerboard for linear interpolation, constants only for Rhie-Chow
assert _rank(_matrix(linear_continuity_operator, n, h, a)) == n - 2
assert _rank(_matrix(rhie_chow_continuity_operator, n, h, a)) == n - 1
def test_the_added_term_is_minus_h2_over_4_times_the_third_derivative():
errs = []
for n in (32, 64):
h = 1.0 / n
x = [(i + 0.5) * h for i in range(n)]
p = [math.sin(2 * math.pi * t) for t in x]
diff = [a - b for a, b in zip(face_difference(p, h), avg(cell_gradient(p, h)))]
third = [-(2 * math.pi) ** 3 * math.cos(2 * math.pi * (t + h / 2)) for t in x]
# dp/h - avg(G p) = -(h^2 / 4) p''' at the face + O(h^4)
assert max(abs(d + h * h / 4 * q) for d, q in zip(diff, third)) < h**4 * (2 * math.pi) ** 5 / 4
errs.append(max(map(abs, diff)))
assert 3.9 < errs[0] / errs[1] < 4.1
def _source(n):
return [1 + math.sin(2 * math.pi * (i + 0.5) / n) + 0.5 * math.sin(6 * math.pi * (i + 0.5) / n) for i in range(n)]
def test_simple_fixed_point_solves_the_discrete_equations():
s = _source(16)
u, uf, p, _ = simple(s, 1.0, 0.01, alpha=0.7, alpha_p=0.3)
assert max(uf) - min(uf) < 1e-12 # continuity
assert momentum_residual(u, p, s, 1.0, 0.01) < 1e-9
assert abs(uf[0] - 1) < 1e-9 # the mean of s divided by c
def test_converged_pressure_depends_on_relaxation_unless_majumdar():
s = _source(16)
_, _, p1, _ = simple(s, 1.0, 0.01, alpha=1.0, alpha_p=1.0)
for alpha, lo in ((0.7, 2.0e-3), (0.3, 5.1e-3)): # measured 2.046e-3 and 5.197e-3
_, _, pa, _ = simple(s, 1.0, 0.01, alpha=alpha, alpha_p=0.3)
_, _, pm, _ = simple(s, 1.0, 0.01, alpha=alpha, alpha_p=0.3, majumdar=True)
assert max(abs(a - b) for a, b in zip(pa, p1)) > lo
assert max(abs(a - b) for a, b in zip(pm, p1)) < 1e-12
Exercises
- Show that the central cell gradient of is zero, and that linear interpolation therefore gives a continuity equation with a two-dimensional null space on an even periodic grid.
- Show that on a uniform grid.
- Derive the face velocity at a fixed point of SIMPLE with under-relaxation , and show that Majumdar's term removes .
- For a transient solver with , find how the plain Rhie-Chow face velocity at convergence of one step depends on .
References
- C. M. Rhie and W. L. Chow, Numerical study of the turbulent flow past an airfoil with trailing edge separation, AIAA Journal 21(11) (1983) 1525-1532, the momentum interpolation of face velocities on a nonstaggered grid
- S. Majumdar, Role of underrelaxation in momentum interpolation for calculation of flow with nonstaggered grids, Numerical Heat Transfer 13(1) (1988) 125-132, the dependence of the converged solution on the under-relaxation factor and its removal
- Joel H. Ferziger, Milovan Perić and Robert L. Street, Computational Methods for Fluid Dynamics, 4th edition, Springer, 2020, pressure-velocity coupling on colocated grids
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 SYEY5V Edit this page History Report an error Markdown