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 4 — 1D Burgers’ Equation

Authors
Affiliations
University of Valencia

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

Steps 1--3 introduced convection and diffusion separately. Now we bring them together in Burgers’ equation — the simplest PDE that exhibits the competition between nonlinear steepening and viscous smoothing. This balance is at the heart of turbulence and is the reason Burgers’ equation has been called “the hydrogen atom of fluid dynamics.”

What you’ll learn:

  1. How convection and diffusion compete to shape the solution

  2. How viscosity controls the balance (low ν\nu: shocks; high ν\nu: smooth decay)

  3. How to compare solutions at different viscosities side by side

  4. How to compute ∂L/∂ν\partial \mathcal{L} / \partial \nu for parameter estimation

The PDE

∂u∂t+u∂u∂x=ν∂2u∂x2\frac{\partial u}{\partial t} + u \frac{\partial u}{\partial x} = \nu \frac{\partial^2 u}{\partial x^2}

The left-hand side is the nonlinear convection from Step 2 (inviscid Burgers). The right-hand side is the diffusion from Step 3. The dimensionless ratio that controls the balance is the Reynolds number:

Re=ULν\mathrm{Re} = \frac{U L}{\nu}

where UU is a characteristic velocity and LL a characteristic length. At high Re the nonlinear term dominates (sharp gradients, near-shocks). At low Re diffusion dominates (smooth, decaying profiles).

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 advection term ∂(u2/2)/∂x\partial(u^2/2)/\partial x

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

Burgers’ equation combines both advection (upwind reconstruction at U-points) and diffusion (Laplacian stencil at T-points). The Laplacian  (ui+1−2ui+ui−1)/Δx2 \,(u_{i+1} - 2u_i + u_{i-1})/\Delta x^2\, reaches both neighbours, so ghost cells are essential for both terms.

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 that both advection and diffusion operate seamlessly across the boundary.

1. Create the model

Burgers1D combines upwind advection with centered diffusion. The viscosity ν\nu is a differentiable parameter.

Grid: Nx=202, dx=0.0200
Viscosity nu = 0.05000000074505806
Advection method: upwind1

2. Initial condition

A Gaussian bump centered at x=1.5x = 1.5. The positive amplitude means the nonlinear term will try to steepen the right flank while diffusion resists.

<Figure size 800x300 with 1 Axes>

3. Forward simulation — the Burgers dynamics

The initial steepening (convection) is gradually balanced by diffusion, producing a characteristic asymmetric profile.

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

Notice the initial rightward steepening (Steps 1--2) followed by overall decay (Step 3). The profile develops the classic Burgers asymmetry: a steep front on the right and a gentle tail on the left.

4. Low vs. high viscosity comparison

The viscosity ν\nu controls the balance between steepening and smoothing. We compare three values to see the effect.

<Figure size 1500x400 with 3 Axes>

Low viscosity (ν=0.005\nu = 0.005): the nonlinear term dominates, producing a sharp front that resembles a shock.

Medium viscosity (ν=0.05\nu = 0.05): steepening and diffusion are balanced — the classic Burgers profile.

High viscosity (ν=0.2\nu = 0.2): diffusion dominates, and the profile decays almost symmetrically (nearly pure diffusion).

5. Side-by-side at a fixed time

Overlaying the three viscosities at t=0.4t = 0.4 makes the contrast even clearer.

<Figure size 1000x400 with 1 Axes>

6. Energy evolution

Energy E=12∫u2 dxE = \frac{1}{2} \int u^2 \, dx always decays for Burgers (the diffusion term dissipates it). Higher viscosity means faster decay.

<Figure size 800x350 with 1 Axes>

7. Differentiability demo — gradient w.r.t. viscosity

Suppose we observe a diffusing, steepening profile and want to infer the viscosity. We compute ∂L/∂ν\partial \mathcal{L} / \partial \nu where L\mathcal{L} measures the mismatch between the predicted and observed final profile.

--- Gradient w.r.t. model parameters ---
  Current nu = 0.050
  True nu    = 0.08
  dL/d(nu)   = -0.041828

A negative gradient means increasing nu (toward the true value)
would decrease the loss — the gradient points in the right direction.

Gradient landscape

We can sweep over ν\nu values to see the full loss landscape and verify that the gradient direction is consistent.

<Figure size 800x350 with 1 Axes>

Summary of 1D models

StepPDEKey physicssomax model
1ut+cux=0u_t + c u_x = 0Translation at constant speedLinearConvection1D
2ut+uux=0u_t + u u_x = 0Self-steepening, shocksNonlinearConvection1D
3ut=νuxxu_t = \nu u_{xx}Smoothing, energy decayDiffusion1D
4ut+uux=νuxxu_t + u u_x = \nu u_{xx}Steepening vs. smoothingBurgers1D

All four models share the same API contract:

  • Model.create(...) — factory with physical parameters

  • model.integrate(state0, t0, t1, dt, saveat=...) — forward sim

  • model.diagnose(state) — on-demand diagnostics

  • eqx.filter_grad(loss)(model) — differentiable w.r.t. parameters

What comes next: These 1D building blocks extend naturally to 2D. Steps 5--8 will introduce 2D convection, diffusion, and the cavity flow problem, building toward the full Navier-Stokes equations.