Skip to content

Commit

Permalink
Merge pull request #54 from fusion-energy/adding_implicit_complement
Browse files Browse the repository at this point in the history
Adding option to set implicit complement material name
  • Loading branch information
shimwell authored Mar 3, 2024
2 parents 98615f1 + f0952a9 commit 9ab88da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/multiple_stp_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
my_model.add_stp_file("two_connected_cubes.stp", material_tags=["mat1", "mat2"])
my_model.add_stp_file("single_sphere.stp", material_tags=["mat3"])

my_model.export_dagmc_h5m_file(max_mesh_size=1, min_mesh_size=0.5)
my_model.export_dagmc_h5m_file(
max_mesh_size=1, min_mesh_size=0.5, implicit_complement_material_tag="air"
)
20 changes: 17 additions & 3 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import typing
from pathlib import Path

import cadquery as cq
import gmsh
import numpy as np
import OCP
import trimesh
from cadquery import importers
from pymoab import core, types

Expand Down Expand Up @@ -72,6 +69,7 @@ def _vertices_to_h5m(
triangles_by_solid_by_face: typing.Iterable[typing.Iterable[typing.Tuple[int, int, int]]],
material_tags: typing.Iterable[str],
h5m_filename="dagmc.h5m",
implicit_complement_material_tag=None,
):
"""Converts vertices and triangle sets into a tagged h5m file compatible
with DAGMC enabled neutronics simulations
Expand Down Expand Up @@ -172,6 +170,17 @@ def _vertices_to_h5m(

moab_core.add_entity(group_set, volume_set)

if implicit_complement_material_tag:
group_set = moab_core.create_meshset()
moab_core.tag_set_data(tags["category"], group_set, "Group")
moab_core.tag_set_data(
tags["name"], group_set, f"mat:{implicit_complement_material_tag}_comp"
)
moab_core.tag_set_data(tags["geom_dimension"], group_set, 4)
moab_core.add_entity(
group_set, volume_set
) # volume is arbitrary but should exist in moab core

all_sets = moab_core.get_entities_by_handle(0)

file_set = moab_core.create_meshset()
Expand Down Expand Up @@ -404,6 +413,7 @@ def export_dagmc_h5m_file(
min_mesh_size: float = 1,
max_mesh_size: float = 5,
mesh_algorithm: int = 1,
implicit_complement_material_tag: typing.Optional[str] = None,
):
"""Saves a DAGMC h5m file of the geometry
Expand All @@ -412,6 +422,9 @@ def export_dagmc_h5m_file(
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.
implicit_complement_material_tag: the name of the material tag to
use for the implicit complement (void space). Defaults to None
which is a vacuum.
"""
assembly = cq.Assembly()
for part in self.parts:
Expand Down Expand Up @@ -454,4 +467,5 @@ def export_dagmc_h5m_file(
triangles_by_solid_by_face=triangles_by_solid_by_face,
material_tags=material_tags_in_brep_order,
h5m_filename=filename,
implicit_complement_material_tag=implicit_complement_material_tag,
)

0 comments on commit 9ab88da

Please sign in to comment.