Skip to content

Extruded solid in assemebly to gmsh #30

Open

Description

@kakila

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:

Image

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:

Image

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

  1. jmwright commented on Jun 17, 2026

    @jmwright
    Member

    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.

  2. kakila commented on Jun 24, 2026

    @kakila
    Author

    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, ...)

  3. kakila commented on Aug 12, 2026

    @kakila
    Author

    Is there any news on this?

  4. jmwright commented on Aug 19, 2026

    @jmwright
    Member

    No, there has been no movement on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions