Deep Research

The Continuity Equation: From Continuous to Discrete

Derivation and discretization of the continuity equation, from the integral form through finite-difference formulations.

1. The Integral (Global) Form

Consider a conserved extensive quantity with volume density ρ(x,t)\rho(\mathbf{x}, t) and flux density J(x,t)\mathbf{J}(\mathbf{x}, t). Conservation demands that the rate of change of the total amount inside an arbitrary fixed control volume Ω\Omega equals the net influx through its boundary Ω\partial\Omega:

ddtΩρdV=ΩJn^dA+ΩSdV\frac{d}{dt} \int_\Omega \rho \, dV = -\oint_{\partial\Omega} \mathbf{J} \cdot \hat{\mathbf{n}} \, dA + \int_\Omega S \, dV

where n^\hat{\mathbf{n}} is the outward unit normal and S(x,t)S(\mathbf{x}, t) is a source/sink term. The minus sign reflects the convention that n^\hat{\mathbf{n}} points outward: a positive Jn^\mathbf{J} \cdot \hat{\mathbf{n}} corresponds to an outflow, hence a decrease in the quantity inside Ω\Omega.

2. The Differential (Local) Form

Since Ω\Omega is fixed in space, the time derivative passes under the integral. Applying the divergence theorem to the surface integral:

ΩJn^dA=ΩJdV\oint_{\partial\Omega} \mathbf{J} \cdot \hat{\mathbf{n}} \, dA = \int_\Omega \nabla \cdot \mathbf{J} \, dV

we obtain:

Ω(ρt+JS)dV=0\int_\Omega \left( \frac{\partial \rho}{\partial t} + \nabla \cdot \mathbf{J} - S \right) dV = 0

Since this must hold for every arbitrary volume Ω\Omega, and the integrand is assumed continuous, the integrand itself must vanish pointwise:

ρt+J=S\boxed{\frac{\partial \rho}{\partial t} + \nabla \cdot \mathbf{J} = S}

In the source-free case (S=0S = 0), this reduces to the familiar form:

ρt+J=0\frac{\partial \rho}{\partial t} + \nabla \cdot \mathbf{J} = 0

2.1 Expanded in Cartesian Coordinates

Writing J=(Jx,Jy,Jz)\mathbf{J} = (J_x, J_y, J_z):

ρt+Jxx+Jyy+Jzz=0\frac{\partial \rho}{\partial t} + \frac{\partial J_x}{\partial x} + \frac{\partial J_y}{\partial y} + \frac{\partial J_z}{\partial z} = 0

3. Discretisation on a Uniform Cartesian Grid

We now derive the discrete form in detail. Consider a uniform grid in dd dimensions with spacing Δx\Delta x, Δy\Delta y, Δz\Delta z and time step Δt\Delta t. We label grid points by integer indices (i,j,k)(i, j, k) and time levels by nn:

xi=iΔx,yj=jΔy,zk=kΔz,tn=nΔtx_i = i \, \Delta x, \quad y_j = j \, \Delta y, \quad z_k = k \, \Delta z, \quad t^n = n \, \Delta t

The discrete density at grid point (i,j,k)(i,j,k) and time tnt^n is denoted ρi,j,kn\rho^n_{i,j,k}.

3.1 Finite-Volume Approach (Conservative Discretisation)

The most natural discretisation proceeds from the integral form. Consider the cell Ωi,j,k\Omega_{i,j,k} centred at (xi,yj,zk)(x_i, y_j, z_k) with volume ΔV=ΔxΔyΔz\Delta V = \Delta x \, \Delta y \, \Delta z. Integrating the continuity equation over this cell:

ddtΩi,j,kρdV=Ωi,j,kJn^dA\frac{d}{dt} \int_{\Omega_{i,j,k}} \rho \, dV = -\oint_{\partial \Omega_{i,j,k}} \mathbf{J} \cdot \hat{\mathbf{n}} \, dA

Step 1: Approximate the volume integral. Assuming ρ\rho is approximately uniform over the cell:

Ωi,j,kρdVρi,j,kΔV\int_{\Omega_{i,j,k}} \rho \, dV \approx \rho_{i,j,k} \, \Delta V

Step 2: Approximate the surface integral. The cell has six faces. The flux through each face is approximated by the flux at the face centre times the face area. For the two faces perpendicular to xx:

  • Right face at xi+1/2x_{i+1/2}: area ΔyΔz\Delta y \, \Delta z, outward normal +x^+\hat{\mathbf{x}}, flux contribution +Jxi+1/2,j,kΔyΔz+J_x \big|_{i+1/2,j,k} \, \Delta y \, \Delta z
  • Left face at xi1/2x_{i-1/2}: area ΔyΔz\Delta y \, \Delta z, outward normal x^-\hat{\mathbf{x}}, flux contribution Jxi1/2,j,kΔyΔz-J_x \big|_{i-1/2,j,k} \, \Delta y \, \Delta z

