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:
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.
- Browse the Code folder and download all files in the latest version sub-folder
- Make sure all the files are in the same folder
- Run the Poisson_2D_v###.py file to test that the code is working
- Make edits on the files to define the necessary geometry and boundary conditions for the specific problem and rerun the code
No additional installations are needed.
-
version 1.5.2
- Created geo_source_definition file. Geometry and source definition functions have been moved there
- Created utilities_definition file. Moved the plotting (and color) definition functions there
-
version 1.5
- Generalized the boundary definition process. A separate function file is used to find all the outer and inner boundary indices. All boundary quantities are in list form. This makes it easier to implement all the boundary operations in one go (rather than treating each boundary separately).
-
version 1.4.4
- Fixed aliasing problem in contour plot export
-
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
Solution of
Solution of
Solution
Center circular region:
Left and right circular region:
Left and right rectangular region:
All the outer boundaries have Neumann boundary conditions:
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