Skip to content

Commit 39f0776

Browse files
committed
returning gmsh object
1 parent 747e507 commit 39f0776

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

assembly_mesh_plugin/plugin.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import gmsh
66

77

8-
def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"):
8+
def assembly_to_gmsh(self):
99
"""
10-
Pack the assembly into a gmsh object, respecting assembly part names and face tags when creating
11-
the physical groups.
10+
Pack the assembly into a gmsh object, respecting assembly part names and
11+
face tags when creating the physical groups.
1212
"""
1313

1414
gmsh.initialize()
@@ -126,12 +126,7 @@ def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"):
126126

127127
gmsh.model.occ.synchronize()
128128

129-
gmsh.model.mesh.field.setAsBackgroundMesh(2)
130-
131-
gmsh.model.mesh.generate(3)
132-
gmsh.write(mesh_path)
133-
134-
gmsh.finalize()
129+
return gmsh
135130

136131

137132
# Patch the new assembly functions into CadQuery's importers package

tests/smoke_test.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
import assembly_mesh_plugin.plugin
23
from tests.sample_assemblies import (
34
generate_simple_nested_boxes,
@@ -14,8 +15,16 @@ def test_basic_assembly():
1415
# Create the basic assembly
1516
assy = generate_simple_nested_boxes()
1617

17-
# Create a mesh that has all the faces tagged as physical groups
18-
assy.assemblyToGmsh(mesh_path="tagged_mesh.msh")
18+
# Create a gmsh object that has all the faces tagged as physical groups
19+
gmsh = assy.assemblyToGmsh()
20+
21+
# perform a simple mesh on the returned gmsh object
22+
gmsh.model.mesh.field.setAsBackgroundMesh(2)
23+
gmsh.model.mesh.generate(3)
24+
gmsh.write("tagged_mesh.msh")
25+
assert Path("tagged_mesh.msh").exists()
26+
assert len(gmsh.model.getEntities(2)) == 16
27+
gmsh.finalize()
1928

2029

2130
def test_basic_cross_section():
@@ -27,7 +36,14 @@ def test_basic_cross_section():
2736
assy = generate_test_cross_section()
2837

2938
# Create a mesh that has all the faces in the correct physical groups
30-
assy.assemblyToGmsh(mesh_path="tagged_cross_section.msh")
39+
gmsh = assy.assemblyToGmsh()
40+
41+
# perform a simple mesh on the returned gmsh object
42+
gmsh.model.mesh.field.setAsBackgroundMesh(2)
43+
gmsh.model.mesh.generate(3)
44+
gmsh.write("tagged_cross_section.msh")
45+
assert Path("tagged_cross_section.msh").exists()
46+
gmsh.finalize()
3147

3248

3349
def test_planar_coil():
@@ -39,4 +55,11 @@ def test_planar_coil():
3955
assy = generate_assembly()
4056

4157
# Create a mesh that has all the faces in the correct physical groups
42-
assy.assemblyToGmsh(mesh_path="tagged_planar_coil.msh")
58+
gmsh = assy.assemblyToGmsh()
59+
60+
# perform a simple mesh on the returned gmsh object
61+
gmsh.model.mesh.field.setAsBackgroundMesh(2)
62+
gmsh.model.mesh.generate(3)
63+
gmsh.write("tagged_cross_section.msh")
64+
assert Path("tagged_cross_section.msh").exists()
65+
gmsh.finalize()

0 commit comments

Comments
 (0)