This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

PDE solvers · Steady states and modes (elliptic)

Laplace's equation

Method
successive over-relaxation, with the optimal relaxation factor for a square
Checked
a value symmetry fixes exactly; and that over-relaxation beats plain Gauss-Seidel by the factor theory predicts

A square plate: one edge held at 1, the other three at 0. What is the temperature at the center?

Exactly , and no series is needed to see it. Solve the problem four times, heating each edge in turn, and add the answers: the sum has every edge at 1, so it is 1 everywhere. By symmetry each of the four gives the same value at the center. The discrete equations have the same symmetry, so the numerical answer is too — to the solver's tolerance, not the grid's. It is the rare test with no discretization error in it.

Gauss-Seidel replaces each point by the average of its neighbors, sweep after sweep, and is slow: the error shrinks by a factor of about per sweep. SOR moves each point a factor past that average. With the factor becomes about , and the number of sweeps drops from to .

What the run shows

A plate with one hot edge
y
x
25 × 25 grid
  • the center of the plate is exactly 1/4, by symmetry
  • Gauss-Seidel reaches the same answer
  • optimal over-relaxation needs an order of magnitude fewer sweeps
OMEGA
1.76909
center
0.25
sor_sweeps
110
gs_sweeps
1315
speedup
11.9545

Computed when this page was built, by the same interpreter that runs it in your browser: 3 of 3 tests, 2.13 s. The numbers above are the program's show lines.

The program

63 lines, one function. It is editable: change it and press Run (or ⌘/Ctrl + Enter). The tests at the bottom run too, so if your change breaks the solver, a test fails.

relax
Relax to convergence with relaxation factor omega; returns the grid.
Viv [1]

Open in the workbench The atlas Download laplace_2d.viv