Skip to content

Commit

Permalink
Merge pull request #59 from fusion-energy/two_environment
Browse files Browse the repository at this point in the history
running tests in two environment
  • Loading branch information
shimwell authored Mar 14, 2024
2 parents 3cb0144 + 5e48fd5 commit e1320e7
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 43 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ jobs:
python -m pip install --upgrade pip
python -m pip install .
python -c "import cad_to_dagmc"
mamba install -y -c conda-forge "openmc=0.14.0=dagmc*nompi*"
python -m pip install .[tests]
pytest tests -v
cd examples
pytest tests/test_file_creation.py
pytest tests/test_loading_from_file_vs_shape_object.py
pytest tests/test_match.py
pytest tests/test_python_api.py
pytest tests/test_version.py
cd examples/surface_mesh
python create_stp_files_for_examples.py
python cadquery_assembly.py
python cadquery_compound.py
Expand All @@ -57,3 +60,14 @@ jobs:
python single_stp_file_multiple_volumes.py
python single_cadquery_object.py
python single_stp_file.py
rm *.h5m
pytest tests/test_model_creation_for_transport.py
mamba activate base
mamba create --name openmc python=3.12
mamba activate openmc
mamba install -y -c conda-forge "openmc=0.14.0=dagmc*nompi*"
pytest tests/test_package.py
pytest tests/test_h5m_in_simulation.py
pytest tests/test_h5m_in_transport.py
cd examples/unstrucutred_volume_mesh
python simulate_unstrucutred_volume_mesh_with_openmc.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _get_ids_from_imprinted_assembly(solid_id_dict):
return ids


def _order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
material_tags_in_brep_order = []
for brep_id in scrambled_id:
id_of_solid_in_org = original_ids.index(brep_id)
Expand Down Expand Up @@ -470,7 +470,7 @@ def export_dagmc_h5m_file(
msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(material_tags)}"
raise ValueError(msg)

material_tags_in_brep_order = _order_material_ids_by_brep_order(
material_tags_in_brep_order = order_material_ids_by_brep_order(
original_ids, scrambled_ids, material_tags
)

Expand Down
8 changes: 2 additions & 6 deletions tests/test_file_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ def test_h5m_with_multi_volume_not_touching():
]
for stp_file, mat_tags, h5m_file in zip(stp_files, material_tags, h5m_files):
my_model = CadToDagmc()
my_model.add_stp_file(filename=stp_file, material_tags=mat_tags)

assert my_model.material_tags == mat_tags
my_model.add_stp_file(filename=stp_file)

my_model.export_dagmc_h5m_file(filename=h5m_file)
my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags)

tags_dict = {}
for counter, loop_mat_tag in enumerate(mat_tags, 1):
Expand All @@ -112,8 +110,6 @@ def test_h5m_with_multi_volume_touching():
my_model = CadToDagmc()
my_model.add_stp_file(stp_file)

assert my_model.material_tags == mat_tags

my_model.export_dagmc_h5m_file(filename=h5m_file, material_tags=mat_tags)

tags_dict = {}
Expand Down
55 changes: 28 additions & 27 deletions tests/test_h5m_in_transport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import openmc
from cad_to_dagmc import CadToDagmc
import cadquery as cq


