Skip to content

Extruded solid in assemebly to gmsh #30

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?

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