Skip to content

Add wave equation PINN example#52

Open
gpartin wants to merge 1 commit intoboschresearch:mainfrom
gpartin:feature/add-wave-equation-example
Open

Add wave equation PINN example#52
gpartin wants to merge 1 commit intoboschresearch:mainfrom
gpartin:feature/add-wave-equation-example

Conversation

@gpartin
Copy link
Copy Markdown

@gpartin gpartin commented Mar 11, 2026

Summary

Adds a Jupyter notebook example demonstrating how to solve the 1D wave equation using TorchPhysics:

feature/add-wave-equation-example\frac{\partial^2 u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2}feature/add-wave-equation-example

The wave equation is fundamental in physics and engineering (acoustics, electromagnetics, seismology), but the current examples don't include one. This fills that gap.

What's included

  • examples/pinn/wave-equation.ipynb: Complete notebook with:
    • Problem definition (fixed-end string with sinusoidal IC)
    • PDE residual using tp.utils.grad for second derivatives
    • Dirichlet boundary conditions (fixed ends)
    • Initial displacement and velocity conditions
    • Training with pytorch-lightning
    • Animation of the learned solution
    • Quantitative comparison with analytical solution

Problem setup

  • Domain: x in [0, 1], t in [0, 1], wave speed c = 1
  • BCs: u(0,t) = u(1,t) = 0 (fixed ends)
  • ICs: u(x,0) = sin(pi*x), u_t(x,0) = 0
  • Analytical solution: u(x,t) = sin(pix) cos(pit)

Technical notes

  • Follows the same structure as the heat-equation example
  • Uses NormalizationLayer for stable training
  • Four PINNConditions: PDE residual, boundary, initial displacement, initial velocity
  • The wave equation requires enforcing the initial velocity separately since it's a second-order PDE in time

Add a Jupyter notebook demonstrating how to solve the 1D wave equation
using the PINN approach with TorchPhysics. The example solves:

  u_tt = c^2 * u_xx

on [0,1] x [0,1] with fixed-end boundary conditions and a sinusoidal
initial displacement. Includes PDE residual, boundary conditions,
initial displacement and velocity conditions, training with
pytorch-lightning, animation of learned solution, and comparison
with the analytical solution.
Copilot AI review requested due to automatic review settings March 11, 2026 19:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants