Assigning Physical Surface to External XY Surface on Extruded 3D Geometry

Hello,

I have imported a step file into gmsh with importshape and am now trying to only extract one surface of the triangular mesh, for example all surface tags that belong in the range (xmin,ymin) and (xmax,ymax) at either zmin or zmax. Note that I am using gmsh to transform the step file into msh and then using meshio to read the msh, create an xdmf, and then I use that xdmf with dolfinx. I am not sure whether what I wish belongs in the meshio workflow or the gmsh workflow. Also this is done in google colab.

Consider the MWE of the workflow. I added a portion after to show what I intend to use this for. As of now my output answer is all NaN, I assume bc of mesh problems.

import gmsh
gmsh.initialize()
gmsh.clear()
gmsh.model.add("hbase")
gmsh.model.setCurrent('hbase')
v = gmsh.model.occ.importShapes('/content/drive/MyDrive/Colab Notebooks/hrehbase2.step',highestDimOnly = 'true', format = "step")
xmin, ymin, zmin, xmax, ymax, zmax = gmsh.model.occ.getBoundingBox(
    v[0][0], v[0][1])

gmsh.model.occ.removeAllDuplicates() 
gmsh.model.occ.synchronize()
testtags = gmsh.model.getEntitiesInBoundingBox(xmin,ymin,zmin,xmax,ymax,zmax,dim=-1)

gmsh.model.mesh.generate(3)

gmsh.write("hbase.msh")



import meshio
import h5py
hreh = meshio.read('hbase.msh')

def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    points = mesh.points[:,:2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells})
    return out_mesh

triangle_mesh = create_mesh(hreh, "triangle", prune_z=True)
meshio.write("hreh.xdmf", triangle_mesh)


# Then I plug these into dolfinx and create an elasticity problem with dirchlet and neumann bc
from dolfinx.io import gmshio
import basix
from mpi4py import MPI

mesh_comm = MPI.COMM_WORLD
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "hreh.xdmf", "r") as xdmf:
       hmesh = xdmf.read_mesh(name="Grid")

import ufl
V = dolfinx.fem.functionspace(hmesh, ("Lagrange", 1))
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a = ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx


def u_exact(x):
    return 1 + x[0]**2 + 2 * x[1]**2


def boundary_D(x):
    return np.logical_or(np.isclose(x[0], 0), np.isclose(x[0], 1))

dofs_D = dolfinx.fem.locate_dofs_geometrical(V, boundary_D)
u_bc = dolfinx.fem.Function(V)
u_bc.interpolate(u_exact)
bc = dolfinx.fem.dirichletbc(u_bc, dofs_D)

meshio to read the msh, create an xdmf, and then I use that xdmf with dolfinx

That shouldn’t be needed. You are importing

from dolfinx.io import gmshio

which offers dolfinx.io.gmshio — DOLFINx 0.7.2 documentation

Please try again without meshio, report back the updated code and if it works correctly or not. This will help further users who are willing to help you, but may not have meshio installed.