Skip to content

Commit

Permalink
allowing 3d gmsh export
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Feb 29, 2024
1 parent 98615f1 commit 5a1d3f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _mesh_brep(
min_mesh_size: float = 1,
max_mesh_size: float = 10,
mesh_algorithm: int = 1,
dimensions: int = 2
):
"""Creates a conformal surface meshes of the volumes in a Brep file using
Gmsh.
Expand All @@ -200,6 +201,8 @@ def _mesh_brep(
into gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
mesh_algorithm: The Gmsh mesh algorithm number to use. Passed into
gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
dimensions: The number of dimensions, 2 for a surface mesh 3 for a
volume mesh. Passed to gmsh.model.mesh.generate()
Returns:
The resulting gmsh object and volumes
Expand All @@ -214,7 +217,7 @@ def _mesh_brep(
gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
gmsh.model.mesh.generate(2)
gmsh.model.mesh.generate(dimensions)

return gmsh, volumes

Expand Down Expand Up @@ -369,14 +372,18 @@ def export_gmsh_mesh_file(
min_mesh_size: float = 1,
max_mesh_size: float = 5,
mesh_algorithm: int = 1,
dimensions: int = 2,
):
"""Saves a GMesh msh file of the geometry
"""Saves a GMesh msh file of the geometry in either 2D surface mesh or
3D volume mesh.
Args:
filename
min_mesh_size: the minimum size of mesh elements to use.
max_mesh_size: the maximum size of mesh elements to use.
mesh_algorithm: the gmsh mesh algorithm to use.
dimensions: The number of dimensions, 2 for a surface mesh 3 for a
volume mesh. Passed to gmsh.model.mesh.generate()
"""

assembly = cq.Assembly()
Expand All @@ -390,10 +397,9 @@ def export_gmsh_mesh_file(
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
mesh_algorithm=mesh_algorithm,
dimensions=dimensions
)

_mesh_to_h5m_in_memory_method(volumes=volumes)

gmsh.write(filename)

gmsh.finalize()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_file_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def test_h5m_with_single_volume_list():
my_model.export_dagmc_h5m_file(filename=h5m_file)
my_model.export_gmsh_mesh_file(filename="test.msh")
assert Path("test.msh").is_file()
my_model.export_gmsh_mesh_file(filename="test3d.msh", dimensions=3)
assert Path("test3d.msh").is_file()
assert get_volumes_and_materials_from_h5m(h5m_file) == {1: "mat:mat1"}


Expand Down Expand Up @@ -165,6 +167,10 @@ def test_gmsh_mesh_with_single_volume_list():
my_model.export_gmsh_mesh_file(filename=gmsh_mesh_file)
my_model.export_gmsh_mesh_file(filename="test2.msh")
assert Path("test2.msh").is_file()
assert Path("tests/single_cube.msh").is_file()
my_model.export_gmsh_mesh_file(filename="test2_3d.msh", dimensions=3)
assert Path("test2_3d.msh").is_file()



def test_gmsh_mesh_with_single_volume_2():
Expand Down

0 comments on commit 5a1d3f2

Please sign in to comment.