A Byte of PhysicsLogo

Fields as partial differential equations

A field assigns a value to every position, and a partial differential equation (PDE) relates local changes in that value across space and time. Code cannot store “every position,” so it chooses a grid, an update rule, and boundary behavior. Those choices are part of the physical model, not low-level implementation details.

Think like a programmer

Represent field state as immutable arrays plus explicit grid geometry. A PDE solver is a local reducer: it reads the previous grid, computes neighbor-based differences, and returns a next grid without mixing drawing code into the update. Make dx, dt, coefficient units, source arrays, and edge policy parameters. Then write known-value tests before animating the result.

Model checklist

Inputs
Initial grid values, spatial spacing Δx and Δy, time step Δt, coefficients, source terms, and boundary policy.
State
Current field array and, for second-order time models, any prior-time array.
Rule
Approximate partial derivatives with local finite differences, then advance a stable update.
Output
Next field grid, conserved or dissipated quantities, residuals, and boundary transfer.
Check
Known uniform and symmetric fixtures behave as predicted; refined grid/time choices converge; invalid stability choices are rejected before updates.

A classic scalar example is diffusion,

\[\frac{\partial u}{\partial t}=D\nabla^2u\]

where u might be a concentration or temperature-like scalar and D is diffusivity. On a unit-spaced two-dimensional grid, the five-point Laplacian is

\[\nabla_h^2u_{i,j}=u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1}-4u_{i,j}\]

An explicit update becomes

\[u^{n+1}_{i,j}=u^n_{i,j}+D\Delta t\nabla_h^2u^n_{i,j}\]
const laplacian = east + west + north + south - 4 * center;
const nextValue = center + diffusivity * timeStep * laplacian;

This teaches two important API choices. First, all nextValue computations must read the old grid; mutating cells in place makes update order change the model. Second, for the unit-grid two-dimensional explicit scheme, stability requires approximately D * Δt ≤ 1/4. Rejecting a larger product is more honest than rendering exploding values and calling them a surprising pattern.

Boundary policy changes the question. A fixed-zero boundary acts like a prescribed exterior value; wrapping makes opposite edges neighbors and models a periodic tile. Start with a single central peak: one stable step should lower its center, raise nearby cells, leave the old grid unchanged, and behave differently at edges under the two policies.

Try this experiment

Prediction: A stable diffusion step spreads a peak, while a time step beyond the stability bound can create nonphysical oscillation or growth.

Use a 3×3 grid with one central value of 1 and zeros elsewhere. Predict the center and four neighbor values after DΔt = 0.1, then compare with the update. Next explain why a wrap boundary makes an edge cell interact with the opposite edge.

Where this model breaks

The grid helper is a teaching diffusion model, not a universal PDE engine. It assumes a square unit grid, constant diffusivity, explicit time stepping, and simple boundaries. Waves, fluids, electromagnetism, nonlinear reaction terms, irregular geometry, and anisotropic materials need different state, operators, stability criteria, and often implicit or higher-order methods.

Summary

PDE code is local array programming with physical consequences. State the grid and boundaries, derive the finite-difference update, enforce its stability condition, and test old-grid immutability, symmetric fixtures, and refinement before trusting an animated field.

Glossary

Self-check

  1. Why must an explicit step read only the previous grid?
  2. What boundary policy makes opposite edges neighbors?
  3. What should a stable diffusion step do to an isolated peak?

Sources

Model contract

Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.

\[\text{observable output} = f(\text{inputs},\,\text{state})\]
Inputs
Quantities you set or measure, with units and useful bounds.
State
Values the program must retain to reproduce the next result.
Rule
The relationship or update that turns inputs and state into a result.
Check
A known limit, unit check, invariant, or measured result that can expose a bad model.

Implement the idea as a model

For Fields as Partial Differential Equations, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Maxwell’s Equations and EM Waves, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.

Guided experiment

Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.

Where this model breaks

This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.

Summary

Treat Fields as Partial Differential Equations as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.

Glossary

  • Input: a measured value or chosen parameter supplied to a model.
  • State: the smallest set of values needed to continue or reproduce a model.
  • Validation: comparing an output with a known result, limit, invariant, or measurement.

Self-check

  1. Which values are inputs, and which values must remain state?
  2. What observable result would tell you the model is behaving as expected?
  3. Which assumption would you test first before applying the model to a real system?

Model review: turn Fields as Partial Differential Equations into a test

Translate field equations into explicit grid state, boundaries, and stable local update rules.

  1. Name the inputs and units that the maxwell’s equations and em waves model needs.
  2. Separate the state you must keep from values you can calculate when needed.
  3. Write one rule that maps the current state and inputs to an observable result.
  4. Choose a limiting case, unit check, invariant, or known result before trusting an output.
  5. State one assumption you would change before using this simplified model for a real decision.

Share to: