Web Simulation 

 

 

 

 

1D Wave Equation Simulation 

This note provides an interactive, visual simulation of the 1D Wave Equation using the finite difference method. The simulation allows you to draw initial wave shapes and observe how they propagate, reflect, and interact with different boundary conditions.

The wave equation is solved using an explicit central difference scheme, which discretizes the string into 200 points and updates the displacement at each point based on its neighbors. The simulation uses a Courant number of 0.5 for numerical stability, ensuring that the wave propagates correctly without numerical artifacts. A small damping factor (0.999) is applied to prevent energy accumulation over time.

You can interact with the simulation in two modes: Drawing mode (initial state) and Simulating mode. In Drawing mode, click and drag on the canvas to draw the initial wave shape. The drawn waveform is automatically smoothed using a 3-point moving average to prevent high-frequency numerical noise. Once you click Play, the wave propagates according to the wave equation, and you can observe reflections, interference patterns, and wave behavior at boundaries.

The simulation supports four different boundary conditions that can be changed in real-time: Fixed (Dirichlet) boundaries create hard reflections that invert the wave, Free (Neumann) boundaries create soft reflections without inversion, Periodic boundaries wrap the wave around, and Absorbing (Mur's first-order) boundaries minimize reflections to simulate an infinite string. You can also adjust the simulation speed to observe the wave dynamics at different rates.

NOTE : The simulation uses the finite difference method with explicit time stepping. The Courant number (C = c·dt/dx) is set to 0.5, which satisfies the stability condition C ≤ 1.0. The wave is visualized on a dark background with a neon cyan-green line, and a faint horizontal line marks the equilibrium position (y = 0).

Math behind the Simulation

The 1D wave equation describes the propagation of waves along a string:

∂²u/∂t² = c² · ∂²u/∂x²

where u(x,t) is the displacement at position x and time t, and c is the wave speed. The simulation uses the finite difference method to discretize this equation. The string is divided into N = 200 points with spacing dx = L/(N-1), and time is discretized with step dt.

The explicit central difference scheme updates each interior point using:

uin+1 = 2uin - uin-1 + C² · (ui+1n - 2uin + ui-1n)

where C = c·dt/dx is the Courant number (set to 0.5 for stability), and superscripts denote time steps. This scheme requires C ≤ 1.0 for numerical stability. Boundary conditions are applied after updating interior points to enforce the desired behavior at the string ends.

 

Usage Example

Follow these steps to explore wave propagation and boundary effects:

  1. Initial State: When you first load the simulation, you're in Drawing mode. The canvas is empty (all displacement is zero). You can either draw a custom wave shape or select a predefined wave type from the dropdown.
  2. Draw or Select a Wave:
    • To draw custom: Click and drag on the canvas to create your initial wave shape. The waveform is automatically smoothed when you release the mouse.
    • To use predefined: Select a wave type (Sine Wave, Gaussian Pulse, Square Wave, etc.) from the dropdown. The wave will appear immediately.
  3. Start the Simulation: Click the "Play" button to start wave propagation. Watch how the wave moves according to the wave equation. Notice how:
    • The wave shape propagates along the string
    • In the 2D plot, you see the current wave state
    • In the 3D waterfall plot, you see the wave evolution over time (newest at front, oldest fading into the background)
  4. Observe Boundary Reflections: Try different boundary conditions and watch how they affect wave behavior:
    • Fixed: Waves reflect with inversion - a positive peak becomes negative upon reflection
    • Free: Waves reflect without inversion - peaks remain peaks
    • Periodic: Waves wrap around, creating continuous motion
    • Absorbing: Waves exit with minimal reflection, simulating an infinite string
  5. Experiment with Wave Speed: Adjust the "Wave Speed (c)" slider. Higher values make waves propagate faster. Notice how the Courant number display updates automatically. Watch how faster waves create more frequent reflections at boundaries.
  6. Study the Waterfall Plot: The 3D waterfall plot shows wave history over time. The origin is positioned lower to provide more vertical space for the time axis. New waves appear at the front (bottom), and older waves fade into the background (top). This visualization helps you see:
    • How wave shapes evolve over time
    • Reflection patterns at boundaries
    • Interference between incoming and reflected waves
  7. Try Different Wave Types: Experiment with different predefined waves:
    • Gaussian Pulse: A single pulse that splits into two waves traveling in opposite directions
    • Sine Wave: A complete sine wave that shows standing wave patterns with fixed boundaries
    • Double Pulse: Two pulses that create complex interference patterns
    • Standing Wave: Demonstrates standing wave patterns with nodes and antinodes
  8. Adjust Simulation Speed: Use the "Speed" slider to control how many simulation steps run per frame. Higher values (5x-10x) let you observe long-term behavior quickly, while lower values (1x) show detailed wave motion. This is useful for studying wave interactions in detail.
  9. Reset and Compare: Click "Reset" to clear the wave and try different scenarios. Compare how the same initial wave behaves with different boundary conditions. Notice how boundary conditions fundamentally change the wave dynamics and create different interference patterns.

Tip: The key insight is to observe how boundary conditions affect wave reflections. With Fixed boundaries, you'll see inverted reflections creating standing wave patterns. With Free boundaries, non-inverted reflections create different interference patterns. The waterfall plot is particularly useful for visualizing how waves evolve and interact over time - watch how reflected waves combine with incoming waves to create complex patterns.

Parameters

Followings are short descriptions on each parameters
  • Wave Speed (c): Controls the physical wave speed parameter c in the wave equation. This determines how fast waves propagate along the string. Higher values (up to 5.0) make waves travel faster, while lower values (down to 0.1) make waves travel slower. When the wave speed changes, the time step dt is automatically adjusted to maintain a constant Courant number (C = 0.5) for numerical stability. Default is 1.0. The Courant number display updates in real-time as you adjust this parameter.
  • Boundary Condition: Selects how the wave behaves at the left and right boundaries of the string. Four options are available:
    • Fixed (Dirichlet): The string is clamped at both ends (u = 0 at boundaries). Waves reflect with inversion - a positive displacement becomes negative upon reflection. This creates hard reflections typical of a string fixed at both ends.
    • Free (Neumann): The string ends are free to move vertically (du/dx = 0 at boundaries). Waves reflect without inversion - a positive displacement remains positive. This creates soft reflections typical of a free end.
    • Periodic: The string wraps around, connecting the left and right ends. Waves that exit one side reappear on the other side. This simulates a circular or ring-shaped string.
    • Absorbing (Mur's): Uses Mur's first-order absorbing boundary condition to minimize reflections. This simulates an infinite string by allowing waves to exit the domain with minimal reflection. The boundary condition accounts for the wave speed to cancel incoming waves.
    The boundary condition can be changed in real-time during simulation to observe different behaviors.
  • Speed: Controls how many simulation steps are performed per frame. Higher values (up to 10x) make the wave propagate faster, while lower values (1x) show the wave at normal speed. This is useful for observing fast-moving waves or slowing down the simulation to study wave interactions in detail. Default is 1x (realtime).
  • Courant Number: A stability parameter defined as C = c·dt/dx, where c is the wave speed, dt is the time step, and dx is the spatial step. The simulation uses C = 0.5, which satisfies the stability condition C ≤ 1.0. This ensures that the wave propagates correctly without numerical artifacts. The Courant number is displayed in the control panel for reference.
  • Grid Resolution: The string is discretized into 200 points (N = 200) for numerical computation. The spatial step size is dx = L/(N-1) where L = 1.0 is the length of the string. Higher resolution would provide smoother waves but requires more computation.
  • Damping: A small damping factor (0.999) is applied to prevent numerical energy accumulation over time. This simulates slight energy loss due to friction or air resistance, ensuring the simulation remains stable over long periods.

Buttons and Controls

Followings are short descriptions on each control
  • Play/Pause: Starts or pauses the wave simulation. When in Drawing mode, clicking Play initializes the simulation with the current drawn waveform. The button text changes to "Pause" during simulation, allowing you to pause and resume at any time. When paused, the mode changes to "Paused" and you can observe the current wave state.
  • Reset: Clears the current wave, stops the simulation, and returns to Drawing mode. All wave arrays are reset to zero, and you can draw a new initial condition. The mode display returns to "Drawing".

Interaction and Visualization

  • Drawing Mode: The initial state of the simulation. Click and drag on the canvas to draw the initial wave shape. The mouse position is converted to grid coordinates, and the displacement is set based on the vertical position relative to the center line. When you release the mouse, the waveform is automatically smoothed using a 3-point moving average to prevent high-frequency numerical noise that could cause instability.
  • Canvas Visualization: The wave is displayed on a dark background (#1a1a1a) with a neon cyan-green line (#00ff88) showing the displacement. A faint horizontal dashed line marks the equilibrium position (y = 0). The wave is drawn as a continuous path connecting all grid points, scaled to fit the canvas dimensions.
  • Real-time Updates: During simulation, the wave updates in real-time using requestAnimationFrame for smooth animation. The number of simulation steps per frame is controlled by the Speed parameter. The mode display shows whether you're in Drawing, Simulating, or Paused mode.
  • Wave Propagation: The wave propagates according to the 1D wave equation using the finite difference method. Interior points are updated using the explicit central difference scheme: u_next[i] = 2*u[i] - u_prev[i] + C²*(u[i+1] - 2*u[i] + u[i-1]). This creates realistic wave motion with proper propagation speed and wave behavior.
  • Boundary Effects: Different boundary conditions create distinct visual effects. Fixed boundaries show inverted reflections, free boundaries show non-inverted reflections, periodic boundaries create continuous wave motion, and absorbing boundaries minimize reflections to simulate an infinite string. You can change boundary conditions during simulation to observe the immediate effect.
  • Initial Conditions: When you draw a waveform and click Play, the previous displacement array (u_prev) is initialized to match the current displacement (u). This implies zero initial velocity, meaning the wave starts from rest with the drawn shape. The wave then evolves according to the wave equation.