Vector Poisson equation in a rectangle#
\[\begin{split}
\mathbb{S}
\begin{cases}
\Omega = [0, L_x] \times [0, L_y] \\
\textbf{f}(x,y)=(-y, x) \\
\textbf{u}_{\text{D}}(x,y=0)=(x, 1) \\
\textbf{u}_{\text{D}}(x,y=L_y)=(1, 2) \\
\textbf{u}_{\text{D}}(x=0,y)=(0, 0) \\
\textbf{u}_{\text{D}}(x=L_x,y)=(1, -1)
\end{cases}
\end{split}\]
from dolfinx.fem import FunctionSpace
from lucifex.mesh import rectangle_mesh, mesh_boundary
from lucifex.fem import Function, Constant
from lucifex.solver import bvp, BoundaryConditions
from lucifex.viz import plot_colormap, plot_line
from lucifex.utils import cross_section, get_component_fem_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,
},
)
fs = FunctionSpace(mesh, ('P', 1, 2))
f = Function(fs, lambda x: (-x[1], x[0]), name='f')
bcs = BoundaryConditions(
('dirichlet', boundary['left'], (0.0, 0.0)),
('dirichlet', boundary['right'], Constant(mesh, (1.0, -1.0))),
('dirichlet', boundary['lower'], (lambda x: x[0], 1.0), 1),
('dirichlet', boundary['upper'], 1.0, 0),
('dirichlet', boundary['upper'], 2.0, 1),
)
u = Function(fs, name='u')
u_solver = bvp(poisson, bcs)(u, f)
u_solver.solve()
ux, uy = get_component_fem_functions(('P', 1), u, names=('ux', 'uy'))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 22
12 mesh = rectangle_mesh(Lx, Ly, 20, 10)
13 boundary = mesh_boundary(
14 mesh,
15 {
(...)
20 },
21 )
---> 22 fs = FunctionSpace(mesh, ('P', 1, 2))
23 f = Function(fs, lambda x: (-x[1], x[0]), name='f')
25 bcs = BoundaryConditions(
26 ('dirichlet', boundary['left'], (0.0, 0.0)),
27 ('dirichlet', boundary['right'], Constant(mesh, (1.0, -1.0))),
(...)
30 ('dirichlet', boundary['upper'], 2.0, 1),
31 )
File ~/miniconda3/envs/lucifex/lib/python3.10/site-packages/dolfinx/fem/function.py:481, in FunctionSpace.__init__(self, mesh, element, cppV, form_compiler_options, jit_options)
479 super().__init__(mesh.ufl_domain(), element)
480 else:
--> 481 e = ElementMetaData(*element)
482 ufl_element = basix.ufl_wrapper.create_element(
483 e.family, mesh.ufl_cell().cellname(), e.degree, gdim=mesh.ufl_cell().geometric_dimension())
484 super().__init__(mesh.ufl_domain(), ufl_element)
TypeError: ElementMetaData.__new__() takes 3 positional arguments but 4 were given
x_axis, ux_x, y_value = cross_section(ux, 'y', 0.5)
plot_line((x_axis, ux_x), x_label='$x$', y_label=f'{u.name}_x(y={y_value:.2f})')
y_axis, ux_y, x_value = cross_section(ux, 'x', 0.5)
plot_line((y_axis, ux_y), x_label='$y$', y_label=f'{u.name}_x(x={y_value:.2f})')
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[2], line 1
----> 1 x_axis, ux_x, y_value = cross_section(ux, 'y', 0.5)
2 plot_line((x_axis, ux_x), x_label='$x$', y_label=f'{u.name}_x(y={y_value:.2f})')
4 y_axis, ux_y, x_value = cross_section(ux, 'x', 0.5)
NameError: name 'ux' is not defined
x_axis, uy_x, y_value = cross_section(uy, 'y', 0.5)
plot_line((x_axis, uy_x), x_label='$x$', y_label=f'{u.name}_y(y={y_value:.2f})')
y_axis, uy_y, x_value = cross_section(uy, 'x', 0.5)
plot_line((y_axis, uy_x), x_label='$y$', y_label=f'{u.name}_y(x={y_value:.2f})')
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[3], line 1
----> 1 x_axis, uy_x, y_value = cross_section(uy, 'y', 0.5)
2 plot_line((x_axis, uy_x), x_label='$x$', y_label=f'{u.name}_y(y={y_value:.2f})')
4 y_axis, uy_y, x_value = cross_section(uy, 'x', 0.5)
NameError: name 'uy' is not defined