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) and flux density J(x,t). Conservation demands that the rate of change of the total amount inside an arbitrary fixed control volume Ω equals the net influx through its boundary ∂Ω:
dtd∫ΩρdV=−∮∂ΩJ⋅n^dA+∫ΩSdV
where n^ is the outward unit normal and S(x,t) is a source/sink term. The minus sign reflects the convention that n^ points outward: a positive J⋅n^ corresponds to an outflow, hence a decrease in the quantity inside Ω.
2. The Differential (Local) Form
Since Ω is fixed in space, the time derivative passes under the integral. Applying the divergence theorem to the surface integral:
∮∂ΩJ⋅n^dA=∫Ω∇⋅JdV
we obtain:
∫Ω(∂t∂ρ+∇⋅J−S)dV=0
Since this must hold for every arbitrary volume Ω, and the integrand is assumed continuous, the integrand itself must vanish pointwise:
∂t∂ρ+∇⋅J=S
In the source-free case (S=0), this reduces to the familiar form:
∂t∂ρ+∇⋅J=0
2.1 Expanded in Cartesian Coordinates
Writing J=(Jx,Jy,Jz):
∂t∂ρ+∂x∂Jx+∂y∂Jy+∂z∂Jz=0
3. Discretisation on a Uniform Cartesian Grid
We now derive the discrete form in detail. Consider a uniform grid in d dimensions with spacing Δx, Δy, Δz and time step Δt. We label grid points by integer indices (i,j,k) and time levels by n:
xi=iΔx,yj=jΔy,zk=kΔz,tn=nΔt
The discrete density at grid point (i,j,k) and time tn is denoted ρi,j,kn.
The most natural discretisation proceeds from the integral form. Consider the cell Ωi,j,k centred at (xi,yj,zk) with volume ΔV=ΔxΔyΔz. Integrating the continuity equation over this cell:
dtd∫Ωi,j,kρdV=−∮∂Ωi,j,kJ⋅n^dA
Step 1: Approximate the volume integral. Assuming ρ is approximately uniform over the cell:
∫Ωi,j,kρdV≈ρi,j,kΔ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 x:
Right face at xi+1/2: area ΔyΔz, outward normal +x^, flux contribution +Jxi+1/2,j,kΔyΔz
Left face at xi−1/2: area ΔyΔz, outward normal −x^, flux contribution −Jxi−1/2,j,kΔyΔz
Similarly for y and z. The total surface integral becomes:
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 with a known velocity field v, a simple choice is:
Jx,i+1/2=21(ρivx,i+ρi+1vx,i+1)
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>0:
Jx,i+1/2=ρivx,i+1/2
For vx<0:
Jx,i+1/2=ρi+1vx,i+1/2
Compactly:
Jx,i+1/2=vx,i+1/2+ρi+vx,i+1/2−ρi+1
where v+=max(v,0) and v−=min(v,0).
3.3.3 Lax–Friedrichs Flux
A simple alternative that adds artificial diffusion:
Jx,i+1/2LF=21(Jx,i+Jx,i+1)−2ΔtΔx(ρi+1−ρi)
3.4 One-Dimensional Summary
In 1D with J=ρv and uniform velocity v, the upwind scheme with forward Euler gives the clean form:
ρin+1=ρin−ΔxvΔt(ρin−ρi−1n)for v>0
which is stable under the CFL condition:
ΔxvΔt≤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,…,N:
i=1∑Nρin+1Δx=i=1∑NρinΔx−Δt(JN+1/2−J1/2)
The total discrete "mass" changes only through the boundary fluxes JN+1/2 and J1/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.