This project implements a numerical solver for the 2D stationary heat diffusion equation on a rectangular domain. It uses the Finite Difference Method (FDM) to discretize the Partial Differential Equation (PDE) into a sparse linear system, which is then solved efficiently.
A key feature is the custom implementation of 2D quadratic spline interpolation, built from scratch using successive 1D row and column interpolations. The coefficients for these splines are calculated using a custom QR factorization algorithm (via modified Gram-Schmidt), also implemented from scratch.
The solver is validated against an analytical solution to analyze convergence rates across different grid densities.
- Finite Difference Method (FDM): Discretizes the 2D PDE with variable diffusion coefficients into a large, sparse linear system.
- Custom Spline Interpolation: Implements 2D quadratic spline interpolation from scratch to reconstruct a continuous solution from discrete grid points.
- QR Factorization from Scratch: Solves the linear systems for spline coefficients using a custom-built QR decomposition algorithm.
- Sparse Matrix Operations: Utilizes
scipy.sparsefor efficient storage and solution of the large linear systems arising from FDM. - Error & Convergence Analysis: Automatically compares numerical results with an analytical solution, plotting error surfaces and calculating convergence rates.
The solver addresses the stationary heat diffusion equation:
-
Dirichlet Boundary Conditions: On
$y=0$ and$y=2$ . -
Neumann Boundary Conditions: On
$x=0$ and$x=5$ .
- NumPy: For numerical operations and dense matrix handling in the QR solver.
- SciPy: Specifically
scipy.sparseandscipy.sparse.linalg.spsolvefor handling the main FDM linear system. - Matplotlib: For 3D visualization of solutions and error surfaces, and 2D convergence plots.
- Ensure you are in the root directory of the project:
pip install -r requirements.txt
- Run the main script:
python main.py
The script will sequentially solve the problem for grid sizes