1-D Linear Convection with the Finite Volume Method

Solving the fundamental transport equation using a conservative cell-averaged approach.

This example is the finite-volume version of the 1-D linear convection benchmark. While the physical equation being solved is exactly the same as in the Finite Difference Method (FDM) example, the Finite Volume Method (FVM) approaches the problem from a fundamentally different perspective: the conservation-law viewpoint.

What changes compared with FDM?

The Finite Difference Method directly approximates the derivatives of the governing PDE at specific points on a grid. In contrast, the Finite Volume Method is built upon the integral form of the conservation laws. Instead of storing point values, FVM stores cell averages. The values inside each cell are updated by calculating the numerical fluxes across the boundaries (faces) of the cells. This ensures that the transported quantity is conserved exactly, a property that makes FVM the method of choice for commercial CFD solvers.

Conservative form of linear convection

The 1-D linear convection equation can be written in conservative form as:

ut+f(u)x=0\frac{\partial u}{\partial t} + \frac{\partial f(u)}{\partial x} = 0

Here, uu is the conserved quantity, and f(u)f(u) is the flux function. For linear convection with a constant wave speed cc, the flux is simply:

f(u)=cuf(u) = c u

Control volumes and cell averages

In the Finite Volume Method, the 1D domain is partitioned into discrete control volumes, or cells. Instead of calculating uu at distinct grid nodes, we track uiu_i, which represents the average value of uu over the entire ii-th cell.

Numerical flux at cell faces

To update these cell averages over a time step, we must determine how much of the quantity uu flows into and out of each cell. This physical flow is represented by the numerical flux. We denote the flux at the right face of cell ii as Fi+1/2F_{i+1/2} and the flux at the left face as Fi1/2F_{i-1/2}.

Upwind flux for c > 0

The method used to calculate the numerical flux is crucial for the stability and accuracy of the simulation. For a strictly positive convection speed (c>0c > 0), information travels only from left to right. Thus, the flux at the right face i+1/2i+1/2 depends only on the state of the cell to its left, cell ii:

Fi+1/2=cuiF_{i+1/2} = c u_i

This approximation is known as the first-order upwind numerical flux.

Finite volume update

By integrating the conservative form of the equation over a control volume and applying the numerical fluxes, we obtain the explicit Finite Volume update formula:

uin+1=uinΔtΔx(Fi+1/2Fi1/2)u_i^{n+1} = u_i^n - \frac{\Delta t}{\Delta x} \left( F_{i+1/2} - F_{i-1/2} \right)

This algebraic equation clearly shows the conservation principle: the change in the cell average uiu_i is exactly determined by the net difference between the flux entering the cell and the flux leaving the cell.

Understanding the CFL number

As with the explicit Finite Difference method, the explicit Finite Volume method requires the time step to be limited for stability. The Courant-Friedrichs-Lewy (CFL) number is defined as:

CFL=cΔtΔx\text{CFL} = \frac{c \Delta t}{\Delta x}

For the first-order upwind FVM scheme to remain stable, we must satisfy 0CFL10 \le \text{CFL} \le 1. If the CFL number exceeds 1, the scheme attempts to transport flux further than one cell width per time step, causing non-physical oscillations and exponential instability.

CFL sweep interpretation

In our Python example, we perform a sweep over three CFL values to observe their impact:

  • CFL = 0.8: The scheme is stable. However, the first-order upwind flux introduces numerical diffusion, which causes the pulse to become noticeably smeared out as it travels.
  • CFL = 1.0: The scheme is stable. In this special periodic grid setup, the numerical transport shifts the cell averages exactly one cell width per time step. This leads to near-exact agreement with the analytic solution. Note that this zero-diffusion property at CFL = 1 is a special case and does not generally hold for non-uniform grids or varying speeds.
  • CFL = 1.2: This violates the stability condition, resulting in rapid growth of numerical errors. In the generated plot, the values for CFL = 1.2 are clipped simply for visual readability, but the console output (the minimum/maximum values and L2 error) reveals the true, massive magnitude of the instability.

Relationship to the FDM result

If you carefully substitute the upwind flux Fi+1/2=cuiF_{i+1/2} = c u_i and Fi1/2=cui1F_{i-1/2} = c u_{i-1} into the FVM update equation, you will find that it reduces to the exact same algebraic formula as the first-order upwind Finite Difference Method on a uniform grid with a constant positive wave speed.

Despite this algebraic equivalence, understanding the FVM derivation is extremely important. The FVM is built around cell averages, exact conservation, and flux balancing—concepts that easily extend to complex unstructured meshes and nonlinear systems of equations like the Navier-Stokes equations, where FDM struggles.

Educational Python Example

You can find the complete, runnable Python code for this numerical experiment in The Numerics Lab repository. It includes the calculation of cell face fluxes and the finite volume update.

View Example on GitHub

Note: If the code PR is not merged yet, the example folder will appear in the main branch after the code PR is merged.