Similarly for yy and zz. The total surface integral becomes:

ΩJn^dA(Jx,i+1/2Jx,i1/2)ΔyΔz+(Jy,j+1/2Jy,j1/2)ΔxΔz+(Jz,k+1/2Jz,k1/2)ΔxΔy\oint_{\partial \Omega} \mathbf{J} \cdot \hat{\mathbf{n}} \, dA \approx \left( J_{x,i+1/2} - J_{x,i-1/2} \right) \Delta y \, \Delta z + \left( J_{y,j+1/2} - J_{y,j-1/2} \right) \Delta x \, \Delta z + \left( J_{z,k+1/2} - J_{z,k-1/2} \right) \Delta x \, \Delta y

where we have suppressed the constant indices for brevity (e.g. Jx,i+1/2Jxi+1/2,j,kJ_{x,i+1/2} \equiv J_x\big|_{i+1/2,j,k}).

Step 3: Approximate the time derivative. Using a forward Euler (explicit) discretisation:

ddt(ρi,j,kΔV)ρi,j,kn+1ρi,j,knΔtΔV\frac{d}{dt}\left(\rho_{i,j,k} \, \Delta V\right) \approx \frac{\rho^{n+1}_{i,j,k} - \rho^n_{i,j,k}}{\Delta t} \, \Delta V

Step 4: Assemble. Dividing through by ΔV\Delta V:

ρi,j,kn+1ρi,j,knΔt+Jx,i+1/2nJx,i1/2nΔx+Jy,j+1/2nJy,j1/2nΔy+Jz,k+1/2nJz,k1/2nΔz=0\boxed{\frac{\rho^{n+1}_{i,j,k} - \rho^n_{i,j,k}}{\Delta t} + \frac{J^n_{x,i+1/2} - J^n_{x,i-1/2}}{\Delta x} + \frac{J^n_{y,j+1/2} - J^n_{y,j-1/2}}{\Delta y} + \frac{J^n_{z,k+1/2} - J^n_{z,k-1/2}}{\Delta z} = 0}

This is the discrete continuity equation in conservative (finite-volume) form.

3.2 Explicit Update Formula

Solving for ρi,j,kn+1\rho^{n+1}_{i,j,k}:

ρi,j,kn+1=ρi,j,knΔt[Jx,i+1/2nJx,i1/2nΔx+Jy,j+1/2nJy,j1/2nΔy+Jz,k+1/2nJz,k1/2nΔz]\rho^{n+1}_{i,j,k} = \rho^n_{i,j,k} - \Delta t \left[ \frac{J^n_{x,i+1/2} - J^n_{x,i-1/2}}{\Delta x} + \frac{J^n_{y,j+1/2} - J^n_{y,j-1/2}}{\Delta y} + \frac{J^n_{z,k+1/2} - J^n_{z,k-1/2}}{\Delta z} \right]

Defining the Courant numbers:

νx=ΔtΔx,νy=ΔtΔy,νz=ΔtΔz\nu_x = \frac{\Delta t}{\Delta x}, \quad \nu_y = \frac{\Delta t}{\Delta y}, \quad \nu_z = \frac{\Delta t}{\Delta z}

the update becomes:

ρi,j,kn+1=ρi,j,knνx(Jx,i+1/2nJx,i1/2n)νy(Jy,j+1/2nJy,j1/2n)νz(Jz,k+1/2nJz,k1/2n)\rho^{n+1}_{i,j,k} = \rho^n_{i,j,k} - \nu_x \left( J^n_{x,i+1/2} - J^n_{x,i-1/2} \right) - \nu_y \left( J^n_{y,j+1/2} - J^n_{y,j-1/2} \right) - \nu_z \left( J^n_{z,k+1/2} - J^n_{z,k-1/2} \right)

3.3 Specifying the Face Fluxes

The discretisation is completed by a prescription for the face fluxes. Several standard choices exist.

3.3.1 Central Differences (Second-Order, Non-Dissipative)

If J=ρv\mathbf{J} = \rho \, \mathbf{v} with a known velocity field v\mathbf{v}, a simple choice is:

Jx,i+1/2=12(ρivx,i+ρi+1vx,i+1)J_{x,i+1/2} = \frac{1}{2}\left(\rho_i v_{x,i} + \rho_{i+1} v_{x,i+1}\right)

This is second-order accurate in space but introduces no numerical dissipation, which can lead to spurious oscillations.

3.3.2 Upwind Scheme (First-Order, Dissipative)

For vx>0v_x > 0:

