solve_wave_1d
Solve the 1D wave equation u_tt = c^2 u_xx with explicit central differences, enforcing the Courant condition and supporting Dirichlet, Neumann, and Robin boundary conditions.
Instructions
Solve u_tt = c^2*u_xx with explicit central differences.
``initial_displacement`` and ``initial_velocity`` are expressions in ``x``.
The Courant condition c*dt/dx <= 1 is enforced. Each of ``left``/``right``
is either a float (Dirichlet displacement) or a dict:
``{"type": "dirichlet", "value": v}``,
``{"type": "neumann", "flux": q}`` or
``{"type": "robin", "h": h, "ambient": a}``; boundary conditions act on the
displacement. ``flux`` is du/dx at the boundary (not the outward-normal
derivative): the left outward normal is -x so its outward-normal derivative
is -flux, while the right end's is +flux. Robin means
``h*(u - ambient) + du/dx = 0`` at both ends with the same x-derivative
convention (unit conductivity k). Neumann/Robin ends use ghost
nodes, with Robin applied at the new time level for stability at large h.
The full grid is saved as .npz, while the returned arrays are downsampled
to at most 100 spatial and 50 time points.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| c | Yes | ||
| nt | Yes | ||
| nx | Yes | ||
| left | No | ||
| right | No | ||
| t_end | Yes | ||
| length | Yes | ||
| initial_velocity | No | 0 | |
| initial_displacement | Yes |