Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Step 2 — 1D Nonlinear Convection

Authors
Affiliations
University of Valencia

13 Steps to Navier-Stokes with somax (inspired by Lorena Barba’s CFD Python)

In Step 1 we saw linear convection: a wave translating at constant speed. Now we let the wave speed depend on the solution itself. This seemingly small change introduces dramatic new physics — steepening fronts, shock formation, and the need for upwind schemes.

What you’ll learn:

  1. How nonlinear self-advection steepens wave profiles

  2. Why upwind flux reconstruction is essential for stability

  3. How to track energy conservation in a nonlinear system

  4. How to differentiate through the nonlinear simulation

The PDE

∂u∂t+u∂u∂x=0\frac{\partial u}{\partial t} + u \frac{\partial u}{\partial x} = 0

This is the inviscid Burgers equation — the simplest nonlinear hyperbolic conservation law. It can be written in conservative form:

∂u∂t+∂∂x(u22)=0\frac{\partial u}{\partial t} + \frac{\partial}{\partial x} \left( \frac{u^2}{2} \right) = 0

Self-steepening

The wave speed is uu itself: regions with larger amplitude travel faster. The crest of a positive bump outruns the trough, causing the leading edge to steepen until a shock (discontinuity) forms in finite time. After the shock, the classical solution breaks down and one needs weak (entropy) solutions.

In our discrete simulation, the upwind scheme adds enough numerical dissipation to keep the solution stable through mild steepening, but we deliberately stop before a strong shock develops.

Grid layout and boundary conditions

somax uses the Arakawa C-grid from finitevolX. In 1D, scalar fields (like uu) live at T-points (cell centres) and fluxes are computed at U-points (cell edges):

 ghost                    interior                     ghost
 ┌─────┬──────┬──────┬──────┬──────┬──────┬──────┬─────┐
 │  G  │  T₁  │  T₂  │  T₃  │ ···  │ Tₙ₋₁│  Tₙ  │  G  │
 └──┬──┴──┬───┴──┬───┴──┬───┴──┬───┴──┬───┴──┬───┴──┬──┘
    U₀    U₁     U₂     U₃           Uₙ₋₁    Uₙ    Uₙ₊₁
         ←── dx ──→
  • T-points (indices 1:-1): where u is stored and updated

  • U-points: where upwind flux reconstruction computes the nonlinear advection term ∂(u2/2)/∂x\partial(u^2/2)/\partial x

  • Ghost cells (indices 0 and -1): filled by BCs before each RHS evaluation

Periodic BCs copy the last interior value into the opposite ghost cell:

 u[0] = u[-2]      (left ghost ← rightmost interior)
 u[-1] = u[1]      (right ghost ← leftmost interior)

This makes the domain wrap around so waves that exit one side re-enter from the other.

1. Create the model

NonlinearConvection1D has no learnable parameters (the wave speed is the solution itself). The model uses upwind flux reconstruction for stability.

Grid: Nx=202, dx=0.0200
Advection method: upwind1

2. Initial condition

A Gaussian bump centered at x=1.5x = 1.5 with amplitude 1. The positive values mean the entire bump travels to the right, but faster at the peak than at the tails.

<Figure size 800x300 with 1 Axes>

3. Forward simulation — watching the profile steepen

We save snapshots at several times to visualize how the leading edge steepens while the trailing edge stretches.

Trajectory shape: u=(6, 202)
<Figure size 1000x400 with 1 Axes>

Notice how the right edge of the bump steepens: the peak (where uu is largest) outruns the base (where uu is smaller). This is the hallmark of nonlinear advection.

4. Comparing with linear convection

To highlight the nonlinear effect, we overlay the nonlinear result with a pure translation (what linear convection would give for the same initial bump).

<Figure size 1000x400 with 1 Axes>

5. Energy evolution

For the inviscid Burgers equation, the L2L^2 energy E=12∫u2 dxE = \frac{1}{2} \int u^2 \, dx is conserved analytically (before shock formation). Numerically, the upwind scheme introduces dissipation — this is actually desirable as it provides the entropy condition needed to select the physically correct weak solution.

<Figure size 800x300 with 1 Axes>
Energy: initial = 0.265868, final = 0.243400
Relative change: 8.4509%

6. A note on upwind schemes and stability

The nonlinear convection equation requires careful numerical treatment:

  • Upwind schemes bias the stencil in the direction from which information propagates. somax uses "upwind1" (first-order upwind) by default, which is diffusive but unconditionally entropy-stable.

  • Central differences (what you might try first) are unstable for hyperbolic equations — they produce unphysical oscillations.

  • Higher-order methods (WENO, PPM) reduce numerical diffusion while maintaining stability near shocks.

The CFL condition for Burgers’ equation uses the maximum wave speed: Δt≤Δx/max⁡∣u∣\Delta t \le \Delta x / \max|u|.

CFL number (initial): max|u| * dt / dx = 0.100

7. Differentiability demo

Even though the model has no explicit learnable parameters, we can still differentiate with respect to the initial condition. This is useful for data assimilation and optimal control.

<Figure size 1000x300 with 1 Axes>
Max |dL/du0|: 0.007150

Summary

Conceptsomax API
Create modelNonlinearConvection1D.create(nx=200, Lx=4.0)
Initial stateNonlinearConvection1DState(u=...)
Forward simmodel.integrate(state0, t0, t1, dt, saveat=...)
Energy checkmodel.diagnose(state).energy
Grad w.r.t. ICjax.grad(loss)(state0)

Key takeaway: Nonlinear convection causes self-steepening — the wave speed depends on amplitude. Upwind schemes provide the numerical dissipation needed for stability.

Next: Step 3 — Diffusion introduces viscosity, which smooths gradients and dissipates energy.