Finite difference solution of 2D Poisson equation
Detials about the work can be found in the following tutorial paper:
Zaman, M.A. "Numerical Solution of the Poisson Equation Using Finite Difference Matrix Operators", Electronics 2022, 11, 2365. https://doi.org/10.3390/electronics11152365
Current version can handle Dirichlet, Neumann, and mixed (combination of Dirichlet and Neumann) boundary conditions:
(Dirichlet left boundary value)
(Dirichlet right boundary value)
(Dirichlet top boundary value)
(Dirichlet bottom boundary value)
(Dirichlet interior boundary value)
(Neumann right boundary value)
(Neumann right boundary value)
The boundary values themselves can be functions of (x,y). In addition to the boundaries being at the edge of the solution domain, boundary values imposed on interior regions (i.e. regions surrounded by points where the equation is to be solved) can be also be solved using this code.
-
version 1.3
- It is now possible to apply Neumann and mixed boundary conditions
-
version 1.2
- It is now possible to define arbitrary Dirichlet boundary points at the interior of the solution domain
-
version 1.1
- Fixed a bug regarding the right-hand function
- Figure size and font size adjusted
-
version 1.0 notes
- Sparse matrix implementation. CSR format (Compressed sparse row matrix) matrix.
In addition to algebraically defining the solution domain and the boundary regions, it is possible to import the geometry from bitmap image (bmp) file. Differere colors in the bmp file are taken as different regions (i.e. Dirichlet boundary 1, Direchlet boundary 2, solution domain, Neumann boundary etc.). The different regions can be handled appropriately by defining the color mapping in the code. This feature can be useful when working with complex geometries that are difficult/cumbersome to define algebraically.
Solution of with boundary conditions is shown below:
Solution of with boundary conditions is shown below:
Solution of with boundary conditions (Dirichlet boundary condition on the left wall and in the region 1<x<1.4, -0.5<y<0.2. Neumann boundary conditions on the right, top and bottom walls.) is shown below:
Solution of with the following boundary conditions:
Center circular region: u = 1
Left and right circular region: u = -2
Left and right rectangular region: u = 2
All the outer boundaries have Neumann boundary conditions: du/dx = 0 (left and right boundary), du/dy = 0 (top and bottom boundary)
The results are shown below:
- Zaman, M.A. "Numerical Solution of the Poisson Equation Using Finite Difference Matrix Operators", Electronics 2022, 11, 2365. https://doi.org/10.3390/electronics11152365
- Sparse matrices: https://docs.scipy.org/doc/scipy/reference/sparse.html
- Sparse matrix linear algebra: https://docs.scipy.org/doc/scipy/reference/sparse.linalg.html