Skip to content
Closed
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: 4 additions & 9 deletions assembly_mesh_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import gmsh


def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"):
def assembly_to_gmsh(self):
"""
Pack the assembly into a gmsh object, respecting assembly part names and face tags when creating
the physical groups.
Pack the assembly into a gmsh object, respecting assembly part names and
face tags when creating the physical groups.
"""

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

gmsh.model.occ.synchronize()

gmsh.model.mesh.field.setAsBackgroundMesh(2)

gmsh.model.mesh.generate(3)
gmsh.write(mesh_path)

gmsh.finalize()
return gmsh


# Patch the new assembly functions into CadQuery's importers package
Expand Down
31 changes: 27 additions & 4 deletions tests/smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import assembly_mesh_plugin.plugin
from tests.sample_assemblies import (
generate_simple_nested_boxes,
Expand All @@ -14,8 +15,16 @@ def test_basic_assembly():
# Create the basic assembly
assy = generate_simple_nested_boxes()

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

# perform a simple mesh on the returned gmsh object
gmsh.model.mesh.field.setAsBackgroundMesh(2)
gmsh.model.mesh.generate(3)
gmsh.write("tagged_mesh.msh")
assert Path("tagged_mesh.msh").exists()
assert len(gmsh.model.getEntities(2)) == 16
gmsh.finalize()


def test_basic_cross_section():
Expand All @@ -27,7 +36,14 @@ def test_basic_cross_section():
assy = generate_test_cross_section()

# Create a mesh that has all the faces in the correct physical groups
assy.assemblyToGmsh(mesh_path="tagged_cross_section.msh")
gmsh = assy.assemblyToGmsh()

# perform a simple mesh on the returned gmsh object
gmsh.model.mesh.field.setAsBackgroundMesh(2)
gmsh.model.mesh.generate(3)
gmsh.write("tagged_cross_section.msh")
assert Path("tagged_cross_section.msh").exists()
gmsh.finalize()


def test_planar_coil():
Expand All @@ -39,4 +55,11 @@ def test_planar_coil():
assy = generate_assembly()

# Create a mesh that has all the faces in the correct physical groups
assy.assemblyToGmsh(mesh_path="tagged_planar_coil.msh")
gmsh = assy.assemblyToGmsh()

# perform a simple mesh on the returned gmsh object
gmsh.model.mesh.field.setAsBackgroundMesh(2)
gmsh.model.mesh.generate(3)
gmsh.write("tagged_cross_section.msh")
assert Path("tagged_cross_section.msh").exists()
gmsh.finalize()
Loading