Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions assembly_mesh_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ def get_tagged_gmsh(self):
# All the solids in the current part should be added to the mesh
for s in obj.moved(loc).Solids():
# Add the current solid to the mesh

with tempfile.NamedTemporaryFile(suffix=".brep") as temp_file:
s.exportBrep(temp_file.name)
gmsh.model.occ.importShapes(temp_file.name)
ps = gmsh.model.occ.importShapes(temp_file.name)

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

gmsh.model.occ.synchronize()

# Technically, importShapes could import multiple entities/dimensions, so filter those
vol_ents = []
for p in ps:
if p[0] == 3:
vol_ents.append(p[1])

# Set the physical name to be the part name in the assembly for all the solids
ps2 = gmsh.model.addPhysicalGroup(3, vol_ents)
gmsh.model.setPhysicalName(3, ps2, f"{name.split('/')[-1]}")

# All the faces in the current part should be added to the mesh
for face in s.Faces():
# Face name can be based on a tag, or just be a generic name
Expand Down
44 changes: 44 additions & 0 deletions tests/test_meshes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import gmsh
import assembly_mesh_plugin.plugin
from tests.sample_assemblies import (
generate_nested_boxes,
generate_simple_nested_boxes,
generate_test_cross_section,
generate_assembly,
)


def test_simple_assembly():
"""
Tests to make sure that the most basic assembly works correctly with tagging.
"""

# Create the basic assembly
assy = generate_simple_nested_boxes()

# Create a mesh that has all the faces tagged as physical groups
assy.saveToGmsh(mesh_path="tagged_mesh.msh")

gmsh.initialize()

gmsh.open("tagged_mesh.msh")

# Check the solids for the correct tags
physical_groups = gmsh.model.getPhysicalGroups(3)
for group in physical_groups:
# Get the name for the current volume
cur_name = gmsh.model.getPhysicalName(3, group[1])

assert cur_name in ["shell", "insert"]

# Check the surfaces for the correct tags
physical_groups = gmsh.model.getPhysicalGroups(2)
for group in physical_groups:
# Get the name for this group
cur_name = gmsh.model.getPhysicalName(2, group[1])

# Skip any groups that are not tagged explicitly
if "_surface_" in cur_name:
continue

assert cur_name in ["shell_inner-right", "insert_outer-right", "in_contact"]
Loading