This project studies the modeling of air pollution using the advection-diffusion equation in a bounded two-dimensional domain. We implement and compare two numerical methods for solving time-dependent advection-diffusion equations:
- Physics-Informed Neural Networks (PINN): A deep learning approach where a neural network is trained to satisfy the PDE, initial conditions, and boundary conditions
- Crouzeix-Raviart Finite Element Method (CRBE): A classical finite element approach using Crouzeix-Raviart elements and a Backward Euler time-stepping scheme
The project solves the 2D advection-diffusion equation:
where:
-
$c(x,y,t)$ is the concentration field -
$\mathbf v$ is the velocity field -
$D$ is the diffusion coefficient -
$s(x,y,t)$ is the source term
The equation is solved subject to appropriate initial and boundary conditions in a bounded 2D domain.
- Dual Implementation Approach:
- CRBE implementation for 2D advection-diffusion problems
- PINN implementation for 2D advection-diffusion problems
- Advanced Meshing: Mesh generation for FEM using the Gmsh Python API
- Smart Sampling: Latin Hypercube Sampling for generating collocation points in PINNs
- Systematic Experimentation: Automated experiment scripts (
crbe_experiments.py,pinn_experiments.py) for comprehensive method comparison - Comprehensive Analysis: Solution visualization, L2 error analysis, and maximum error computation
- Optimized Training: Early stopping and learning rate scheduling for PINN training
- Flexible Architecture: Support for different activation functions in PINN (Tanh, Sine, Swish)
- Performance Monitoring: Memory usage and timing analysis for both methods
AirPollution/
├── crbe.py # Crouzeix-Raviart Finite Element implementation
├── pinn.py # Physics-Informed Neural Network implementation
├── experiments/
│ ├── crbe_experiments.py # CRBE systematic experiments
│ ├── pinn_experiments.py # PINN systematic experiments
│ ├── sensitivity_analysis.py # Parameter sensitivity analysis
│ └── fixed_runtime_experiments.py # Fixed runtime comparison
├── requirements.txt # Python dependencies
├── README.md # This file
├── experimental_results/ # Generated files with experiment results
└── results/ # Generated plots from individual solver runs
PINNs leverage deep neural networks to approximate the solution of PDEs. The network takes spatio-temporal coordinates
- PDE Residual: Evaluated over a set of collocation points in the domain
- Initial Condition Error: Ensures proper initial state satisfaction
- Boundary Condition Error: Enforces boundary constraints
Key Components:
Problem: Defines the initial, boundary conditions, and source term using Numpy arrays and/or PyTorch tensorsDomain: Specifies the physical domain parametersPINN: Defines the neural network architecture, PDE residual computation, and training loopEarlyStopping: Utility to prevent overfitting- Helper functions for Latin Hypercube Sampling and automatic differentiation
The CRBE approach discretizes the spatial domain using a uniform triangular mesh. The concentration variable is approximated by piecewise linear functions that are continuous at the midpoints of element edges (Crouzeix-Raviart elements). A Backward Euler scheme provides temporal discretization.
Key Components:
create_mesh(): Generates structured triangular meshes usinggmshProblem: Defines the initial, boundary conditions, and source term using Numpy arrays and/or PyTorch tensorsDomain: Specifies physical domain parametersMeshData: Stores and processes mesh informationElementCR: Defines Crouzeix-Raviart reference element propertiesBESCRFEM: Implements the complete Backward Euler Scheme with matrix assembly and error computation
- Python Version: 3.8+
- Key Dependencies:
torch>=1.9.0(PyTorch for PINN implementation)numpy>=1.21.0matplotlib>=3.4.0scipy>=1.7.0gmsh>=4.8.0(mesh generation)pyDOE(for Latin Hypercube Sampling)
-
Clone the repository:
git clone https://github.com/clemsadand/AirPollution.git cd AirPollution -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate -
Install system dependencies:
sudo apt-get update sudo apt-get install -y libglu1-mesa # Additional packages for gmsh -
Install Python dependencies:
pip install -r requirements.txt
Note on Gmsh: This project uses gmsh for mesh generation. If you encounter installation issues via pip, please refer to the official Gmsh website for system-specific installation instructions.
Both solvers can be run directly to solve a default problem and generate solution plots:
python crbe.pyThis generates a mesh, solves the advection-diffusion problem, prints error metrics, and saves solution plots in the results/ directory.
python pinn.pyThis trains the PINN, evaluates it on a validation mesh, plots training history, and saves solution plots in the results/ directory. Note that PINN training can be computationally intensive.
The experiment scripts automate running the solvers with different configurations:
python -m experiments.pinn_experiments --width=4 --epochs=0 --activation=tanh --restore_best_weights=True- Trains PINNs with different network architectures and evaluation mesh sizes
- Setting
epochs=0uses default values optimized for each mesh size - Results saved to
experimental_results/pinn/
python -m experiments.crbe_experiments- Runs CRBE solver for various mesh sizes
- Results saved to
experimental_results/crbe/
python -m experiments.sensitivity_analysis --width=4 --epochs=0 --activation=tanh- Analyzes parameter sensitivity for both methods
- Results saved to
experimental_results/sensitivity/
python -m experiments.fixed_runtime_experiments- Compares methods under fixed computational budgets
- Results saved to
experimental_results/fixed_runtime/
The project validates both methods against analytical solutions. Typical performance characteristics:
- CRBE: O(h²) convergence rate in space, robust for various mesh sizes
- PINN: Highly dependent on network architecture and training parameters, can achieve spectral accuracy with sufficient training
Error metrics include L2 norm and maximum absolute error computed over the entire spatio-temporal domain.
- Network Architecture: Fully connected layers with configurable width
- Activation Functions: Tanh (default), Sine, Swish
- Training: Adam optimizer with learning rate scheduling
- Collocation Points: Latin Hypercube Sampling for optimal coverage
- Element Type: Crouzeix-Raviart (non-conforming linear elements)
- Time Stepping: Backward Euler (first-order implicit) or Cranck-Nicolson (second-order implicit)
- Mesh Generation: Structured triangular meshes via Gmsh
This project is available under the MIT License.
- Raissi, M., Perdikaris, P., & Karniadakis, G. E. (2019). Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations. Journal of Computational Physics, 378, 686-707.
- Crouzeix, M., & Raviart, P. A. (1973). Conforming and nonconforming finite element methods for solving the stationary Stokes equations I. Revue française d'automatique, informatique, recherche opérationnelle, 7(3), 33-75.