Numerical Methods · interactive worked example

Potential Flow Over an Irregular Conduit

Laplace's equation on a rectangle is easy to mesh — every interior point looks the same. Cut a slanted wall into the domain and suddenly the mesh itself has to be generated automatically, node by node, before you can even write the equations.

From the site author's own Mathematica work, presented in "Report from the Trenches: Tips, Tricks and Traps for Mathematica Programmers" — reading geometry from input points, auto-generating the FD grid, and solving, for a potential-flow conduit problem.

∇²u = 0 → u[i−1,j]+u[i+1,j]+u[i,j−1]+u[i,j+1]−4u[i,j] = 0
Same Laplace equation as steady conduction or electrostatics — here u is a potential-flow velocity. The 5-point stencil is identical everywhere; only the boundary handling has to adapt to the shape.

Velocity field u(x,y) — solved live on the cut-corner conduit

Darker = slower · Brighter = faster
Unknown nodes solved
Max interior velocity
Matches original notebook

What you're seeing

Entrance velocity (free surface)

10

Exit velocity (free surface)

10

How the mesh gets built automatically

From geometry to matrix, step by step

  1. Read the boundary as a list of points. The conduit's outline is just an ordered list of grid corners: (1,7)→(9,7)→(9,1)→(7,1)→(4,4)→(1,4)→back to (1,7). No formula for the shape is needed — just the points.
  2. Classify every grid node. A node is either outside the domain, on the boundary (value given), or interior (value unknown) — found automatically by checking each row's valid index range, which shrinks where the slanted wall cuts in.
  3. Write the same 5-point Laplace stencil everywhere. Every interior node gets the identical finite-difference equation; the geometry only changes which neighbors are "boundary" (known) vs "interior" (unknown) for a given node.
  4. Assemble into a matrix. Known boundary values move to the right-hand side; unknown-to-unknown coefficients build a sparse matrix — solved here by direct elimination since the system is small.
  5. Solve and plot. The same linear-algebra step as the Gauss-Seidel lab — this lab uses direct Gaussian elimination since 23 unknowns solves instantly, but the same matrix could just as easily be handed to an iterative solver.

None of this changes if you swap "potential flow velocity" for "steady-state temperature" or "electrostatic potential" — Laplace's equation doesn't know which physics it's describing. The geometry-handling machinery is the actual reusable skill.

Reading the result

With both free-surface velocities at 10 m/s (the original problem's values), this lab's solve reproduces the original notebook's printed solution exactly — every one of the 23 interior values matches to six decimal places. Try making the exit velocity larger than the entrance: the flow accelerates through the narrowing/widening geometry, and the contour bands compress near the slanted wall where the domain changes shape fastest.

EngineeringCandy · Mesh generated and matrix solved live, from raw boundary points · the slanted wall is just data, not a special case in the code