I made a simple meshes.The solution should consistent with u =(sin(2piy)/(2pi)+jy)sin(pix)
The main code is following
import numpy as np
import math
import ufl
from dolfinx import fem, mesh, plot
from ufl import ds, dx, grad, inner, sin
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 1.0)), n=(32, 16),
cell_type=mesh.CellType.triangle,)
V = fem.FunctionSpace(msh, (“Lagrange”, 1))
facets = mesh.locate_entities_boundary(msh, dim=1,
marker=lambda x: np.logical_or(np.isclose(x[0], 0.0),
np.isclose(x[0], 2.0)))
dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)
bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
x = ufl.SpatialCoordinate(msh)
pi = math.pi
x0 = pi * x[0]
x1 = sin(x0)
y1 = sin(2 * pi * x[1])
f = pi * x1 * (2.5 * y1 + 1j * pi * x[1])
g = (1 + 1j) * sin(pi * x[1])
a = inner(grad(u), grad(v)) * dx
L = inner(f, v) * dx + inner(g, v) * ds
problem = fem.petsc.LinearProblem(a, L, bcs=[bc], petsc_options={“ksp_type”: “preonly”, “pc_type”: >“lu”})
uh = problem.solve()
Here are my problems:
1.In the analytical solution, u(y=0)=0, u(y=1)=jsin(pix). But the figure in pyvista is not consistent.The figure is as follow:
2.I try to understand “ds” by:
print(fem.assemble(fem.Constant(msh,1) * ds))
But I get:
RuntimeError: Unsupported dtype
I know this way from the answer of this web
print(assemble(Constant(1)*dx))
I have tried “print(assemble(Constant(1)*ds))”. But “assemble” and “Constant” are not defined.
So, how can I do?
Thank you.