Periodic upwind finite volume advection (source code)

= Periodic upwind finite volume advection
{title2=$U_j^{n+1}=(1-\nu)U_j^n+\nu U_{j-1}^n$}

Consider the <advection equation> $u_t+a u_x=0$ with constant speed $a>0$, no sources, and <periodic boundary conditions> on $[0,1]$. Use $N$ equal cells of width $h=1/N$, time step $k>0$, and indices modulo $N$. The exact solution is the periodic translation $u(x,t)=u_0(x-at)$. At a face, the <Riemann problem> transports the left state to the right, so the two-state upwind <numerical flux> is $F(L,R)=aL$, with $F(U,U)=aU$.<Riemann Problems and Jupyter Solutions by David I. Ketcheson, Randall J. LeVeque, and Mauricio J. del Razo>[Advection, equations adv:advection and adv:solution, §The Riemann problem; Approximate solvers, §High-resolution methods: reduction to upwind advection]{ref}

The <finite volume method> with this <numerical flux> and an <explicit Euler method> step gives
$$
F_{j+1/2}^n=aU_j^n,\qquad \nu=\frac{ak}{h},\qquad U_j^{n+1}=(1-\nu)U_j^n+\nu U_{j-1}^n.
$$
Here $U_j^n$ represents a <cell average>; the recurrence also occurs in the <upwind finite difference scheme>. Impose the specific <CFL condition> $0<\nu\leq1$. Each updated <cell average> is then a <convex combination> of two old ones. This proves preservation of their initial minimum and maximum, including nonnegativity for nonnegative data, and contraction of the <maximum norm> of the difference of two solutions on this periodic grid. These statements concern this constant-speed scalar update with this time step.

For an original synthetic example, take $N=8$, $a=1$, $h=1/8$, $k=1/16$, hence <Courant number> $\nu=1/2$. Choose a <function> constant on each successive cell, with the following values, so these are exact initial <cell averages>. One step gives
$$
\begin{array}{c|rrrrrrrr}
j&0&1&2&3&4&5&6&7\\\hline
U_j^0&0&0&2&2&1&0&0&1\\
U_j^1&1/2&0&1&2&3/2&1/2&0&1/2
\end{array}
\qquad M^0=M^1=\frac18\cdot6=\frac34.
$$
For example, cell zero receives from cell seven across the periodic face: $U_0^1=(0+1)/2=1/2$. All eight face transfers cancel in the total by <shared face flux cancellation>. More generally this periodic recurrence conserves the total algebraically for any $\nu$, even though the <CFL condition> is needed for the <convex combination> argument. With the same initial data and $\nu=3/2$, one step gives $U_2^1=-1$ and $U_4^1=5/2$, despite preserving the total.

\Image[/finite-volume-periodic-upwind-mass.png]
{title=Original periodic upwind profile at zero, one and four steps: the integral remains three quarters while jumps spread}

After four steps, $t=1/4$, the exact translated profile has moved two cells to the right. Repeated averaging instead gives the explicit <binomial coefficient> formula
$$
U_j^4=\frac1{16}\bigl(U_j^0+4U_{j-1}^0+6U_{j-2}^0+4U_{j-3}^0+U_{j-4}^0\bigr),
$$
with all indices modulo eight. The diagram compares these computed <cell averages> with the exact translated <cell averages>. Their <integrals> agree, but the numerical jumps spread across cells. The <finite volume method> is useful for <jump discontinuities> because it retains the integral balance even at a jump; conservation alone does not guarantee a sharp profile. At $\nu=1$ this particular update is an exact one-cell shift, whereas for $0<\nu<1$ it mixes neighboring states. No accuracy conclusion at a jump follows just from the conserved total.