1-D Linear Convection with DG0
An introduction to the Discontinuous Galerkin method using piecewise-constant elements.
Welcome to the very first Discontinuous Galerkin (DG) example in The Numerics Lab. This page intentionally starts with the simplest possible DG formulation: a piecewise-constant approximation (DG0). Before diving into high-order DG and the Discontinuous Galerkin Spectral Element Method (DGSEM), it is crucial to establish the foundational concepts of elements, local approximations, discontinuities, and interface fluxes using a straightforward problem.
Why start with DG0?
The Discontinuous Galerkin method is incredibly powerful for high-order simulations, but its mathematical formulation can be intimidating. By setting the polynomial degree to $p = 0$, we strip away the complexities of basis functions, numerical quadrature, and modal/nodal transformations. DG0 allows us to focus purely on the "Galerkin" framework—the weak form and flux balances—in a setting that is highly intuitive.
Conservative form of linear convection
We begin with the 1-D linear convection equation in its conservative form:
Here, is the transported scalar quantity and is the constant wave speed.
Elements and local polynomial approximation
The first step in any DG method is to partition the global domain into non-overlapping local regions called elements. Within each element, the solution is approximated using a local polynomial of degree $p$. Unlike continuous finite element methods, DG does not enforce continuity across element boundaries. The solution is allowed to be discontinuous at the interfaces.
Piecewise-constant DG0 approximation
In DG0, we choose a polynomial degree of $p = 0$. This means the solution is simply a constant value within each element:
Where is the $i$-th element, and is the single constant value representing the solution inside it.
Weak form and interface fluxes
To derive the numerical scheme, we multiply the governing equation by a test function and integrate over the element . For DG0, the test function is just a constant (1). The volume integral of the spatial derivative becomes a boundary evaluation at the element interfaces. Because the solution is discontinuous, the physical flux is ambiguous at the boundaries. We resolve this by introducing a single-valued numerical flux, , which couples adjacent elements together.
Upwind numerical flux for c > 0
Since information flows strictly from left to right when , the interface flux should be determined by the value on the left (upwind) side of the interface:
DG0 update
By substituting the upwind numerical flux into the weak form and applying a forward Euler time step, we arrive at the explicit DG0 update formula:
Understanding the CFL number
Like all explicit schemes, stability dictates a maximum allowable time step size. This is governed by the Courant-Friedrichs-Lewy (CFL) number:
For this specific DG0 formulation and forward Euler time integration, stability requires .
CFL sweep interpretation
In the companion Python code, we simulate the transport of a smooth Gaussian pulse under three different CFL conditions:
- CFL = 0.8: The scheme is stable but highly diffusive. The DG0 approximation with an upwind flux smears out the pulse as it travels.
- CFL = 1.0: The scheme is stable. In this very specific setup (uniform grid, constant speed), the numerical flux shifts the data exactly one cell width per time step, resulting in near-exact transport without diffusion.
- CFL = 1.2: The stability limit is violated. While the plotted values in the graphical output are clipped for visual readability, checking the console's actual minimum, maximum, and L2 error values reveals the massive numerical instability and exponential growth.
Relationship to FVM and FDM
You might recognize the final DG0 update formula. For this specific problem—1-D linear convection with a constant positive wave speed on a uniform mesh—DG0 with an upwind flux is algebraically equivalent to the first-order upwind Finite Volume Method (FVM). Furthermore, it matches the first-order upwind Finite Difference Method (FDM) update.
The true value of this example is purely conceptual. It introduces the language of DG—elements, local polynomial spaces, discontinuous interfaces, and weak flux balances—in a familiar algebraic setting before we introduce the complexity of higher-order polynomials.
What comes next: DG1 and DGSEM
With the foundation laid by DG0, the next natural step is to increase the polynomial degree. In DG1 ($p=1$), we will introduce linear basis functions, volume integrals that no longer vanish, and higher-order time integration schemes like Runge-Kutta. This will eventually culminate in the highly accurate Discontinuous Galerkin Spectral Element Method (DGSEM).
Educational Python Example
You can find the complete, runnable Python code for this numerical experiment in The Numerics Lab repository. It demonstrates the element partitioning, flux calculation, and the exact DG0 update shown above.
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.