Giter Club home page Giter Club logo

poisson-solver-2d's Introduction

Poisson-solver-2D

alt text alt text alt text

Finite difference solution of 2D Poisson equation $\nabla^2u(x,y) = f(x,y)$

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:

$u(x=x_L,y) = u_L$ (Dirichlet left boundary value)

$u(x=x_R,y) = u_R$ (Dirichlet left boundary value)

$u(x,y=y_T) = u_T$ (Dirichlet left boundary value)

$u(x,y=y_B) = u_B$ (Dirichlet left boundary value)

$u(x_l < x < x_h, y_l < y < y_h) = u_b$ (Dirichlet interior boundary value)

$\frac{du}{dx}(x=x_L,y) = u_L$ (Neumann left boundary value)

$\frac{du}{dx}(x=x_R,y) = u_R$ (Neumann right boundary value)

$\frac{du}{dy}(x,y=y_T) = u_T$ (Neumann top boundary value)

$\frac{du}{dy}(x,y=y_B) = u_B$ (Neumann bottom 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.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.

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 $\nabla^2u(x,y) = 0$ with boundary conditions $u(-6,y) = 0.5$, $u(6,y) = 1.2$, $u(x,-3) = -0.75$, $u(x,3) = -1$ is shown below:

Dirichlet boundary conditions at outer wall and inner regions

Solution of $\nabla^2u(x,y) = 0$ with boundary conditions $u(-6,y) = 0.5$, $u(6,y) = 1.2$, $u(x,-3) = -0.75$, $u(x,3) = -1$, $u(1 < x < 1.4, -0.5 < y < 0.2)=1.5$ is shown below:

Mixed boundary conditions (both Dirichlet and Neumann boundary conditions)

Solution of $\nabla^2u(x,y) = 0$ with boundary conditions $\frac{du}{dx}(-6,y) = 0$, $\frac{du}{dx}(6,y) = 0$, $u(x,-3) = 0$, $\frac{du}{dy}(x,3) = 0$, $u(1 < x < 1.4, -0.5 < y < 0.2)=1.5$ (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 $\nabla^2u(x,y) = 0$ 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

poisson-solver-2d's People

Contributors

zaman13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.