Skip to content

Commit 7729a5b

Browse files
authored
Merge pull request #9 from CadQuery/solid_tagging
Added tagging of parts within assemblies
2 parents 50a5a00 + 89cd210 commit 7729a5b

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

assembly_mesh_plugin/plugin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ def get_tagged_gmsh(self):
4545
# All the solids in the current part should be added to the mesh
4646
for s in obj.moved(loc).Solids():
4747
# Add the current solid to the mesh
48-
4948
with tempfile.NamedTemporaryFile(suffix=".brep") as temp_file:
5049
s.exportBrep(temp_file.name)
51-
gmsh.model.occ.importShapes(temp_file.name)
50+
ps = gmsh.model.occ.importShapes(temp_file.name)
5251

5352
# TODO find a way to check if the OCC in gmsh is compatible with the
5453
# OCC in CadQuery. When pip installed they tend to be incompatible
@@ -60,6 +59,16 @@ def get_tagged_gmsh(self):
6059

6160
gmsh.model.occ.synchronize()
6261

62+
# Technically, importShapes could import multiple entities/dimensions, so filter those
63+
vol_ents = []
64+
for p in ps:
65+
if p[0] == 3:
66+
vol_ents.append(p[1])
67+
68+
# Set the physical name to be the part name in the assembly for all the solids
69+
ps2 = gmsh.model.addPhysicalGroup(3, vol_ents)
70+
gmsh.model.setPhysicalName(3, ps2, f"{name.split('/')[-1]}")
71+
6372
# All the faces in the current part should be added to the mesh
6473
for face in s.Faces():
6574
# Face name can be based on a tag, or just be a generic name

tests/test_meshes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import gmsh
2+
import assembly_mesh_plugin.plugin
3+
from tests.sample_assemblies import (
4+
generate_nested_boxes,
5+
generate_simple_nested_boxes,
6+
generate_test_cross_section,
7+
generate_assembly,
8+
)
9+
10+
11+
def test_simple_assembly():
12+
"""
13+
Tests to make sure that the most basic assembly works correctly with tagging.
14+
"""
15+
16+
# Create the basic assembly
17+
assy = generate_simple_nested_boxes()
18+
19+
# Create a mesh that has all the faces tagged as physical groups
20+
assy.saveToGmsh(mesh_path="tagged_mesh.msh")
21+
22+
gmsh.initialize()
23+
24+
gmsh.open("tagged_mesh.msh")
25+
26+
# Check the solids for the correct tags
27+
physical_groups = gmsh.model.getPhysicalGroups(3)
28+
for group in physical_groups:
29+
# Get the name for the current volume
30+
cur_name = gmsh.model.getPhysicalName(3, group[1])
31+
32+
assert cur_name in ["shell", "insert"]
33+
34+
# Check the surfaces for the correct tags
35+
physical_groups = gmsh.model.getPhysicalGroups(2)
36+
for group in physical_groups:
37+
# Get the name for this group
38+
cur_name = gmsh.model.getPhysicalName(2, group[1])
39+
40+
# Skip any groups that are not tagged explicitly
41+
if "_surface_" in cur_name:
42+
continue
43+
44+
assert cur_name in ["shell_inner-right", "insert_outer-right", "in_contact"]

0 commit comments

Comments
 (0)