poisson-transform


Namepoisson-transform JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryPoisson Solver in Tranformed 2D Space using Finite Difference
upload_time2024-11-04 20:10:28
maintainerAr-Kareem
docs_urlNone
authorAr-Kareem
requires_python>=3.9.0
licenseNone
keywords poisson solver finite difference transformed space 2d numerical mathematics physics engineering computational science research
VCS
bugtrack_url
requirements build numpy scipy matplotlib sympy nbconvert twine
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Poisson 2D Transform

This is a [finite difference](https://en.wikipedia.org/wiki/Finite_difference_method) solver for [poisson equations](https://en.wikipedia.org/wiki/Poisson%27s_equation) in **curved 2d space**.

Many different poisson solvers exist but few solve for curved-spaces.

This package provides that in a very simple to use interface.

# How to use

### Install
    pip install poisson_transform

### Use

First you specify the following inputs:

- f: The RHS of poisson's equation (as a function that takes input coordinates and outputs a value). If empty will set `f(x, y)=1`.
- g: the Boundary conditions of poisson's equation. If empty will set BCs to Dirichlet.
  - `g` should be a function that takes in coordinates and returns (a, b, g) for the boundary condition such that `a*u + b*∂u/∂n = g` on ∂Ω (boundary of domain) 
    - For example, returning `(1, 0, 0)` sets `u=0` which is a dirichlet conditions on that point.
    - For example, returning `(0, 1, 0)` sets `∂u/∂n=0` which is a neumann conditions on that point.
    - For example, returning `(1, 2, 3)` sets `u + 2*∂u/∂n = 3` on that point.
- Specify the transformation to be used `T_x, T_y` where `x = T_x(ksi)` and `y = T_y(eta)`. `ksi` and `eta` are the identity coordinates: $\xi \in [0, 1]$ and $\eta \in [0, 1]$. If empty then the identity transformation will be used.
  1. To do this, simply obtain the variables `ksi, eta` with the following line `ksi, eta = Transformation.get_ksi_eta()`
  2. Then, define an arbitrary transformation on the unit square `Tx = ksi**2 + 0.75*ksi ; Ty = (1-eta)*(1.25*ksi) + eta*(2.75-ksi)`. This step can be arbitrarily complex and uses `Sympy` under the hood to perform the calculations. See below examples for more complex transformations such as rotated ellipses.
  3. Then, get the `transformation` object to be given to the solver using `transformation = Transformation(ksi, eta, Tx, Ty)`
- Finally, call `solve_and_plot` with the number of point to use for the mesh. 
  - Since the above inputs can be left blank, the simplest use case is `solve_and_plot(Nx=30, Ny=30)` which will solve poisson's equation on the unit square with Dirichlet BCs using a mesh grid of ($30 \times 30$).
  - To provide all the above inputs, simply write `solve_and_plot(Nx=29, Ny=29, transformation=transformation, f=f, g=g)`

See below for example uses.

Note: This package has not been tested extensively. If you find an issue please report it (or make a pull-request if fixed)

# Examples


```python
from poisson_transform import solve_and_plot
solve_and_plot(Nx=30, Ny=30)
```

    22:54:15 Warning: both f and g are None. Are you sure this is what you want?
    22:54:15 f is None. Setting f=1
    22:54:15 g is None. Setting Dirichlet BCs 
    22:54:17 Integral: 0.03500889856987609
    


    
![png](./README_files/./README_7_1.png)
    



```python
from poisson_transform import solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    if (x - 0.3)**2 + (y - 0.4)**2 < 0.2**2 :
        return 10
    return 0

solve_and_plot(Nx=31, Ny=31, f=f)
```

    22:54:19 g is None. Setting Dirichlet BCs 
    22:54:21 Integral: 0.06935111999589494
    


    
![png](./README_files/./README_8_1.png)
    



```python
from poisson_transform import solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    if 0.45 < x < 0.55:
        return 10
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if eta == 1:  # top, dirichlet = 0
        return (1, 0, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

solve_and_plot(Nx=31, Ny=31, f=f, g=g)
```

    22:54:24 Integral: 0.0832355038593408
    


    
![png](./README_files/./README_9_1.png)
    



```python
from poisson_transform import Transformation, solve_and_plot, plotGeometry
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    if 0.45 < ksi < 0.55:
        return 100
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if eta == 1:  # top, dirichlet = 0
        return (1, 0, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

ksi, eta = Transformation.get_ksi_eta()
Tx = ksi**2 + 0.75*ksi
Ty = (1-eta)*(1.25*ksi) + eta*(2.75-ksi)
transformation = Transformation(ksi, eta, Tx, Ty)
# plotGeometry(29, 29, transformation)
solve_and_plot(Nx=29, Ny=29, transformation=transformation, f=f, g=g)
```

    22:54:28 Integral: 5.2916463228833726
    


    
![png](./README_files/./README_10_1.png)
    



```python
from poisson_transform import Transformation, plotGeometry, solve_and_plot

ksi, eta = Transformation.get_ksi_eta()
Tx = ksi**2 + 0.1*ksi
Ty = 1/2*ksi*(1-eta) + eta
transformation = Transformation(ksi, eta, Tx, Ty)
plotGeometry(Nx=29, Ny=29, transformation=transformation)
solve_and_plot(Nx=29, Ny=29, transformation=transformation)
```

    22:54:30 Warning: both f and g are None. Are you sure this is what you want?
    22:54:30 f is None. Setting f=1
    22:54:30 g is None. Setting Dirichlet BCs 
    22:54:32 Integral: 0.016063603756651158
    


    
![png](./README_files/./README_11_1.png)
    



    
![png](./README_files/./README_11_2.png)
    



```python
import numpy as np
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    if (0.7 < ksi < 0.8 and 0.6 < eta < 0.7) or (0.3 < ksi < 0.4 and 0.3 < eta < 0.4) or (0.1 < ksi < 0.2 and 0.4 < eta < 0.55):
        return 100
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 1:  # top, dirichlet = 0
        return (1, 0, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

ksi, eta = Transformation.get_ksi_eta()
Tx = ksi
ellipse_bottom = (ksi-0.5)**2 + 0.2
ellipse_top = 1 - ellipse_bottom
Ty = ellipse_bottom*(1-eta) + ellipse_top*eta
rotate_phi = -1.2*np.pi/4
Tx_rot, Ty_rot = np.cos(rotate_phi)*Tx - np.sin(rotate_phi)*Ty, np.sin(rotate_phi)*Tx + np.cos(rotate_phi)*Ty
solve_and_plot(Nx=15, Ny=15, transformation=Transformation(ksi, eta, Tx_rot, Ty_rot), f=f, g=g, contour_levels=20)
```

    22:54:35 Integral: 0.021996048708012562
    


    
![png](./README_files/./README_12_1.png)
    



```python
import importlib
import poisson_transform
importlib.reload(poisson_transform)
import numpy as np
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    # centers = ((0.7, 0.6, 0.1), (0.3, 0.3, 0.1), (0.1, 0.4, 0.1))
    centers = ((0.7, 0.0, 0.1), (0.9, -0.4, 0.1), (0.5, 0.0, 0.1))
    if any((x - xc)**2 + (y - yc)**2 < r**2 for xc, yc, r in centers):
        return 100
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 1:  # top, dirichlet = 0
        return (1, 0, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

ksi, eta = Transformation.get_ksi_eta()
Tx = ksi
ellipse_bottom = (ksi-0.5)**2 + 0.2
ellipse_top = 1 - ellipse_bottom
Ty = ellipse_bottom*(1-eta) + ellipse_top*eta
rotate_phi = -1.2*np.pi/4
Tx_rot, Ty_rot = np.cos(rotate_phi)*Tx - np.sin(rotate_phi)*Ty, np.sin(rotate_phi)*Tx + np.cos(rotate_phi)*Ty
solve_and_plot(Nx=15, Ny=15, transformation=Transformation(ksi, eta, Tx_rot, Ty_rot), f=f, g=g, contour_levels=20)
```

    22:54:37 Integral: 0.20123610428427863
    


    
![png](./README_files/./README_13_1.png)
    



```python
import sympy
from poisson_transform import Transformation, solve_and_plot, plotGeometry
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 1
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if eta == 1:  # top, neumann = 0
        return (0, 1, 0)
    if ksi == 0:  # left, dirichlet = 0
        return (1, 0, 0)
    if ksi == 1:  # right, dirichlet = 0
        return (1, 0, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

ksi, eta = Transformation.get_ksi_eta()
Tx = (2*ksi+0.25-eta)
bottom_curve = 0.5*sympy.Abs(Tx+1e-6)  # add 1e-6 to avoid derivative at kink
Ty = bottom_curve + (1.8 - bottom_curve)*eta
plotGeometry(38, 38, Transformation(ksi, eta, Tx, Ty))
solve_and_plot(Nx=38, Ny=38, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:54:52 Integral: 0.46734117404100667
    


    
![png](./README_files/./README_14_1.png)
    



    
![png](./README_files/./README_14_2.png)
    



```python
import importlib
import poisson_transform
importlib.reload(poisson_transform)
import sympy
from poisson_transform import Transformation, solve_and_plot, plotGeometry
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 1
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if eta == 1:  # top, neumann = 0
        return (0, 1, 0)
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if ksi == 1:  # right, dirichlet = 0
        return (1, 0, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)

ll, cc, hh = 3, 0.5, 1
bb = np.sqrt((1/2*ll - hh + cc)**2 - cc**2)
ksi, eta = Transformation.get_ksi_eta()
Tx = ksi*bb
Ty = cc*ksi*(1-eta)+hh*eta
# plotGeometry(21, 21, Transformation(ksi, eta, Tx, Ty))
solve_and_plot(Nx=38, Ny=38, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:54:57 Integral: 0.06464775169432217
    


    
![png](./README_files/./README_15_1.png)
    



```python
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, dirichlet = 0.5
        return (1, 0, 0.5)
    if ksi == 1:  # right, dirichlet = 1.2
        return (1, 0, 1.2)
    if eta == 0:  # bottom, dirichlet = -0.75
        return (1, 0, -0.75)
    if eta == 1:  # top, dirichlet = -1
        return (1, 0, -1)

ksi, eta = Transformation.get_ksi_eta()
Tx = 12*ksi - 6
Ty = 6*eta - 3
solve_and_plot(Nx=30, Ny=30, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:55:01 Integral: -29.042871607935275
    


    
![png](./README_files/./README_16_1.png)
    



```python
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, dirichlet = 0.5
        return (1, 0, 0.5)
    if ksi == 1:  # right, dirichlet = 1.2
        return (1, 0, 1.2)
    if eta == 0:  # bottom, dirichlet = -0.75
        return (1, 0, -0.75)
    if eta == 1:  # top, dirichlet = -1
        return (1, 0, -1)

    # dirichlet conditions inside the domain
    if 1 < x < 1.4 and -0.5 < y < 0.2:
        return (1, 0, 1.5)

ksi, eta = Transformation.get_ksi_eta()
Tx = 12*ksi - 6
Ty = 6*eta - 3
solve_and_plot(Nx=30, Ny=30, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:55:04 Integral: -11.898317261702779
    


    
![png](./README_files/./README_17_1.png)
    



```python
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 0:  # bottom, dirichlet = 0
        return (1, 0, 0)
    if eta == 1:  # top, neumann = 0
        return (0, 1, 0)

    # dirichlet conditions inside the domain
    if 1 < x < 1.4 and -0.5 < y < 0.2:
        return (1, 0, 1.5)

ksi, eta = Transformation.get_ksi_eta()
Tx = 12*ksi - 6
Ty = 6*eta - 3
solve_and_plot(Nx=50, Ny=50, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:55:10 Integral: 35.2240775563179
    


    
![png](./README_files/./README_18_1.png)
    



```python
from poisson_transform import Transformation, solve_and_plot
def f(x, y, ksi, eta):
    """Returns f for the equation -∇2 u = f in Ω"""
    return 0
def g(x, y, ksi, eta):
    """Returns (a, b, g) for the boundary condition a*u + b*∂u/∂n = g on ∂Ω and (1, 0, g) for dirichlet conditions inside the domain)"""
    if ksi == 0:  # left, neumann = 0
        return (0, 1, 0)
    if ksi == 1:  # right, neumann = 0
        return (0, 1, 0)
    if eta == 0:  # bottom, neumann = 0
        return (0, 1, 0)
    if eta == 1:  # top, neumann = 0
        return (0, 1, 0)

    # dirichlet conditions inside the domain
    if (x)**2 + (y)**2 < 0.4**2:
        return (1, 0, 1)
    elif (x+1.4)**2 + (y)**2 < 0.2**2:
        return (1, 0, -2)
    elif (x-1.4)**2 + (y)**2 < 0.2**2:
        return (1, 0, -2)
    elif -3.5 < x < -2 and -0.25 < y < 0.25:
        return (1, 0, 2)
    elif 2 < x < 3.5 and -0.25 < y < 0.25:
        return (1, 0, 2)

ksi, eta = Transformation.get_ksi_eta()
Tx = 8*ksi - 4
Ty = 8*eta - 4
solve_and_plot(Nx=60, Ny=60, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)
```

    22:55:18 Integral: 64.89227055928428
    


    
![png](./README_files/./README_19_1.png)
    


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "poisson-transform",
    "maintainer": "Ar-Kareem",
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": null,
    "keywords": "poisson, solver, finite difference, transformed space, 2D, numerical, mathematics, physics, engineering, computational, science, research",
    "author": "Ar-Kareem",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/13/b1/01fc29d54f1cc138455196df3f24d047b6e309b00db6983f4e309e68808a/poisson_transform-0.2.2.tar.gz",
    "platform": null,
    "description": "# Poisson 2D Transform\r\n\r\nThis is a [finite difference](https://en.wikipedia.org/wiki/Finite_difference_method) solver for [poisson equations](https://en.wikipedia.org/wiki/Poisson%27s_equation) in **curved 2d space**.\r\n\r\nMany different poisson solvers exist but few solve for curved-spaces.\r\n\r\nThis package provides that in a very simple to use interface.\r\n\r\n# How to use\r\n\r\n### Install\r\n    pip install poisson_transform\r\n\r\n### Use\r\n\r\nFirst you specify the following inputs:\r\n\r\n- f: The RHS of poisson's equation (as a function that takes input coordinates and outputs a value). If empty will set `f(x, y)=1`.\r\n- g: the Boundary conditions of poisson's equation. If empty will set BCs to Dirichlet.\r\n  - `g` should be a function that takes in coordinates and returns (a, b, g) for the boundary condition such that `a*u + b*\u2202u/\u2202n = g` on \u2202\u03a9 (boundary of domain) \r\n    - For example, returning `(1, 0, 0)` sets `u=0` which is a dirichlet conditions on that point.\r\n    - For example, returning `(0, 1, 0)` sets `\u2202u/\u2202n=0` which is a neumann conditions on that point.\r\n    - For example, returning `(1, 2, 3)` sets `u + 2*\u2202u/\u2202n = 3` on that point.\r\n- Specify the transformation to be used `T_x, T_y` where `x = T_x(ksi)` and `y = T_y(eta)`. `ksi` and `eta` are the identity coordinates: $\\xi \\in [0, 1]$ and $\\eta \\in [0, 1]$. If empty then the identity transformation will be used.\r\n  1. To do this, simply obtain the variables `ksi, eta` with the following line `ksi, eta = Transformation.get_ksi_eta()`\r\n  2. Then, define an arbitrary transformation on the unit square `Tx = ksi**2 + 0.75*ksi ; Ty = (1-eta)*(1.25*ksi) + eta*(2.75-ksi)`. This step can be arbitrarily complex and uses `Sympy` under the hood to perform the calculations. See below examples for more complex transformations such as rotated ellipses.\r\n  3. Then, get the `transformation` object to be given to the solver using `transformation = Transformation(ksi, eta, Tx, Ty)`\r\n- Finally, call `solve_and_plot` with the number of point to use for the mesh. \r\n  - Since the above inputs can be left blank, the simplest use case is `solve_and_plot(Nx=30, Ny=30)` which will solve poisson's equation on the unit square with Dirichlet BCs using a mesh grid of ($30 \\times 30$).\r\n  - To provide all the above inputs, simply write `solve_and_plot(Nx=29, Ny=29, transformation=transformation, f=f, g=g)`\r\n\r\nSee below for example uses.\r\n\r\nNote: This package has not been tested extensively. If you find an issue please report it (or make a pull-request if fixed)\r\n\r\n# Examples\r\n\r\n\r\n```python\r\nfrom poisson_transform import solve_and_plot\r\nsolve_and_plot(Nx=30, Ny=30)\r\n```\r\n\r\n    22:54:15 Warning: both f and g are None. Are you sure this is what you want?\r\n    22:54:15 f is None. Setting f=1\r\n    22:54:15 g is None. Setting Dirichlet BCs \r\n    22:54:17 Integral: 0.03500889856987609\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_7_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    if (x - 0.3)**2 + (y - 0.4)**2 < 0.2**2 :\r\n        return 10\r\n    return 0\r\n\r\nsolve_and_plot(Nx=31, Ny=31, f=f)\r\n```\r\n\r\n    22:54:19 g is None. Setting Dirichlet BCs \r\n    22:54:21 Integral: 0.06935111999589494\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_8_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    if 0.45 < x < 0.55:\r\n        return 10\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 1:  # top, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nsolve_and_plot(Nx=31, Ny=31, f=f, g=g)\r\n```\r\n\r\n    22:54:24 Integral: 0.0832355038593408\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_9_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, solve_and_plot, plotGeometry\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    if 0.45 < ksi < 0.55:\r\n        return 100\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 1:  # top, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = ksi**2 + 0.75*ksi\r\nTy = (1-eta)*(1.25*ksi) + eta*(2.75-ksi)\r\ntransformation = Transformation(ksi, eta, Tx, Ty)\r\n# plotGeometry(29, 29, transformation)\r\nsolve_and_plot(Nx=29, Ny=29, transformation=transformation, f=f, g=g)\r\n```\r\n\r\n    22:54:28 Integral: 5.2916463228833726\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_10_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, plotGeometry, solve_and_plot\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = ksi**2 + 0.1*ksi\r\nTy = 1/2*ksi*(1-eta) + eta\r\ntransformation = Transformation(ksi, eta, Tx, Ty)\r\nplotGeometry(Nx=29, Ny=29, transformation=transformation)\r\nsolve_and_plot(Nx=29, Ny=29, transformation=transformation)\r\n```\r\n\r\n    22:54:30 Warning: both f and g are None. Are you sure this is what you want?\r\n    22:54:30 f is None. Setting f=1\r\n    22:54:30 g is None. Setting Dirichlet BCs \r\n    22:54:32 Integral: 0.016063603756651158\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_11_1.png)\r\n    \r\n\r\n\r\n\r\n    \r\n![png](./README_files/./README_11_2.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nimport numpy as np\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    if (0.7 < ksi < 0.8 and 0.6 < eta < 0.7) or (0.3 < ksi < 0.4 and 0.3 < eta < 0.4) or (0.1 < ksi < 0.2 and 0.4 < eta < 0.55):\r\n        return 100\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 1:  # top, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = ksi\r\nellipse_bottom = (ksi-0.5)**2 + 0.2\r\nellipse_top = 1 - ellipse_bottom\r\nTy = ellipse_bottom*(1-eta) + ellipse_top*eta\r\nrotate_phi = -1.2*np.pi/4\r\nTx_rot, Ty_rot = np.cos(rotate_phi)*Tx - np.sin(rotate_phi)*Ty, np.sin(rotate_phi)*Tx + np.cos(rotate_phi)*Ty\r\nsolve_and_plot(Nx=15, Ny=15, transformation=Transformation(ksi, eta, Tx_rot, Ty_rot), f=f, g=g, contour_levels=20)\r\n```\r\n\r\n    22:54:35 Integral: 0.021996048708012562\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_12_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nimport importlib\r\nimport poisson_transform\r\nimportlib.reload(poisson_transform)\r\nimport numpy as np\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    # centers = ((0.7, 0.6, 0.1), (0.3, 0.3, 0.1), (0.1, 0.4, 0.1))\r\n    centers = ((0.7, 0.0, 0.1), (0.9, -0.4, 0.1), (0.5, 0.0, 0.1))\r\n    if any((x - xc)**2 + (y - yc)**2 < r**2 for xc, yc, r in centers):\r\n        return 100\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 1:  # top, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = ksi\r\nellipse_bottom = (ksi-0.5)**2 + 0.2\r\nellipse_top = 1 - ellipse_bottom\r\nTy = ellipse_bottom*(1-eta) + ellipse_top*eta\r\nrotate_phi = -1.2*np.pi/4\r\nTx_rot, Ty_rot = np.cos(rotate_phi)*Tx - np.sin(rotate_phi)*Ty, np.sin(rotate_phi)*Tx + np.cos(rotate_phi)*Ty\r\nsolve_and_plot(Nx=15, Ny=15, transformation=Transformation(ksi, eta, Tx_rot, Ty_rot), f=f, g=g, contour_levels=20)\r\n```\r\n\r\n    22:54:37 Integral: 0.20123610428427863\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_13_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nimport sympy\r\nfrom poisson_transform import Transformation, solve_and_plot, plotGeometry\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 1\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if eta == 1:  # top, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 0:  # left, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if ksi == 1:  # right, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = (2*ksi+0.25-eta)\r\nbottom_curve = 0.5*sympy.Abs(Tx+1e-6)  # add 1e-6 to avoid derivative at kink\r\nTy = bottom_curve + (1.8 - bottom_curve)*eta\r\nplotGeometry(38, 38, Transformation(ksi, eta, Tx, Ty))\r\nsolve_and_plot(Nx=38, Ny=38, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:54:52 Integral: 0.46734117404100667\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_14_1.png)\r\n    \r\n\r\n\r\n\r\n    \r\n![png](./README_files/./README_14_2.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nimport importlib\r\nimport poisson_transform\r\nimportlib.reload(poisson_transform)\r\nimport sympy\r\nfrom poisson_transform import Transformation, solve_and_plot, plotGeometry\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 1\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if eta == 1:  # top, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 1:  # right, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n\r\nll, cc, hh = 3, 0.5, 1\r\nbb = np.sqrt((1/2*ll - hh + cc)**2 - cc**2)\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = ksi*bb\r\nTy = cc*ksi*(1-eta)+hh*eta\r\n# plotGeometry(21, 21, Transformation(ksi, eta, Tx, Ty))\r\nsolve_and_plot(Nx=38, Ny=38, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:54:57 Integral: 0.06464775169432217\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_15_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, dirichlet = 0.5\r\n        return (1, 0, 0.5)\r\n    if ksi == 1:  # right, dirichlet = 1.2\r\n        return (1, 0, 1.2)\r\n    if eta == 0:  # bottom, dirichlet = -0.75\r\n        return (1, 0, -0.75)\r\n    if eta == 1:  # top, dirichlet = -1\r\n        return (1, 0, -1)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = 12*ksi - 6\r\nTy = 6*eta - 3\r\nsolve_and_plot(Nx=30, Ny=30, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:55:01 Integral: -29.042871607935275\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_16_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, dirichlet = 0.5\r\n        return (1, 0, 0.5)\r\n    if ksi == 1:  # right, dirichlet = 1.2\r\n        return (1, 0, 1.2)\r\n    if eta == 0:  # bottom, dirichlet = -0.75\r\n        return (1, 0, -0.75)\r\n    if eta == 1:  # top, dirichlet = -1\r\n        return (1, 0, -1)\r\n\r\n    # dirichlet conditions inside the domain\r\n    if 1 < x < 1.4 and -0.5 < y < 0.2:\r\n        return (1, 0, 1.5)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = 12*ksi - 6\r\nTy = 6*eta - 3\r\nsolve_and_plot(Nx=30, Ny=30, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:55:04 Integral: -11.898317261702779\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_17_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 0:  # bottom, dirichlet = 0\r\n        return (1, 0, 0)\r\n    if eta == 1:  # top, neumann = 0\r\n        return (0, 1, 0)\r\n\r\n    # dirichlet conditions inside the domain\r\n    if 1 < x < 1.4 and -0.5 < y < 0.2:\r\n        return (1, 0, 1.5)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = 12*ksi - 6\r\nTy = 6*eta - 3\r\nsolve_and_plot(Nx=50, Ny=50, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:55:10 Integral: 35.2240775563179\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_18_1.png)\r\n    \r\n\r\n\r\n\r\n```python\r\nfrom poisson_transform import Transformation, solve_and_plot\r\ndef f(x, y, ksi, eta):\r\n    \"\"\"Returns f for the equation -\u22072 u = f in \u03a9\"\"\"\r\n    return 0\r\ndef g(x, y, ksi, eta):\r\n    \"\"\"Returns (a, b, g) for the boundary condition a*u + b*\u2202u/\u2202n = g on \u2202\u03a9 and (1, 0, g) for dirichlet conditions inside the domain)\"\"\"\r\n    if ksi == 0:  # left, neumann = 0\r\n        return (0, 1, 0)\r\n    if ksi == 1:  # right, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 0:  # bottom, neumann = 0\r\n        return (0, 1, 0)\r\n    if eta == 1:  # top, neumann = 0\r\n        return (0, 1, 0)\r\n\r\n    # dirichlet conditions inside the domain\r\n    if (x)**2 + (y)**2 < 0.4**2:\r\n        return (1, 0, 1)\r\n    elif (x+1.4)**2 + (y)**2 < 0.2**2:\r\n        return (1, 0, -2)\r\n    elif (x-1.4)**2 + (y)**2 < 0.2**2:\r\n        return (1, 0, -2)\r\n    elif -3.5 < x < -2 and -0.25 < y < 0.25:\r\n        return (1, 0, 2)\r\n    elif 2 < x < 3.5 and -0.25 < y < 0.25:\r\n        return (1, 0, 2)\r\n\r\nksi, eta = Transformation.get_ksi_eta()\r\nTx = 8*ksi - 4\r\nTy = 8*eta - 4\r\nsolve_and_plot(Nx=60, Ny=60, transformation=Transformation(ksi, eta, Tx, Ty), f=f, g=g)\r\n```\r\n\r\n    22:55:18 Integral: 64.89227055928428\r\n    \r\n\r\n\r\n    \r\n![png](./README_files/./README_19_1.png)\r\n    \r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Poisson Solver in Tranformed 2D Space using Finite Difference",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/Ar-Kareem/poisson_transform/",
        "Issues": "https://github.com/Ar-Kareem/poisson_transform/issues",
        "Repository": "https://github.com/Ar-Kareem/poisson_transform/"
    },
    "split_keywords": [
        "poisson",
        " solver",
        " finite difference",
        " transformed space",
        " 2d",
        " numerical",
        " mathematics",
        " physics",
        " engineering",
        " computational",
        " science",
        " research"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13b101fc29d54f1cc138455196df3f24d047b6e309b00db6983f4e309e68808a",
                "md5": "2cf6328d4d47d892cce2c2d81517247d",
                "sha256": "6a5ede96e1f426456cedcd627b047f00fdcf984065f93d43958237fc2a613d0a"
            },
            "downloads": -1,
            "filename": "poisson_transform-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2cf6328d4d47d892cce2c2d81517247d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 10576,
            "upload_time": "2024-11-04T20:10:28",
            "upload_time_iso_8601": "2024-11-04T20:10:28.313619Z",
            "url": "https://files.pythonhosted.org/packages/13/b1/01fc29d54f1cc138455196df3f24d047b6e309b00db6983f4e309e68808a/poisson_transform-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-04 20:10:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ar-Kareem",
    "github_project": "poisson_transform",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "build",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "scipy",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "sympy",
            "specs": []
        },
        {
            "name": "nbconvert",
            "specs": []
        },
        {
            "name": "twine",
            "specs": []
        }
    ],
    "lcname": "poisson-transform"
}
        
Elapsed time: 0.63439s