CadQuery / CadQuery/assembly-mesh-plugin
Extruded solid in assemebly to gmsh
- Dominant language
- Python
- Stars
- 15
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
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:
```python
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:
```python
# 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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the supplied Python script and start at the assembly getTaggedGmsh() entry point, tracing how the solid and tagged faces are transferred to the Gmsh model. The work is done when an assembly solid retains its tagged physical groups while producing a configurable extruded mesh, including tagged lateral faces, without rebuilding geometry from coordinates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100