"""
Expand Down Expand Up @@ -118,20 +116,21 @@ def transport_particles_on_h5m_geometry(


def test_transport_result_h5m_with_2_sep_volumes():
h5m_filename = "test_two_sep_volumes.h5m"
# h5m_filename = "test_two_sep_volumes.h5m"
volumes = 2
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
workplane2 = cq.Workplane("XY").moveTo(0, 15).cylinder(height=10, radius=5)
# cq.Assembly().add(workplane1).add(workplane2)
# workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
# workplane2 = cq.Workplane("XY").moveTo(0, 15).cylinder(height=10, radius=5)
# # cq.Assembly().add(workplane1).add(workplane2)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.add_cadquery_object(workplane2)
my_model.export_dagmc_h5m_file(
filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
)
# my_model = CadToDagmc()
# my_model.add_cadquery_object(workplane1)
# my_model.add_cadquery_object(workplane2)
# my_model.export_dagmc_h5m_file(
# filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
# )
h5m_filename = "test_two_sep_volumes.h5m"

transport_particles_on_h5m_geometry(
h5m_filename=h5m_filename,
Expand All @@ -141,15 +140,17 @@ def test_transport_result_h5m_with_2_sep_volumes():


def test_transport_result_h5m_with_1_volumes():
h5m_filename = "h5m_from_in_memory_method.h5m"
# h5m_filename = "one_cylinder.h5m"
volumes = 1
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
# workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.export_dagmc_h5m_file(filename=h5m_filename, material_tags=[material_tags[0]])
# my_model = CadToDagmc()
# my_model.add_cadquery_object(workplane1)
# my_model.export_dagmc_h5m_file(filename=h5m_filename, material_tags=[material_tags[0]])

h5m_filename = "one_cylinder.h5m"

transport_particles_on_h5m_geometry(
h5m_filename=h5m_filename,
Expand All @@ -159,22 +160,22 @@ def test_transport_result_h5m_with_1_volumes():


def test_transport_result_h5m_with_2_joined_volumes():
h5m_filename = "h5m_from_in_memory_method.h5m"
# h5m_filename = "two_connected_cylinders.h5m"
volumes = 2
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
workplane2 = cq.Workplane("XY").cylinder(height=10, radius=5).cut(workplane1)
# workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
# workplane2 = cq.Workplane("XY").cylinder(height=10, radius=5).cut(workplane1)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.add_cadquery_object(workplane2)
my_model.export_dagmc_h5m_file(
filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
)
# my_model = CadToDagmc()
# my_model.add_cadquery_object(workplane1)
# my_model.add_cadquery_object(workplane2)
# my_model.export_dagmc_h5m_file(
# filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
# )

transport_particles_on_h5m_geometry(
h5m_filename="h5m_from_in_memory_method.h5m",
h5m_filename="two_connected_cylinders.h5m",
material_tags=material_tags,
nuclides=["H1"] * len(material_tags),
)
10 changes: 5 additions & 5 deletions tests/test_loading_from_file_vs_shape_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO test brep_part_finder

import cad_to_dagmc
from cad_to_dagmc import order_material_ids_by_brep_order

# def get_ids_from_assembly(assembly):
# ids = []
Expand All @@ -18,23 +18,23 @@

def test_order_material_ids_by_brep_order():
# two entries, reverse order
new_order = cad_to_dagmc._order_material_ids_by_brep_order(["1", "2"], ["2", "1"], ["m1", "m2"])
new_order = order_material_ids_by_brep_order(["1", "2"], ["2", "1"], ["m1", "m2"])
assert new_order == ["m2", "m1"]

# three entries, partly duplicate materials
new_order = cad_to_dagmc._order_material_ids_by_brep_order(
new_order = order_material_ids_by_brep_order(
["1", "2", "3"], ["2", "1", "3"], ["m1", "m2", "m2"]
)
assert new_order == ["m2", "m1", "m2"]

# three entries, unique materials
new_order = cad_to_dagmc._order_material_ids_by_brep_order(
new_order = order_material_ids_by_brep_order(
["1", "2", "3"], ["2", "1", "3"], ["m1", "m2", "m3"]
)
assert new_order == ["m2", "m1", "m3"]

# three entries, duplicate materials
new_order = cad_to_dagmc._order_material_ids_by_brep_order(
new_order = order_material_ids_by_brep_order(
["1", "2", "3"], ["2", "1", "3"], ["m1", "m1", "m1"]
)
assert new_order == ["m1", "m1", "m1"]
47 changes: 47 additions & 0 deletions tests/test_model_creation_for_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from cad_to_dagmc import CadToDagmc
import cadquery as cq


def test_transport_result_h5m_with_2_sep_volumes():
h5m_filename = "test_two_sep_volumes.h5m"
volumes = 2
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
workplane2 = cq.Workplane("XY").moveTo(0, 15).cylinder(height=10, radius=5)
# cq.Assembly().add(workplane1).add(workplane2)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.add_cadquery_object(workplane2)
my_model.export_dagmc_h5m_file(
filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
)


def test_transport_result_h5m_with_1_volumes():
h5m_filename = "one_cylinder.h5m"
volumes = 1
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.export_dagmc_h5m_file(filename=h5m_filename, material_tags=[material_tags[0]])


def test_transport_result_h5m_with_2_joined_volumes():
h5m_filename = "two_connected_cylinders.h5m"
volumes = 2
material_tags = [f"material_{n}" for n in range(1, volumes + 1)]

workplane1 = cq.Workplane("XY").cylinder(height=10, radius=4)
workplane2 = cq.Workplane("XY").cylinder(height=10, radius=5).cut(workplane1)

my_model = CadToDagmc()
my_model.add_cadquery_object(workplane1)
my_model.add_cadquery_object(workplane2)
my_model.export_dagmc_h5m_file(
filename=h5m_filename, material_tags=[material_tags[0], material_tags[1]]
)

0 comments on commit e1320e7

Please sign in to comment.