Create forced regular mesh for OpenFOAM
I have the follwoing MWE:
import gmsh
# Choose kernel
option = gmsh.option
model = gmsh.model
occ = model.occ
mesh = model.mesh
# Initialize gmsh
gmsh.initialize()
scale = 1e-3 # lengths in mm
element_size = 1 * scale
width = 20 * scale
height_air = 5 * scale
thickness_tray = 3 * scale
diameter_hole = 2 * scale
dz = element_size / 2
height_total = height_air + thickness_tray
p = [
occ.addPoint(width / 2, 0.0, 0.0, element_size),
occ.addPoint(width / 2, height_air, 0.0, element_size),
occ.addPoint(diameter_hole / 2, height_air, 0.0, element_size),
occ.addPoint(diameter_hole / 2, height_total, 0.0, element_size),
occ.addPoint(-width / 2, 0.0, 0.0, element_size),
occ.addPoint(-width / 2, height_air, 0.0, element_size),
occ.addPoint(-diameter_hole / 2, height_air, 0.0, element_size),
occ.addPoint(-diameter_hole / 2, height_total, 0.0, element_size),
]
p_extra = [
occ.addPoint(diameter_hole / 2, 0.0, 0.0, element_size),
occ.addPoint(-diameter_hole / 2, 0.0, 0.0, element_size),
]
l_air_right = [
occ.addLine(p[0], p[1]),
occ.addLine(p[1], p[2]),
occ.addLine(p[2], p_extra[0]),
occ.addLine(p_extra[0], p[0]),
]
l_air_center = [
occ.addLine(p_extra[0], p[2]),
occ.addLine(p[2], p[6]),
occ.addLine(p[6], p_extra[1]),
occ.addLine(p_extra[1], p_extra[0]),
]
l_air_left = [
occ.addLine(p_extra[1], p[6]),
occ.addLine(p[6], p[5]),
occ.addLine(p[5], p[4]),
occ.addLine(p[4], p_extra[1]),
]
l_tray = [
occ.addLine(p[2], p[3]),
occ.addLine(p[3], p[7]),
occ.addLine(p[7], p[6]),
occ.addLine(p[6], p[2]),
]
c_air_right = occ.addCurveLoop(l_air_right)
c_air_center = occ.addCurveLoop(l_air_center)
c_air_left = occ.addCurveLoop(l_air_left)
c_tray = occ.addCurveLoop(l_tray)
s_air_right = occ.addPlaneSurface([c_air_right])
s_air_center = occ.addPlaneSurface([c_air_center])
s_air_left = occ.addPlaneSurface([c_air_left])
s_tray = occ.addPlaneSurface([c_tray])
v = occ.extrude(
[
(2, s_air_right),
(2, s_air_center),
(2, s_air_left),
(2, s_tray),
],
0,
0,
dz,
[1],
recombine=True,
)
occ.synchronize()
option.setNumber("Mesh.MeshSizeMin", 0.5 * scale)
option.setNumber("Mesh.MeshSizeMax", 0.5 * scale)
mesh.setTransfiniteAutomatic()
# mesh options
option.setNumber("Mesh.RecombineAll", 1)
option.setNumber("Mesh.RecombinationAlgorithm", 1)
option.setNumber("Mesh.SubdivisionAlgorithm", 2) # all hexahedra
option.setNumber("Mesh.ElementOrder", 1)
option.setNumber("Mesh.MshFileVersion", 2)
option.setNumber("Mesh.MedFileMinorVersion", 0)
option.setNumber("Mesh.SaveAll", 0)
option.setNumber("Mesh.SaveGroupsOfNodes", 1)
option.setNumber("Mesh.SecondOrderIncomplete", 0)
option.setNumber("Mesh.Algorithm", 5)
# Generate mesh
mesh.generate(3)
mesh.removeDuplicateNodes()
# set physical groups
delta = element_size / 100
inlet_plane = model.getEntitiesInBoundingBox(
-width / 2 - delta,
-delta,
-delta,
width / 2 + delta,
delta,
dz + delta,
2,
)
model.addPhysicalGroup(2, [p[1] for p in inlet_plane], name="inlet")
tray_walls = [(2, 23), (2, 25)]
air_walls = [(2, 8), (2, 9), (2, 19), (2, 20)]
model.addPhysicalGroup(2, [p[1] for p in tray_walls], name="tray_walls")
model.addPhysicalGroup(2, [p[1] for p in air_walls], name="air_walls")
front_plane = model.getEntitiesInBoundingBox(
-width / 2 - delta,
-delta,
-delta,
width / 2 + delta,
height_total + delta,
delta,
2,
)
back_plane = model.getEntitiesInBoundingBox(
-width / 2 - delta,
-delta,
dz - delta,
width / 2 + delta,
height_total + delta,
dz + delta,
2,
)
model.addPhysicalGroup(
2, [p[1] for p in front_plane] + [p[1] for p in back_plane], name="front_and_back"
)
volume = model.getEntitiesInBoundingBox(
-width / 2 - delta,
-delta,
-delta,
width / 2 + delta,
height_total + delta,
dz + delta,
3,
)
model.addPhysicalGroup(3, [v[1] for v in volume], name="volume")
gmsh.write("mesh.msh")
# Launch the GUI to see the results:
gmsh.fltk.run()
gmsh.finalize()
Unfortunately when I import this mesh to OpenFOAM (gmshToFoam
) the surfaces in between the squares are imported as well and make stuff complicated in OpenFOAM. Is there a possibility to merge these meshes or somehow delete the surfaces. I tried using occ.remove
and occ.fuse
with no success.