Repository navigation
Extruded solid in assemebly to gmsh #30
Description
Witht e followng script I attempt at explaning the issue/request.
I am trying to generate an extruded mesh in gmsh using a 3d solid (obtained by extrusion) in an assembly:
import assembly_mesh_plugin
from cadquery import Workplane, Assembly
if __name__ == "__main__":
obj = (Workplane()
.rect(10, 10)
.extrude(5)
)
obj.faces("-Z").tag("back").end()
assy = Assembly()
# main object
assy.add(obj, name="main")
# get into gmsh
gmsh = assy.getTaggedGmsh()
# tagged face is there
pg = "main_back"
print(f"Physical group '{pg}' from tag:")
dimtags = gmsh.model.getEntitiesForPhysicalName(pg)
print()
# clean up physical groups
gmsh.model.removePhysicalGroups()
gmsh.model.addPhysicalGroup(dimtags[0][0], [dt[1] for dt in dimtags], name="back")
# mesh is not extruded
gmsh.model.mesh.generate(3)
gmsh.fltk.run()The issue is that gmsh doesn't now the body was extruded, so the mesh is not extruded:
The goal would be to inform gmsh that the body is extruded (and how many elements it should put in the extrusion direction), to get a mesh like this:
which is done by extending the previous script with:
# New model with tagged entity only
# get lines then points
_, lines = gmsh.model.getAdjacencies(*dimtags[0])
pts = []
for l in lines:
_, pts_ = gmsh.model.getAdjacencies(1, l)
p1 = gmsh.model.getValue(0, pts_[1], [])
pts.append(p1)
# new model
gmsh.model.add("extruded")
# rebuild face
pts_tag = []
for p in pts:
pts_tag.append(gmsh.model.occ.addPoint(*p))
lin_tag = []
for p0, p1 in zip([pts_tag[-1]]+pts_tag[:-1], pts_tag):
lin_tag.append(gmsh.model.occ.addLine(p0, p1))
loop_tag = gmsh.model.occ.addCurveLoop(lin_tag)
surf_tag = gmsh.model.occ.addPlaneSurface([loop_tag])
# rebuild physical group
gmsh.model.addPhysicalGroup(2, [surf_tag], name="back")
gmsh.model.occ.extrude(
[[2,surf_tag]],
dx=0,
dy=0,
dz=10,
numElements=[1],
recombine=True,
)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
gmsh.fltk.run()
gmsh.finalize()My approach
Currently I am building a workaround to rebuild the extruded solid and the correspoding physical groups.
In the example above I tagged the surface I used to extrude, but in the general problem lateral surfaces can also be tagged.
For example ,"+X" faces with tag "side".
So what I do in this case, when the second gmsh model (named "extruded" in the code above) is extruded I compare the coordinates of the surfaces with those of the tagged surfaces in the original model, and add a physical group to the extruded model with the corresponding entities. Quite a hack! ... and brittle.
Do you have a better idea?
Activity
jmwright commentedon Jun 17, 2026
Transfinite meshing might be an alternative, but I don't think it will work with all CadQuery solids. The edge tagging in #29 could be part of a transfinite + recombine path and should preserve the tags, but there is still quite a bit of work to do to make sure it would be appropriate for your purposes.
kakila commentedon Jun 24, 2026
Transfinite was more complicated than rebuilding and re-tagging. Also, we weren't able to get transfinite to generate meshes with a single element along the entity (e.g. needed for some solvers to get 2d results), so we use extruded meshes for this.
The information that the solid was extruded should somehow be passed to the gmsh object, in the same way that the extrude command works.
Maybe as an argument to getTaggedGmsh(), e.g. getTaggedGmsh(tag, axis, numElements); with the aim to emulate the call occ.extrude(tag, ...)
kakila commentedon Aug 12, 2026
Is there any news on this?
jmwright commentedon Aug 19, 2026
No, there has been no movement on this.