Hello everyone,
I am implementing a mixed Poisson problem on the circumference (exterior of the circle, which means 1D elements). Here is my code:
def gmsh_circle(model: gmsh.model, name: str) -> gmsh.model:
"""Create a Gmsh model of a circle.
Args:
model: Gmsh model to add the mesh to.
name: Name (identifier) of the mesh to add.
Returns:
Gmsh model with a circle mesh added.
"""
model.add(name)
model.setCurrent(name)
gmsh.option.setNumber("Mesh.CharacteristicLengthFactor", 0.8)
circle= model.occ.addCircle(0, 0, 0, 1, tag=1)
# Synchronize OpenCascade representation with gmsh model
model.occ.synchronize()
# Add physical marker for cells. It is important to call this
# function after OpenCascade synchronization
model.add_physical_group(dim=1, tags=[circle])
# Generate the mesh
model.mesh.generate(dim=2)
return model
def create_mesh(comm: MPI.Comm, model: gmsh.model, name: str, filename: str, mode: str):
"""Create a DOLFINx from a Gmsh model and output to file.
Args:
comm: MPI communicator top create the mesh on.
model: Gmsh model.
name: Name (identifier) of the mesh to add.
filename: XDMF filename.
mode: XDMF file mode. "w" (write) or "a" (append).
"""
msh, ct, ft = gmshio.model_to_mesh(model, comm, rank=0)
msh.name = name
ct.name = f"{msh.name}_cells"
ft.name = f"{msh.name}_facets"
with XDMFFile(msh.comm, filename, mode) as file:
msh.topology.create_connectivity(0, 1)
file.write_mesh(msh)
file.write_meshtags(ct, msh.geometry, geometry_xpath=f"/Xdmf/Domain/Grid[@Name='{msh.name}']/Geometry")
file.write_meshtags(ft, msh.geometry, geometry_xpath=f"/Xdmf/Domain/Grid[@Name='{msh.name}']/Geometry")
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0)
# Create model
model = gmsh.model()
model = gmsh_circle(model, "Circle")
model.setCurrent("Circle")
create_mesh(MPI.COMM_SELF, model, "circle", f"out_gmsh/mesh_rankCirc_{MPI.COMM_WORLD.rank}.xdmf", "w")
with XDMFFile(MPI.COMM_WORLD, "out_gmsh/mesh_rankCirc_0.xdmf", "r") as xdmf:
mesh = xdmf.read_mesh(name="circle")
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim)
gmsh.finalize
# Define approximation spaces and basis functions
k = 1
Q_el = element("Lagrange", mesh.basix_cell(), k)
P_el = element("Lagrange", mesh.basix_cell(), k)
V_el = mixed_element([Q_el, P_el])
V = fem.functionspace(mesh, V_el)
However, I encounter this error:
ValueError: Non-matching UFL cell and mesh cell shapes.
for the last line.
I have already changed some parameters of the mesh generation, but I still havenât found a solution.
Does anyone know how to fix this?
Thanks.