Jx,i+1/2=ρivx,i+1/2J_{x,i+1/2} = \rho_i \, v_{x,i+1/2}

For vx<0v_x < 0:

Jx,i+1/2=ρi+1vx,i+1/2J_{x,i+1/2} = \rho_{i+1} \, v_{x,i+1/2}

Compactly:

Jx,i+1/2=vx,i+1/2+ρi+vx,i+1/2ρi+1J_{x,i+1/2} = v^+_{x,i+1/2} \, \rho_i + v^-_{x,i+1/2} \, \rho_{i+1}

where v+=max(v,0)v^+ = \max(v, 0) and v=min(v,0)v^- = \min(v, 0).

3.3.3 Lax–Friedrichs Flux

A simple alternative that adds artificial diffusion:

Jx,i+1/2LF=12(Jx,i+Jx,i+1)Δx2Δt(ρi+1ρi)J_{x,i+1/2}^{\text{LF}} = \frac{1}{2}\left(J_{x,i} + J_{x,i+1}\right) - \frac{\Delta x}{2\Delta t}\left(\rho_{i+1} - \rho_i\right)

3.4 One-Dimensional Summary

In 1D with J=ρv\mathbf{J} = \rho \, v and uniform velocity vv, the upwind scheme with forward Euler gives the clean form:

ρin+1=ρinvΔtΔx(ρinρi1n)for v>0\rho^{n+1}_i = \rho^n_i - \frac{v \, \Delta t}{\Delta x} \left( \rho^n_i - \rho^n_{i-1} \right) \quad \text{for } v > 0

which is stable under the CFL condition:

vΔtΔx1\left| \frac{v \, \Delta t}{\Delta x} \right| \leq 1

4. Conservation Property of the Discrete Scheme

A key feature of the finite-volume discretisation is that it is telescoping: summing the update equation over all cells, all internal face fluxes cancel in pairs, leaving only boundary contributions. Explicitly, for a 1D domain with cells i=1,,Ni = 1, \dots, N:

i=1Nρin+1Δx=i=1NρinΔxΔt(JN+1/2J1/2)\sum_{i=1}^{N} \rho^{n+1}_i \, \Delta x = \sum_{i=1}^{N} \rho^n_i \, \Delta x - \Delta t \left( J_{N+1/2} - J_{1/2} \right)

The total discrete "mass" changes only through the boundary fluxes JN+1/2J_{N+1/2} and J1/2J_{1/2}, exactly mirroring the integral conservation law. This is the discrete analogue of conservation and holds regardless of the flux approximation chosen.


5. Higher-Order Time Integration

The forward Euler discretisation is only first-order in time. Higher-order methods can be used while preserving the conservative spatial structure.

Crank–Nicolson (implicit, second-order):

ρin+1ρinΔt+12[(δJxδx)n+(δJxδx)n+1]=0\frac{\rho^{n+1}_i - \rho^n_i}{\Delta t} + \frac{1}{2}\left[\left(\frac{\delta J_x}{\delta x}\right)^n + \left(\frac{\delta J_x}{\delta x}\right)^{n+1}\right] = 0

SSP-RK2 (explicit, second-order, strong-stability preserving):

ρi(1)=ρinΔtL(ρn)i\rho^{(1)}_i = \rho^n_i - \Delta t \, L(\rho^n)_i
ρin+1=12ρin+12[ρi(1)ΔtL(ρ(1))i]\rho^{n+1}_i = \frac{1}{2} \rho^n_i + \frac{1}{2}\left[\rho^{(1)}_i - \Delta t \, L(\rho^{(1)})_i\right]

where L(ρ)iL(\rho)_i denotes the discrete spatial divergence operator evaluated at ρ\rho.


6. Summary Table

| Aspect | Continuous | Discrete (Finite Volume) | |---|---|---| | Domain | ΩRd\Omega \subset \mathbb{R}^d | Grid cells Ωi,j,k\Omega_{i,j,k} | | Density | ρ(x,t)\rho(\mathbf{x}, t) | ρi,j,kn\rho^n_{i,j,k} | | Flux | J(x,t)\mathbf{J}(\mathbf{x}, t) | Jx,i±1/2J_{x,i\pm 1/2}, etc. | | Divergence | J\nabla \cdot \mathbf{J} | Ji+1/2Ji1/2Δx+\frac{J_{i+1/2} - J_{i-1/2}}{\Delta x} + \cdots | | Time derivative | tρ\partial_t \rho | ρn+1ρnΔt\frac{\rho^{n+1} - \rho^n}{\Delta t} | | Conservation | ddtρdV=Jn^dA\frac{d}{dt}\int \rho\,dV = -\oint \mathbf{J}\cdot\hat{\mathbf{n}}\,dA | Telescoping sum: internal fluxes cancel |