diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bba8b2..ae1d8bc 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,6 +30,11 @@ jobs: command: pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + - run: + name: run tests Geometry() + command: + pytest tests/test_geometry.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + - run: name: run tests Materials() command: diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 7d670cd..971358c 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -32,6 +32,7 @@ jobs: pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_geometry.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml diff --git a/examples/regular_2d_mesh_tally_example.py b/examples/regular_2d_mesh_tally_example.py index ae7ff91..58277f9 100644 --- a/examples/regular_2d_mesh_tally_example.py +++ b/examples/regular_2d_mesh_tally_example.py @@ -3,15 +3,14 @@ # Particular emphasis is placed on explaining the openmc-dagmc-wrapper # extentions of openmc base classes. -import tarfile -import urllib.request import openmc import openmc_dagmc_wrapper as odw from openmc_plasma_source import FusionRingSource -from dagmc_bounding_box import DagmcBoundingBox # downloads a dagmc file for use in the example +# import tarfile +# import urllib.request # url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz" # urllib.request.urlretrieve(url, "v0.0.2.tar.gz") # tar = tarfile.open("v0.0.2.tar.gz", "r:gz") @@ -45,8 +44,9 @@ ) # makes use of the dagmc-bound-box package to get the corners of the bounding -# box. This will be used to set the bounding box for the tally -my_bounding_box = DagmcBoundingBox(h5m_filename).corners() +# box. This will be used to set the bounding box for the tally. This can be +# expanded with the expand keyword if needed +my_bounding_box = geometry.corners() # A MeshTally2D tally allows a set of standard tally types (made from filters diff --git a/examples/regular_3d_mesh_tally_example.py b/examples/regular_3d_mesh_tally_example.py index 58c60c0..8cd8a05 100644 --- a/examples/regular_3d_mesh_tally_example.py +++ b/examples/regular_3d_mesh_tally_example.py @@ -3,15 +3,15 @@ # Particular emphasis is placed on explaining the openmc-dagmc-wrapper # extentions of openmc base classes. -import tarfile -import urllib.request import openmc import openmc_dagmc_wrapper as odw from openmc_plasma_source import FusionRingSource -from dagmc_bounding_box import DagmcBoundingBox + # downloads a dagmc file for use in the example +# import tarfile +# import urllib.request # url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz" # urllib.request.urlretrieve(url, "v0.0.2.tar.gz") # tar = tarfile.open("v0.0.2.tar.gz", "r:gz") @@ -45,8 +45,9 @@ ) # makes use of the dagmc-bound-box package to get the corners of the bounding -# box. This will be used to set the bounding box for the tally -my_bounding_box = DagmcBoundingBox(h5m_filename).corners() +# box. This will be used to set the bounding box for the tally. This can be +# expanded with the expand keyword if needed +my_bounding_box = geometry.corners() # A MeshTally3D tally allows a set of standard tally types (made from filters # and scores) to be applied to the DAGMC geometry. By default the mesh will be diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index 2d5a547..1b95bcb 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -3,6 +3,7 @@ import dagmc_h5m_file_inspector as di import openmc from numpy import cos, sin +from dagmc_bounding_box import DagmcBoundingBox class Geometry(openmc.Geometry): @@ -25,16 +26,30 @@ class Geometry(openmc.Geometry): def __init__( self, - h5m_filename: str = None, + h5m_filename: str, reflective_angles: Tuple[float, float] = None, graveyard_box=None, ): self.h5m_filename = h5m_filename self.reflective_angles = reflective_angles self.graveyard_box = graveyard_box + self.dagmc_bounding_box = DagmcBoundingBox(h5m_filename) super().__init__(root=self.make_root()) + def corners( + self, expand: Tuple[float, float, float] = None + ) -> Tuple[Tuple[float, float, float], Tuple[float, float, float]]: + """Gets the lower left corner and upper right corner of the DAGMC + geometry + Args: + expand: + Returns: + A tuple of two coordinates + """ + + return self.dagmc_bounding_box.corners(expand) + def make_root(self): # this is the underlying geometry container that is filled with the diff --git a/run_tests.sh b/run_tests.sh index 6e9c081..d4d9052 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,8 +1,9 @@ -pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -pytest tests/test_tallies/test_mesh_tallies.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -pytest tests/test_system.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -# pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -# pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -python tests/notebook_testing.py \ No newline at end of file + +pytest tests/test_neutronics_utils.py -v +pytest tests/test_example_neutronics_simulations.py -v +pytest tests/test_settings.py -v +pytest tests/test_geometry.py -v +pytest tests/test_materials.py -v +pytest tests/test_tallies/ -v +pytest tests/test_system/ -v +python tests/notebook_testing.py -v diff --git a/setup.py b/setup.py index 8eefd51..dd0b4ba 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ "plotly", "defusedxml", "dagmc_h5m_file_inspector", + "dagmc_bounding_box", ], # openmc, dagmc, moab are also needed and embree and double down are also # optionally needed but not avaible on PyPi diff --git a/tests/test_geometry.py b/tests/test_geometry.py new file mode 100644 index 0000000..af7b68d --- /dev/null +++ b/tests/test_geometry.py @@ -0,0 +1,75 @@ +import tarfile +import unittest +import urllib.request +from pathlib import Path + +import openmc +import openmc_dagmc_wrapper as odw + + +class TestSettings(unittest.TestCase): + """Tests the geometry.py file functionality""" + + def setUp(self): + + if not Path("tests/v0.0.2.tar.gz").is_file(): + url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz" + urllib.request.urlretrieve(url, "tests/v0.0.2.tar.gz") + + tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") + tar.extractall("tests") + tar.close() + + self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" + + self.material_description_bigger = { + "pf_coil_case_mat": "Be", + "center_column_shield_mat": "Be", + "blanket_rear_wall_mat": "Be", + "divertor_mat": "Be", + "tf_coil_mat": "Be", + "pf_coil_mat": "Be", + "inboard_tf_coils_mat": "Be", + "blanket_mat": "Be", + "firstwall_mat": "Be", + } + + def test_attributes(self): + my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + assert my_geometry.reflective_angles is None + assert my_geometry.graveyard_box is None + + def test_corners_types(self): + """checks the corner method returns the correct types""" + my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + assert isinstance(my_geometry.corners(), tuple) + assert isinstance(my_geometry.corners()[0], tuple) + assert isinstance(my_geometry.corners()[1], tuple) + assert isinstance(my_geometry.corners()[0][0], float) + assert isinstance(my_geometry.corners()[0][1], float) + assert isinstance(my_geometry.corners()[0][2], float) + assert isinstance(my_geometry.corners()[1][0], float) + assert isinstance(my_geometry.corners()[1][1], float) + assert isinstance(my_geometry.corners()[1][2], float) + + def test_corners_dimensions(self): + """checks length of tuples returned""" + my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + assert len(my_geometry.corners()) == 2 + assert len(my_geometry.corners()[0]) == 3 + assert len(my_geometry.corners()[1]) == 3 + + def test_corners_expand_increases_size(self): + """checks the expand increases the value returned""" + my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + small_corners = my_geometry.corners() + big_corners = my_geometry.corners(expand=(1, 2, 3)) + + assert small_corners[0][0] - 1 == big_corners[0][0] + assert small_corners[0][1] - 2 == big_corners[0][1] + assert small_corners[0][2] - 3 == big_corners[0][2] + + assert small_corners[1][0] + 1 == big_corners[1][0] + assert small_corners[1][1] + 2 == big_corners[1][1] + assert small_corners[1][2] + 3 == big_corners[1][2] diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 9fa1925..6c71247 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -7,7 +7,6 @@ import neutronics_material_maker as nmm import openmc import openmc_dagmc_wrapper as odw -from dagmc_bounding_box import DagmcBoundingBox from remove_dagmc_tags import remove_tags @@ -271,7 +270,7 @@ def test_neutronics_component_2d_mesh_simulation(self): my_tallies = odw.MeshTallies2D( tally_types=["heating"], planes=["xy", "xz", "yz"], - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), ) my_model = openmc.model.Model( @@ -304,7 +303,7 @@ def test_neutronics_component_3d_mesh_simulation(self): my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), ) my_model = openmc.model.Model( @@ -339,13 +338,13 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): my_3d_tally = odw.MeshTally3D( tally_type="heating", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), ) my_2d_tallies = odw.MeshTallies2D( planes=["xz", "xy", "yz"], tally_types=["heating"], - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), ) my_model = openmc.model.Model( diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py index 53d3e88..3a6efd6 100644 --- a/tests/test_tallies/test_mesh_tally_2d.py +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -6,7 +6,6 @@ import openmc import openmc_dagmc_wrapper as odw from openmc_plasma_source import FusionRingSource -from dagmc_bounding_box import DagmcBoundingBox class TestMeshTally2D(unittest.TestCase): @@ -59,19 +58,19 @@ def test_shape_of_resulting_png(self): tally1 = odw.MeshTally2D( tally_type="neutron_flux", plane="xy", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(10, 200), ) tally2 = odw.MeshTally2D( tally_type="neutron_flux", plane="xz", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(20, 100), ) tally3 = odw.MeshTally2D( tally_type="neutron_flux", plane="yz", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(30, 500), ) @@ -95,22 +94,23 @@ def test_shape_of_resulting_png(self): def test_correct_resolution(self): """Tests that the mesh resolution is in accordance with the plane """ + geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) tally_xy = odw.MeshTally2D( tally_type="neutron_flux", plane="xy", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(10, 20), ) tally_yz = odw.MeshTally2D( tally_type="neutron_flux", plane="yz", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(10, 20), ) tally_xz = odw.MeshTally2D( tally_type="neutron_flux", plane="xz", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), mesh_resolution=(10, 20), ) diff --git a/tests/test_tallies/test_mesh_tally_3d.py b/tests/test_tallies/test_mesh_tally_3d.py index 72773b2..36d6a81 100644 --- a/tests/test_tallies/test_mesh_tally_3d.py +++ b/tests/test_tallies/test_mesh_tally_3d.py @@ -5,7 +5,6 @@ import openmc import openmc_dagmc_wrapper as odw -from dagmc_bounding_box import DagmcBoundingBox class TestMeshTally3D(unittest.TestCase): @@ -46,8 +45,9 @@ def incorrect_mesh_tally_3d_type(): def test_meshfilter_from_h5m_file(self): # build + geometry = odw.Geometry(self.h5m_filename_smaller) expected_mesh = openmc.RegularMesh(mesh_id=99, name="3d_mesh_expected") - bbox = DagmcBoundingBox(self.h5m_filename_smaller).corners() + bbox = geometry.corners() expected_mesh.lower_left = bbox[0] expected_mesh.upper_right = bbox[1] expected_mesh.dimension = (100, 100, 100) @@ -55,7 +55,7 @@ def test_meshfilter_from_h5m_file(self): # run my_tally = odw.MeshTally3D( "heating", - bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(), + bounding_box=geometry.corners(), ) produced_filter = my_tally.filters[-1] produced_mesh = produced_filter.mesh