The following is a brief summary of the methodology and results of my Masters summer internship at NIT Kurukshetra.
The numerical solution of the Heat Equation plays a crucial role in various scientific and engineering applications. In this study, we implemented Explicit, Implicit, and Crank-Nicholson schemes to solve the Heat Equation and performed a comparative analysis of their computational costs. To efficiently solve the resulting Tri-Diagonal System of Linear Equations (SOLE), we employed the Thomas Algorithm and Sparse Matrix methods, ensuring optimal computational efficiency. The implementation was carried out using Python, with a focus on accuracy, stability, and performance. The comparative results highlight the trade-offs between different schemes in terms of convergence, stability, and computational complexity, providing valuable insights for selecting the most appropriate method for practical applications.
In this section, we present the numerical solution of the one-dimensional heat equation. The heat equation is a fundamental partial differential equation that describes the distribution of temperature in a medium over time. We consider a model with specified initial and boundary conditions.
The governing heat equation is given by:
where:
The problem is solved subject to the following conditions:
These are homogeneous Dirichlet boundary conditions, indicating that the temperature at both ends of the rod remains fixed at zero.
This represents the initial temperature distribution along the domain.
The objective is to determine the temperature distribution \(u(x,t)\) over the spatial domain and time interval using a numerical method such as the Finite Difference Method (FDM).
Consider the one-dimensional heat equation
where \(u(x,t)\) denotes the temperature distribution and \(\alpha\) is the thermal diffusivity coefficient.
Let
The Explicit FTCS method is conditionally stable and requires small time steps for convergence.
The Bender–Schmidt method is a special case of the Explicit scheme obtained by choosing
Substituting into the explicit formula:
The method remains stable only when this condition is satisfied.
There is no restriction on the ratio \( \alpha\Delta t/(\Delta x)^2 \).
The Crank–Nicolson method is obtained by averaging the Explicit and Implicit finite difference schemes.
The method remains stable for all values of \( \lambda \).
| Method | Type | Stability | Condition | Accuracy |
|---|---|---|---|---|
| Explicit (FTCS) | Explicit | Conditional | \(\lambda \le 0.5\) | O(Δt)+O(Δx²) |
| Bender–Schmidt | Explicit | Conditional | \(\lambda=0.5\) | O(Δt)+O(Δx²) |
| BTCS | Implicit | Unconditional | No Restriction | O(Δt)+O(Δx²) |
| Crank–Nicolson | Semi-Implicit | Unconditional | No Restriction | O(Δt²)+O(Δx²) |
The coefficient matrices arising from the BTCS and Crank–Nicolson schemes are highly sparse because only the main diagonal and the two adjacent diagonals contain non-zero entries.
Instead of storing all matrix elements, sparse matrix techniques store only the non-zero values and their indices. This significantly reduces memory consumption and computational overhead.
In Python, sparse matrices can be efficiently represented using libraries such as SciPy:
where the matrix \(A\) is stored in sparse format and solved using optimized sparse linear algebra routines.
The Implicit (BTCS) and Crank–Nicolson finite difference schemes generate a system of linear equations at each time step. The resulting coefficient matrix is tridiagonal, making specialized numerical solvers highly effective. In this project, two approaches are considered:
The Thomas Algorithm is a simplified form of Gaussian Elimination specifically designed for tridiagonal systems of linear equations. Since only three diagonals contain non-zero entries, the algorithm can solve the system efficiently using forward elimination and backward substitution.
The system obtained from the finite difference discretization can be written as:
Equivalently,
For \(i=2,3,\ldots,n\):
This process removes the lower diagonal elements and transforms the matrix into an upper triangular form.
Therefore, the Thomas Algorithm is significantly faster than general dense matrix solvers and is well suited for finite difference discretizations of the heat equation.
For the BTCS scheme:
Thus,
which directly forms a tridiagonal system that can be solved using the Thomas Algorithm.
In large-scale numerical simulations, the coefficient matrix contains a very small number of non-zero entries compared to the total number of elements. Such matrices are known as sparse matrices.
Instead of storing every element, sparse matrix methods store only the non-zero values and their locations, resulting in substantial savings in memory and computational cost.
Only the main diagonal and the two adjacent diagonals contain non-zero values.
Rather than storing all matrix entries, only the following diagonals are stored:
This significantly reduces storage requirements for large systems.
The matrix \(A\) is stored in sparse format while preserving the original mathematical problem.
Sparse matrix methods become increasingly advantageous as the number of spatial grid points increases.
In Python, sparse matrices are commonly stored using CSR (Compressed Sparse Row) or CSC (Compressed Sparse Column) formats. Libraries such as SciPy provide optimized sparse linear algebra routines that solve
by operating only on the non-zero entries of the matrix. Internally, these methods employ sparse LU factorization and highly optimized numerical routines.
Both the Thomas Algorithm and Sparse Matrix Solver solve the same system of equations generated by BTCS and Crank–Nicolson methods. However, their implementations differ significantly.
| Property | Thomas Algorithm | Sparse Matrix Solver |
|---|---|---|
| Matrix Type | Tridiagonal Only | General Sparse Matrix |
| Time Complexity | O(n) | O(n) – O(n log n) |
| Memory Usage | O(n) | O(n) |
| Flexibility | Low | High |
| Large Scale Problems | Good | Excellent |
| Parallelization | Limited | Supported |
Numerical experiments conducted in this project showed that the Sparse Matrix Solver achieved approximately 10× faster execution time compared to the conventional Thomas Algorithm implementation for large grid sizes.
The improvement is mainly due to optimized sparse linear algebra routines, efficient memory access, reduced storage requirements, and highly optimized low-level implementations.
The Thomas Algorithm is an efficient direct solver for tridiagonal systems arising from finite difference discretizations. However, sparse matrix techniques provide greater flexibility and superior performance for large-scale simulations. In this project, the sparse matrix approach demonstrated significantly reduced execution times while maintaining the same numerical accuracy, making it the preferred choice for solving large heat equation problems.
Consider the one-dimensional heat equation
with homogeneous Dirichlet boundary conditions
and initial condition
| Mesh Points N = M |
Error in Solution Calculating by Thomas Algorithm |
Computational Cost (using TA) |
Error in Solution Calculating by Sparse Matrix |
Computational Cost (Using SM) |
|---|---|---|---|---|
| 10 | 0.5811 | 0.0019919872283933547 | 0.4344 | 0.0009987354278564453 |
| 20 | 0.3915 | 0.02094101905822754 | 0.2651 | 0.0009996891021728516 |
| 30 | 0.2390 | 0.06778788566589355 | 0.1619 | 0.0009913444519042969 |
| 40 | 0.14594 | 0.16256427764892578 | 0.0988 | 0.00099135485609412969 |