solve_heat_1d
Solve the 1D heat equation u_t = alpha*u_xx using explicit FTCS with Dirichlet, Neumann, or Robin boundary conditions and configurable grid and time steps.
Instructions
Solve u_t = alpha*u_xx with explicit FTCS and configurable ends.
``nx`` is the number of spatial intervals (nx+1 grid points) and ``nt`` the
number of time steps. The scheme requires r = alpha*dt/dx^2 <= 0.5; larger
values are rejected as unstable. Each of ``left``/``right`` is either a
float (Dirichlet value) or a dict:
``{"type": "dirichlet", "value": v}``,
``{"type": "neumann", "flux": q}`` or
``{"type": "robin", "h": h, "ambient": a}``.
Sign conventions: ``flux`` is the x-derivative du/dx at the boundary, not
the outward-normal derivative. At the left end the outward normal is -x,
so the outward-normal derivative there is -flux; at the right end it is
+flux. The Robin condition uses the same x-derivative convention at both
ends: ``h*(u - ambient) + du/dx = 0`` (unit conductivity k), i.e.
``h*(u - ambient) - du/dn = 0`` on the left and
``h*(u - ambient) + du/dn = 0`` on the right. Neumann/Robin ends use ghost
nodes; Robin is applied at the new time level so that large h remains
stable. 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 |
|---|---|---|---|
| nt | Yes | ||
| nx | Yes | ||
| left | No | ||
| alpha | Yes | ||
| right | No | ||
| t_end | Yes | ||
| length | Yes | ||
| initial | Yes |