Poisson equation on an annulus

Poisson equation on an annulus#

\[\begin{split} \mathbb{S}= \begin{cases} \Omega = \{(x, y)~:~R_{\text{inner}}^2 < x^2 + y^2 < R_{\text{outer}}^2\} \\ \partial\Omega_{\text{inner}} = \{(x, y)~:~ x^2 + y^2 = R_{\text{inner}}^2 \} \\ \partial\Omega_{\text{outer}} = \{(x, y)~:~ x^2 + y^2 = R_{\text{outer}}^2 \} \\ u_{\text{D}}\vert_{\partial\Omega_{\text{inner}}}=0 \\ u_{\text{D}}\vert_{\partial\Omega_{\text{outer}}}=1 \\ f=0 \\ u_{\text{e}}(r)=\frac{\ln(r/R_{\text{inner}})}{\ln(R_{\text{outer}}/R_{\text{inner}})}~~,~~r=\sqrt{x^2+y^2} \end{cases}\end{split}\]
import numpy as np
from dolfinx.fem import FunctionSpace
from lucifex.mesh import annulus_mesh, mesh_boundary
from lucifex.fem import Function, Constant
from lucifex.solver import bvp, BoundaryConditions
from lucifex.viz import plot_colormap, plot_mesh, save_figure
from lucifex.utils import triangulation
from lucifex.pde.poisson import poisson

Rinner = 1.0
Router = 2.0
Nradial = 10
dr = (Router - Rinner) / Nradial
mesh = annulus_mesh(dr, 'triangle')(Rinner, Router)
boundary = mesh_boundary(
    mesh, 
    {
        "inner": lambda x: x[0]**2 + x[1]**2 - Rinner**2,
        "outer": lambda x: x[0]**2 + x[1]**2 - Router**2,
    },
)

fs = FunctionSpace(mesh, ('P', 1))
f = Constant(mesh, 0.0)

bcs = BoundaryConditions(
    ("dirichlet", boundary['inner'], 0.0),
    ("dirichlet", boundary['outer'], 1.0),  
)
u = Function(fs, name='u')
u_solver = bvp(poisson, bcs)(u, f)
u_solver.solve()
mesh_tri = triangulation(mesh)
u_tri = triangulation(u)
x, y = mesh_tri.x, mesh_tri.y

fig, ax = plot_colormap((mesh_tri, u_tri), cartesian=False, triangles=mesh_tri.triangles)
plot_mesh(fig, ax, mesh, title='$u$', color='cyan', linewidth=0.5)
save_figure('u(x,y)_mesh', thumbnail=True)(fig)
../../_images/f8a42490a59f4a39edda9b4714720945ae5c116ff7a6470c24f75f4f2a62c264.png
def exact_solution(x, y, Rinner, Router):
    r = np.sqrt(x**2 + y**2)
    return np.log(r / Rinner) / np.log(Router / Rinner)

ue = [exact_solution(xi, yi, Rinner, Router) for xi, yi in zip(x, y)]

fig, ax = plot_colormap(
    (x, y, ue), 
    title='$u_{\mathrm{e}}$', 
    cartesian=False, 
    triangles=mesh_tri.triangles,
)
save_figure('ue(x,y)')(fig)
../../_images/5aed2f438a81bb7e5138e1fe94f3d7c139d6ac3402db030a2d253b7bd55d25d9.png
error = np.subtract(ue, u_tri)
fig, ax = plot_colormap(
    (x, y, error), 
    title='$u_{\mathrm{e}} - u$', 
    cartesian=False, 
    triangles=mesh_tri.triangles,
)
save_figure('error(x,y)')(fig)
../../_images/48ba2f119bffa6e81b07c420cca9a1c9e72fe98587b3d5d04f1e63de1d9c3efd.png
The Kernel crashed while executing code in the current cell or a previous cell. 

Please review the code in the cell(s) to identify a possible cause of the failure. 

Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. 

View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.