Numerical Methods · Design background
A 5-point finite-difference stencil doesn't care what shape the domain is. The hard part is everything that happens before you can write that stencil down — and that's where automating the geometry pays off.
On a rectangular grid, every interior node has exactly the same situation: four neighbors, all either interior or boundary, and the boundary is just "the edge of the array." That's the case in the 2D Conduction lab — looping over a rectangular array and writing one stencil everywhere just works.
Cut a corner off — a slanted wall, a notch, an L-shape — and two things break: some grid points that would exist in the full rectangle no longer belong to the domain at all, and the boundary is no longer "just the array edge." You need an explicit way to ask, for any grid point, "is this inside the domain, on its boundary, or outside entirely?"
This row-by-row index range is the entire trick: describe the irregular shape as a function that shrinks the allowed range of $i$ as $j$ decreases, instead of trying to write one formula for the whole 2-D region at once. The slanted wall here is just a sequence of grid points stepping diagonally — (4,4), (5,3), (6,2), (7,1) — handled as ordinary boundary points, no different in kind from a flat wall.
Once a node is known to be interior, the Laplace finite-difference equation is always the same 5-point form:
Geometry only affects which of those four neighbor terms are "known" (move to the right-hand side) versus "unknown" (stay as a matrix coefficient) — not the equation's form. That separation — geometry decides knowns vs. unknowns, the stencil stays fixed — is what makes irregular domains tractable at all.
Loop over every interior node, write its stencil equation, sort each term into "known boundary value → right-hand side" or "unknown neighbor → matrix coefficient," and you have a standard linear system $Ax=b$. For the conduit problem that's 23 unknowns — small enough for direct Gaussian elimination, but the exact same matrix could be handed to Gauss-Seidel or SOR for a larger mesh where direct solving becomes too slow.
At the original problem's settings (10 m/s entrance and exit), the lab's live solve reproduces all 23 values from the 1990s-era notebook this is based on, to six decimal places. Open the lab →
Laplace's equation $\nabla^2 u=0$ doesn't know whether $u$ is a velocity potential, a steady-state temperature, or an electrostatic potential — the math is identical in all three cases. The mesh-generation and matrix-assembly machinery built here works unchanged for any of them; only the boundary values change with the physics, never the method.
EngineeringCandy · Learn · the design thinking behind the playground