Finite volume method (source code)

= Finite volume method
{wiki}

The <finite volume method> follows the amount of a conserved quantity inside each <control volume>. Its unknowns are <cell averages>, rather than values at isolated points: a cell's width times its stored average approximates that cell's total. A <numerical flux> transfers an amount across a face. Using one shared transfer for both neighboring cells makes the loss from one exactly the gain of the other, as explained in <shared face flux cancellation>.<Riemann Problems and Jupyter Solutions by David I. Ketcheson, Randall J. LeVeque, and Mauricio J. del Razo>[Approximate solvers, §Finite volume methods, equation FVupdate and the following cancellation argument]{ref}

For a one-dimensional <scalar conservation law> without sources, let $u_t+\partial_x f(u)=0$, with <conservation law flux> $f$. Fix cells $I_j=[x_{j-1/2},x_{j+1/2}]$ of widths $h_j>0$. Define the exact <cell average> and its numerical approximation by
$$
\overline u_j(t)=\frac1{h_j}\int_{I_j}u(x,t)\,dx,\qquad U_j^n\approx\overline u_j(t_n).
$$
The integral balance over one cell and one time interval of length $k>0$ is
$$
h_j\bigl(\overline u_j(t_n+k)-\overline u_j(t_n)\bigr)=\int_{t_n}^{t_n+k}\bigl[f(u(x_{j-1/2},t))-f(u(x_{j+1/2},t))\bigr]\,dt.
$$
For a smooth solution this follows by <integration> of the differential equation; with <jump discontinuities>, it expresses the <conservation law> in integral form, using appropriate face traces when they exist. Replacing each time-averaged face <conservation law flux> by a <numerical flux> gives
$$
U_j^{n+1}=U_j^n-\frac{k}{h_j}\bigl(F_{j+1/2}^n-F_{j-1/2}^n\bigr).
$$
Thus the <finite volume method> implements a balance directly, without needing a pointwise <derivative> at a jump. The tube balance in <Riemann Problems and Jupyter Solutions by David I. Ketcheson, Randall J. LeVeque, and Mauricio J. del Razo> (Advection, §Conservation of mass) motivates this construction from <conservation of mass>.

This is useful for <shock waves>: their speed is constrained by the <Rankine-Hugoniot condition>, itself an integral balance. A nonconservative approximation can give a visibly plausible jump with the wrong speed. Conservation is one requirement; a nonlinear <scalar conservation law> also needs the correct <entropy solution>, and the chosen <numerical flux> and update need their own <stability> and accuracy analysis.<Riemann Problems and Jupyter Solutions by David I. Ketcheson, Randall J. LeVeque, and Mauricio J. del Razo>[Approximate solvers, §§Finite volume methods, Godunov's method, High-resolution methods: wrong shock speeds, time-step restrictions and smeared jumps]{ref} The original <periodic upwind finite volume advection> example isolates the shared-transfer mechanism in a problem with a known translated solution.