This project is an interactive web application built with Python and Streamlit that simulates the one-dimensional time-dependent advection equation. It serves as a pedagogical tool to visualize and compare various finite-difference numerical schemes against the exact analytical solution.
The application allows users to modify simulation parameters in real-time—such as the Courant number, spatial resolution, and wave velocity—to observe how different discretization methods handle stability, dissipation, and dispersion.
The simulator solves the linear advection equation, a partial differential equation (PDE) that describes the transport of a quantity (scalar field
Where:
-
$u(x,t)$ is the scalar field being advected. -
$v$ is the constant velocity.
-
Interactive Simulation Controls: Adjust Domain Length (
$L$ ), Advection Velocity ($v$ ), Simulation Time ($T$ ), and Spatial Resolution ($N_x$ ). -
Courant Number Analysis: Dynamically adjust the Courant-Friedrichs-Lewy (CFL) condition (
$C = v \frac{dt}{dx}$ ) to observe stability limits. -
Multiple Initial Conditions:
- Gaussian Bell
- Square Pulse
- Triangle Wave
- Cosine Hat
-
Numerical Schemes: The application implements and compares the following schemes:
- Exact Solution (Analytical)
- Forward Euler Centered Space (FECS)
- Upwind Scheme
- Leapfrog Scheme
- Lax-Wendroff Scheme
- Crank-Nicolson (Implicit)
- Backward Euler (Implicit)
-
Visualizations:
- Animated wave propagation (Plotly).
- Space-Time (Hovmöller) heatmaps for every solver.
- Mass conservation integrals to analyze numerical dissipation and instability.
Ensure you have Python 3.8+ installed.
-
Clone the repository:
git clone https://github.com/hsannav/advection-simulator.git cd advection-simulator -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the Streamlit application:
streamlit run app.py
app.py: The main application script containing the PDE solvers and Streamlit interface.requirements.txt: List of Python dependencies.README.md: Project documentation.
This project demonstrates the behavior of different discretization strategies:
- FECS: Unconditionally unstable.
-
Upwind: First-order accurate, stable if
$C \leq 1$ , but diffusive. - Leapfrog: Second-order accurate, non-dissipative, but dispersive.
- Lax-Wendroff: Second-order accurate, minimizes dissipation compared to Upwind.
- Implicit Schemes (CN, BE): Unconditionally stable, requiring matrix inversion at each time step.
- Fernando Blanco
- Hugo Sánchez