Skip to content

Finite difference solution of 2D Poisson equation. Can handle Dirichlet, Neumann and mixed boundary conditions.

License

Notifications You must be signed in to change notification settings

kli-jfp/Poisson-solver-2D

 
 

Repository files navigation

Poisson-solver-2D

alt text alt text alt text

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 left boundary value)

(Neumann right boundary value)

(Neumann left 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.

Package requirements

  • NumPy
  • SciPy (sparse matrices, sparse linear algebra)

Version notes

  • 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.

Graphically Defined Geometry

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.

Sample Output

Dirichlet boundary conditions at outer walls

Solution of with boundary conditions is shown below:

Dirichlet boundary conditions at outer wall and inner regions

Solution of with boundary conditions is shown below:

Mixed boundary conditions (both Dirichlet and Neumann boundary conditions)

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:

Graphically defined geometry (both Dirichlet and Neumann boundary conditions)

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:

References

About

Finite difference solution of 2D Poisson equation. Can handle Dirichlet, Neumann and mixed boundary conditions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%