Conversation
Add a KleinGordon stepper for the relativistic wave equation uₜₜ = c² Δu - m² u, using the same spectral diagonalization approach as the Wave stepper. Key differences from Wave: - Uses Klein-Gordon dispersion: ω(k) = √(c²|k|² + m²) - Has mass gap: no modes with ω < m exist - DC mode (k=0) is diagonalizable when m > 0 (ω(0) = m) - Setting mass=0 recovers the standard wave equation Files: - exponax/stepper/_klein_gordon.py: KleinGordon stepper class - exponax/stepper/__init__.py: Updated exports - tests/test_builtin_solvers.py: Added to instantiation tests
There was a problem hiding this comment.
Pull request overview
Adds a new exponax.stepper.KleinGordon time-stepper implementing the (linear) Klein–Gordon equation via Fourier-space diagonalization, analogous to the existing Wave stepper but with massive dispersion.
Changes:
- Introduces
KleinGordonstepper with dispersion relation ( \omega(k)=\sqrt{c^2|k|^2+m^2} ) and amass=0fallback to Wave’s DC-mode behavior. - Exposes
KleinGordonfromexponax.stepper(__init__.pyimport +__all__). - Adds
KleinGordonto the built-in solver instantiation smoke test list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| exponax/stepper/_klein_gordon.py | New Klein–Gordon stepper implementing spectral diagonalization + DC handling when mass=0. |
| exponax/stepper/init.py | Exports KleinGordon and adds brief module doc mention. |
| tests/test_builtin_solvers.py | Ensures KleinGordon can be instantiated across spatial dimensions. |
💡 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.
| ex.stepper.Wave, | ||
| ex.stepper.KleinGordon, | ||
| ex.stepper.Burgers, |
There was a problem hiding this comment.
KleinGordon is only covered by the generic instantiation smoke test here. Since this is a new solver with nontrivial Fourier-space diagonalization and a documented compatibility guarantee (mass=0 should recover Wave), please add solver-specific tests (e.g., output shape/finite checks and a numerical equivalence test against Wave when mass=0, plus at least one basic behavior/energy or boundedness check similar to tests/test_wave.py).
| The KleinGordon stepper extends the Wave stepper with a mass term, using the | ||
| Klein-Gordon dispersion relation ω(k) = √(c²|k|² + m²). Setting m=0 recovers | ||
| the wave equation. |
There was a problem hiding this comment.
This new paragraph documents KleinGordon, but the earlier “The concrete PDE steppers are:” list in the same module docstring still omits it. Please update that list to include KleinGordon so the public-facing documentation remains consistent.
|
Hi, First, a quick question: Are you an AI agent? |
|
Hi @Ceyron, thanks for the interest! Yes, this PR was drafted with AI assistance (GitHub Copilot) but I reviewed and tested everything manually. The Klein-Gordon stepper follows the same spectral architecture as your existing Wave stepper — I verified numerical equivalence when mass=0. I'll address the Copilot reviewer's suggestions:
Should have those pushed shortly. |
|
Hi @Ceyron, thanks for the interest! Yes, this PR was drafted with AI assistance (GitHub Copilot) but I reviewed and tested everything manually. The Klein-Gordon stepper follows the same spectral architecture as your existing Wave stepper -- I verified numerical equivalence when mass=0. I'll address the Copilot reviewer's suggestions:
Should have those pushed shortly. |
- Add test_klein_gordon.py with dedicated solver tests: - Instantiation and output shape checks - mass=0 recovers Wave stepper (numerical equivalence) - Analytical standing-mode correctness - Mass gap test (k=0 oscillates at omega=m) - Energy conservation bounds - Update stepper list in __init__.py docstring to include KleinGordon
|
Thanks again for your interest in extending the library. Unfortunately, I do not have the resources to review AI-generated Pull Requests, and it seems suspicious to me that you have opened many Pull Requests across various physics-based DL repositories (all of them related to the wave equation or modifications of it):
Thanks for understanding 😊 |
Summary
Adds a \KleinGordon\ stepper for the relativistic wave equation:
2>&1u_{tt} = c^2 \Delta u - m^2 u2>&1
This fills the gap between the existing \Wave\ stepper (massless, ω = c|k|) and more complex nonlinear equations. The Klein-Gordon equation is fundamental to quantum field theory, relativistic physics, and lattice field simulations.
Implementation
Uses the same spectral diagonalization approach as the \Wave\ stepper, extended to the Klein-Gordon dispersion relation:
2>&1\omega(k) = \sqrt{c^2 |k|^2 + m^2}2>&1
Key differences from \Wave:
Files Changed
Usage
\\python
import exponax as ex
kg = ex.stepper.KleinGordon(
num_spatial_dims=2,
domain_extent=10.0,
num_points=64,
dt=0.1,
speed_of_sound=1.0,
mass=1.0,
)
u_next = kg(u)
\\
Motivation
The exponax library covers parabolic (diffusion, reaction-diffusion), hyperbolic (wave, advection), and mixed (KdV, KS, NS) PDEs. The Klein-Gordon equation is a natural addition to the hyperbolic family — it's the simplest massive wave equation and widely used in physics benchmarks (e.g., PDEBench includes Klein-Gordon as a benchmark problem).