Conversation
Add a new example solving the 1D wave equation u_tt = c^2 * u_xx with Dirichlet boundary conditions and initial displacement/velocity conditions. Uses analytical reference data (sin(pi*x)*cos(pi*t)) for validation. Includes: - examples/wave_equation/train.py: PDE residual, initial conditions, boundary conditions, and analytical data generation - examples/wave_equation/configs/config.yaml: Hydra configuration with training parameters - examples/wave_equation/README.md: Problem description and setup
There was a problem hiding this comment.
Pull request overview
Adds a new self-contained 1D wave equation example to the examples/ collection, following the repo’s existing Hydra + pinnstf2.train() example structure and using analytically generated reference data.
Changes:
- Introduces
examples/wave_equation/train.pywith PDE residual, initial/boundary conditions wiring, and analytical reference solution generation. - Adds
examples/wave_equation/configs/config.yamldefining domains, samplers, network architecture, and training settings. - Adds
examples/wave_equation/README.mddocumenting the PDE setup and training configuration table.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/wave_equation/train.py | Implements wave-equation residual and analytical solution generation for mesh-based training/validation. |
| examples/wave_equation/configs/config.yaml | Provides Hydra config for mesh, samplers (collocation/IC/BC), model, and trainer settings. |
| examples/wave_equation/README.md | Documents the PDE, exact solution, and problem setup table for the new example. |
💡 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.
| nx, nt = 256, 201 | ||
| x = np.linspace(0, 1, nx) | ||
| t = np.linspace(0, 1, nt) | ||
| X, T = np.meshgrid(x, t, indexing="ij") | ||
| exact_u = np.sin(np.pi * X) * np.cos(np.pi * C * T) | ||
| return {"u": exact_u} |
There was a problem hiding this comment.
config.yaml requests initial-condition supervision for both u and v, but read_data_fn() only returns {"u": exact_u}. This will raise a KeyError when Mesh.on_initial_boundary() tries to slice self.solution["v"] for the initial condition sampler. Include an analytical v solution array in the returned dict (e.g., v = ∂u/∂t) or adjust the config to avoid requesting v from the mesh solution.
| | 1D Wave Equation | | | ||
| |------------------------------|---| |
There was a problem hiding this comment.
The markdown table is not formatted consistently with other example READMEs: the rows start with || (double pipe), which renders as an extra empty column in many Markdown parsers. Use a standard table format (single leading | per row) like the other examples under examples/*/README.md.
| | 1D Wave Equation | | | |
| |------------------------------|---| | |
| | Quantity | Value | | |
| |------------------------------|-------------------------------| |
Summary
Add a 1D wave equation example to the PINNs-TF2 examples collection.
Problem
The wave equation
u_tt = c^2 * u_xxis one of the fundamental PDEs in physics and engineering, but there is currently no wave equation example in the repository.Solution
This PR adds a complete wave equation example following the existing example structure:
examples/wave_equation/train.py— Defines the PDE residual, initial conditions (displacement and velocity), boundary conditions, and generates analytical reference dataexamples/wave_equation/configs/config.yaml— Hydra configuration with training parametersexamples/wave_equation/README.md— Problem description and setup tableProblem Setup
The example solves:
Exact solution:
u(x,t) = sin(πx) cos(πt)Design Choices
root_dir: null) instead of loading from.matfiles, keeping the example self-contained with no external data dependenciesu) and velocity (v = u_t) initial conditions for the second-order-in-time PDE[2, 50, 50, 50, 50, 50, 1](5 hidden layers of 50 neurons)This mirrors the wave equation example in PINNs-Torch, adapted for the TensorFlow 2 API.