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:
Here, is the conserved quantity, and is the flux function. For linear convection with a constant wave speed , the flux is simply:
Control volumes and cell averages
In the Finite Volume Method, the 1D domain is partitioned into discrete control volumes, or cells. Instead of calculating at distinct grid nodes, we track , which represents the average value of over the entire -th cell.
Numerical flux at cell faces
To update these cell averages over a time step, we must determine how much of the quantity 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 as and the flux at the left face as .
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 (), information travels only from left to right. Thus, the flux at the right face depends only on the state of the cell to its left, cell :
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:
This algebraic equation clearly shows the conservation principle: the change in the cell average 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:
For the first-order upwind FVM scheme to remain stable, we must satisfy . 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 and 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 GitHubNote: If the code PR is not merged yet, the example folder will appear in the main branch after the code PR is merged.