Import from gmsh and define boundary conditions

Hi
I have troubles to define the boundary condition correctly when I import a geometry from gmsh.
Can someone help me? I looked for hours, but I have no idea how to do it correctly…

I think I mixed somethings I should only use when I create a geometry directly in fenics and something I should use when I import geometries…

I added some parts of the code:

#Defnie Mesh

    
msh = meshio.read("./beam.msh")
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells = cell.data
    elif  cell.type == "tetra":
        tetra_cells = cell.data

for key in msh.cell_data_dict["gmsh:physical"].keys():
    if key == "triangle":
        triangle_data = msh.cell_data_dict["gmsh:physical"][key]
    elif key == "tetra":
        tetra_data = msh.cell_data_dict["gmsh:physical"][key]
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})
triangle_mesh =meshio.Mesh(points=msh.points,
                           cells=[("triangle", triangle_cells)],
                           cell_data={"name_to_read":[triangle_data]})
meshio.write("mesh.xdmf", tetra_mesh)

meshio.write("mf.xdmf", triangle_mesh)

# Create mesh 
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
File("beam_mesh.pvd").write(mesh)

mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File("beam_facets.pvd").write(mf)


Boundary Conditions:
# Create mesh function over the cell facets

boundary_subdomains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)

#boundary_subdomains.set_all(0)
#force_boundary = AutoSubDomain(right)
#force_boundary.mark(boundary_subdomains, 3)


#Define measure for boundary condition integral
dss = ds(subdomain_data = boundary_subdomains)

#Set up boudary condition at left end
zero = Constant((0.0, 0.0, 0.0))
bc = DirichletBC(V, zero, mf, 1)

Load:
# Work of external forces
def Wext(u_):
    return dot(u_, p)*dss(2)

Please take some time to carefully format your question such that code snippets and mathematical formulae are correctly presented.

Furthermore construct a minimal working example as described here.

The more succinct your question, the more likely it is that people will be able to offer help.

For your specific question, there is a long thread, Where I have covered most of the different issues you can get when importing external meshes, see Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio