omega-source-v2-15s.mp4
WavePDE is a Python project that simulates and animates the wave equation in one or two dimensions. Users can customize various parameters, including domain size, grid resolution, wave speed, boundary conditions, initial conditions, and more.
- Supports both 1D and 2D wave equations.
- Customizable domain size and grid resolution.
- Adjustable wave speed and time step.
- Different boundary conditions, Dirichlet and Neumann.
- Custom initial conditions and velocity profiles.
- Option to save the animation as a video file.
- Python 3.12 or higher
- numpy
- matplotlib
- argparse
-
Clone the repository:
git clone https://github.com/salastro/wavepde.git cd wavepde
-
Install the required packages:
pip install -e .
Run the script with desired parameters from the command line:
wavepde.py [OPTIONS]
--dim
: Dimension of the wave equation (1 or 2). Default is2
.-a
: Length of the domain. Default is1
.-n
: Number of grid points along each axis. Default is50
.-c
: Wave speed. Default is1
.-t
: Factor for calculating the time step. Default issqrt(2)
.-T
: Final time for the simulation. Default is1
.-f
: Initial condition as a string expression. Default is"np.zeros_like(x)"
.-g
: Initial velocity condition as a string expression. Default is"np.zeros_like(x)"
.--bndry
: Boundary condition for 2D simulations (dirichlet
orneumann
). Default isneumann
.--source
: Amplitude and angular frequency of the source for 2D simulations. Default is[0.5, 2]
.--video
: Name of the video file to save the animation. If not provided, the animation will be displayed instead.
To run a 2D wave simulation with default settings:
wavepde --dim 2
To run a 1D wave simulation with custom initial conditions and save the
animation as wave1d.mp4
:
wavepde --dim 1 -f "np.sin(np.pi * x)" -g "np.zeros_like(x)" --source 0 --video wave1d.mp4
src/wavepde/
: Main package directory.Plot.py
: ContainsWave1DAnim
andWave2DAnim
classes for animating the simulations.Wave.py
: ContainsWave1D
andWave2D
classes for setting up the wave equations.
main.py
: Main script for running the simulations and animations.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or improvements. Remember to follow the Contribution guidelines.
If you encounter any problems or have any suggestions, please open an issue along with a detailed description.
This project is licensed under the MIT License. See the LICENSE file for details.