Vector Poisson equation in a rectangle

Vector Poisson equation in a rectangle#

\[\begin{split} \mathbb{S}_{\mathbf{u}} \begin{cases} \Omega = [0, L_x] \times [0, L_y] \\ \textbf{f}(x,y)=-y\textbf{e}_x + x\textbf{e}_y \\ \textbf{u}_{\text{D}}(x=0,y)=\textbf{0} \\ \textbf{u}_{\text{D}}(x=L_x,y)=\textbf{e}_x -\textbf{e}_y \\ \textbf{u}_{\text{D}}(x,y=0)\sin\left(\frac{\pi x}{2L_x}\right)\textbf{e}_x + \sin\left(\frac{3\pi x}{2L_x}\right)\textbf{e}_y \\ \textbf{e}_x\cdot\textbf{u}_{\text{D}}(x,y=L_y)=\frac{x}{L_x} \\ \textbf{e}_y\cdot\textbf{u}_{\text{D}}(x,y=L_y)=-\frac{x}{L_x} \\ \end{cases} \end{split}\]
import numpy as np
from lucifex.mesh import rectangle_mesh, mesh_boundary
from lucifex.fem import Function, Constant, cross_section_grid
from lucifex.solver import bvp, BoundaryConditions
from lucifex.plt import plot_colormap, plot_line, save_figure
from lucifex.utils.fenicsx_utils import extract_component_functions
from lucifex.pde.poisson import poisson


Lx = 2.0
Ly = 1.0
mesh = rectangle_mesh(Lx, Ly, 20, 10)
boundary = mesh_boundary(
    mesh, 
    {
        "left": lambda x: x[0],
        "right": lambda x: x[0] - Lx,
        "lower": lambda x: x[1],
        "upper": lambda x: x[1] - Ly,
    },
)
f = Function((mesh, 'P', 1, 2), lambda x: (-x[1], x[0]), name='f')

u_lower = (
    lambda x: np.sin(0.5 * np.pi * x[0] / Lx),
    lambda x: np.sin(1.5 * np.pi * x[0] / Lx),
)
ux_upper = lambda x: x[0] / Lx
uy_upper = lambda x: ux_upper(-x)
bcs = BoundaryConditions(
    ('dirichlet', boundary['left'], (0.0, 0.0)),
    ('dirichlet', boundary['right'], Constant(mesh, (1.0, -1.0))),
    ('dirichlet', boundary['lower'], u_lower),
    ('dirichlet', boundary['upper'], ux_upper, 0),
    ('dirichlet', boundary['upper'], uy_upper, 1),
)

u = Function(f.function_space, name='u')
u_solver = bvp(poisson, bcs)(u, f)
u_solver.solve()

ux, uy = extract_component_functions(('P', 1), u, names=('ux', 'uy'))
fx, fy = extract_component_functions(('P', 1), f, names=('fx', 'fy'))
fig, ax = plot_colormap(fx, title='$f_x$')
fig, ax = plot_colormap(fy, title='$f_y$')
fig, ax = plot_colormap(ux, title='$u_x$')
fig, ax = plot_colormap(uy, title='$u_y$')
save_figure('uy(x,y)', thumbnail=True)(fig)
../../_images/215c6c2bc6d7ce8699c4bb7c26e87292d4ab0c882b039e07976949568c767126.png ../../_images/3ddc55d6d043e6e54ec71a15353f2a0363fa2ac02fc32c32a24825794cf47dd4.png ../../_images/f1a56bf8bc02578495b51708dd923ef100ae597e35d15e530d346e4061fd1926.png ../../_images/ce8a497718e8b4137d76eb0e0a8d7f52cf191e961fc85880866c87c23518796b.png
for axis in ('x', 'y'):
    x_label = 'y' if axis == 'x' else 'x'
    for i in (0, -1):
        ux_cs, value = cross_section_grid(ux, axis, i, use_cache=False)
        plot_line(ux_cs, x_label=f'${x_label}$', y_label=f'$u_x({axis}={value:.2f})$')
        uy_cs, value = cross_section_grid(uy, axis, i, use_cache=False)
        plot_line(uy_cs, x_label=f'${x_label}$', y_label=f'$u_y({axis}={value:.2f})$')
../../_images/6c39ea41dd830f4632a4d14a589aa9e4a101685286346fd73dec105e51116bed.png ../../_images/4dba813f93dba0e6f4d800b8ba420216e0dd826a03417b5dcb3090e839b0cf97.png ../../_images/ef078c5dbd7d36ecf82c192f22669948891b29c6eda4e4d06de5d764fcc1f9c9.png ../../_images/2c5e782edc931934d7f564b44b4bdd96558d7f86b6e567c07800e29ec19e0a7d.png ../../_images/115f5ca197e103540bd8ca6f9dfbb06c467f3d8291a34e271a2ab6bf06ffb029.png ../../_images/4a9fda7803326e6e37d4f255e6b8ca5363b59e3e0bf2cecba602581ae0f8bae2.png ../../_images/4ba498c9507d393770ad1f6130888fd7ca7bbc0e866064458311e5157ccc40e7.png ../../_images/9635049c15fd61ff329c5485cb98261a2b53f0891e1bc5bb16b9d7285b06669f.png