How to import mixed triangle and quad meshes from gmsh to fenics

could you give me some clues? I am a little missing. How to create a facet meshfunction from the gmsh info for this demo.

As you chose to use the mesh editor, you need to backwards engineer such a facet function. If you instead had modified the meshio mesh, it would have been easier to create facet and volume functions.

I claim that the code I added above solves your first issue, with setting boundary conditions to the upper square. For the facet function on the lower square, you should use that facet that the tags in line_data refers to the vertex in the Meshio mesh. Since you are adding these to the mesh editor in the same way, the numbering should align.
Consider an extension of my previous code. Say that we denote the pairs of vertices that gives a facet with a tag from gmsh as pairs. I create the pairs in the example below from the volume cell marking.
What we would like to do, is to recreate the meshfunction ff as ff_rebuild only using vertex information.
This is what is done below:

from dolfin import *

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 2)
v = Function(V)
cf = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
cf.array()[:5] = 1

ff = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
for cell in cells(mesh):
    if cf.array()[cell.index()] == 1:
        l_facets = cell.entities(mesh.topology().dim()-1)
        for facet in l_facets:
            ff.array()[facet] = 1

File("cf.pvd").write(cf)
bc = DirichletBC(V, Constant(2), ff, 1)
bc.apply(v.vector())
XDMFFile("v.xdmf").write_checkpoint(v, "v", 0)

import numpy as np
f_rebuild = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
pairs = np.zeros((np.sum(ff.array()==1),2))
j = 0
for facet in facets(mesh):
    if ff.array()[facet.index()] == 1:
        pairs[j] = facet.entities(0)
        j +=1
print(pairs)
# Loop over all facets
for facet in facets(mesh):
    vertices = facet.entities(0)
    # Loop through vertex pairs from gmsh
    for msh_facet in pairs:
        # Check if they match, if True, add to facet function
        if np.all(np.isin(vertices, msh_facet)):
            f_rebuild.array()[facet.index()] = 1

Thank you very much! this solved my proble. you’re right I will try to modify the meshio mesh.