Skip to content

Commit

Permalink
Merge pull request #118 from connoramoreno/public-functions
Browse files Browse the repository at this point in the history
Make private functions in `core.py` public
  • Loading branch information
shimwell authored Feb 3, 2025
2 parents 943f698 + 1bcbb34 commit fdcb00e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings


def _define_moab_core_and_tags() -> tuple[core.Core, dict]:
def define_moab_core_and_tags() -> tuple[core.Core, dict]:
"""Creates a MOAB Core instance which can be built up by adding sets of
triangles to the instance
Expand Down Expand Up @@ -62,7 +62,7 @@ def _define_moab_core_and_tags() -> tuple[core.Core, dict]:
return moab_core, tags


def _vertices_to_h5m(
def vertices_to_h5m(
vertices: list[tuple[float, float, float]] | list["cadquery.occ_impl.geom.Vector"],
triangles_by_solid_by_face: list[list[tuple[int, int, int]]],
material_tags: list[str],
Expand Down Expand Up @@ -100,7 +100,7 @@ def _vertices_to_h5m(
else:
face_ids_with_solid_ids[face_id] = [solid_id]

moab_core, tags = _define_moab_core_and_tags()
moab_core, tags = define_moab_core_and_tags()

volume_sets_by_solid_id = {}
for material_tag, (solid_id, triangles_on_each_face) in zip(
Expand Down Expand Up @@ -233,7 +233,7 @@ def init_gmsh():
return gmsh


def _mesh_brep(
def mesh_brep(
gmsh,
min_mesh_size: float | None = None,
max_mesh_size: float | None = None,
Expand Down Expand Up @@ -355,21 +355,21 @@ def mesh_to_vertices_and_triangles(
return vertices, triangles_by_solid_by_face


def _get_ids_from_assembly(assembly: cq.assembly.Assembly):
def get_ids_from_assembly(assembly: cq.assembly.Assembly):
ids = []
for obj, name, loc, _ in assembly:
ids.append(name)
return ids


def _get_ids_from_imprinted_assembly(solid_id_dict):
def get_ids_from_imprinted_assembly(solid_id_dict):
ids = []
for id in list(solid_id_dict.values()):
ids.append(id[0])
return ids


def _check_material_tags(material_tags, iterable_solids):
def check_material_tags(material_tags, iterable_solids):
if material_tags:
if len(material_tags) != len(iterable_solids):
msg = (
Expand Down Expand Up @@ -448,7 +448,7 @@ def export_dagmc_h5m_file(

gmsh.finalize()

h5m_filename = _vertices_to_h5m(
h5m_filename = vertices_to_h5m(
vertices=vertices,
triangles_by_solid_by_face=triangles_by_solid_by_face,
material_tags=material_tags,
Expand Down Expand Up @@ -537,7 +537,7 @@ def add_cadquery_object(
else:
scaled_iterable_solids = [part.scale(scale_factor) for part in iterable_solids]

_check_material_tags(material_tags, scaled_iterable_solids)
check_material_tags(material_tags, scaled_iterable_solids)
if material_tags:
self.material_tags = self.material_tags + material_tags
self.parts = self.parts + scaled_iterable_solids
Expand Down Expand Up @@ -613,7 +613,7 @@ def export_unstructured_mesh_file(

gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method, scale_factor=scale_factor)

gmsh = _mesh_brep(
gmsh = mesh_brep(
gmsh=gmsh,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
Expand Down Expand Up @@ -690,7 +690,7 @@ def export_gmsh_mesh_file(

gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method, scale_factor=scale_factor)

gmsh = _mesh_brep(
gmsh = mesh_brep(
gmsh=gmsh,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
Expand Down Expand Up @@ -761,7 +761,7 @@ def export_dagmc_h5m_file(
for part in self.parts:
assembly.add(part)

original_ids = _get_ids_from_assembly(assembly)
original_ids = get_ids_from_assembly(assembly)

# both id lists should be the same length as each other and the same
# length as the self.material_tags
Expand All @@ -774,7 +774,7 @@ def export_dagmc_h5m_file(
assembly
)

scrambled_ids = _get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)
scrambled_ids = get_ids_from_imprinted_assembly(imprinted_solids_with_org_id)

material_tags_in_brep_order = order_material_ids_by_brep_order(
original_ids, scrambled_ids, self.material_tags
Expand All @@ -783,15 +783,15 @@ def export_dagmc_h5m_file(
material_tags_in_brep_order = self.material_tags
imprinted_assembly = assembly

_check_material_tags(material_tags_in_brep_order, self.parts)
check_material_tags(material_tags_in_brep_order, self.parts)

gmsh = init_gmsh()

gmsh, volumes = get_volumes(
gmsh, imprinted_assembly, method=method, scale_factor=scale_factor
)

gmsh = _mesh_brep(
gmsh = mesh_brep(
gmsh=gmsh,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
Expand All @@ -808,7 +808,7 @@ def export_dagmc_h5m_file(
gmsh.finalize()

# checks and fixes triangle fix_normals within vertices_to_h5m
return _vertices_to_h5m(
return vertices_to_h5m(
vertices=vertices,
triangles_by_solid_by_face=triangles_by_solid_by_face,
material_tags=material_tags_in_brep_order,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pymoab import core, types

from cad_to_dagmc import CadToDagmc
from cad_to_dagmc.core import _check_material_tags
from cad_to_dagmc.core import check_material_tags


def get_volumes_and_materials_from_h5m(filename: str) -> dict:
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_export_gmsh_mesh_file_handel_paths_folders_strings(filename):
def test_check_material_tags_too_long():
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
_check_material_tags(["a" * 29], [1])
check_material_tags(["a" * 29], [1])
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
assert "Material tag" in str(w[-1].message)
Expand Down

0 comments on commit fdcb00e

Please sign in to comment.