From 9efd3431cb23cd1263318d8ebb76dae52cd8f088 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 13:38:38 +0000 Subject: [PATCH 01/23] added a class Model --- openmc_dagmc_wrapper/Materials.py | 12 ++++-------- openmc_dagmc_wrapper/__init__.py | 2 ++ openmc_dagmc_wrapper/mesh.py | 5 +++-- openmc_dagmc_wrapper/model.py | 25 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 openmc_dagmc_wrapper/model.py diff --git a/openmc_dagmc_wrapper/Materials.py b/openmc_dagmc_wrapper/Materials.py index d492f40..c8ce0b8 100644 --- a/openmc_dagmc_wrapper/Materials.py +++ b/openmc_dagmc_wrapper/Materials.py @@ -10,18 +10,14 @@ class Materials(openmc.Materials): input formats. Args: - h5m_filename: the filename of the h5m file containing the DAGMC - geometry correspondence_dict: A dictionary that maps the material tags present within the DAGMC file with materials. Materials can be provided in a variety of formats including neutronics_material_maker.Material objects, strings or openmc.Material objects. """ - def __init__(self, h5m_filename: str, correspondence_dict: dict): + def __init__(self, correspondence_dict: dict): self.correspondence_dict = correspondence_dict - self.h5m_filename = h5m_filename - self.checks() self.set_openmc_materials() super().__init__(list(self.openmc_materials.values())) @@ -43,14 +39,14 @@ def set_openmc_materials(self): self.openmc_materials = openmc_materials - def checks(self): - materials_in_h5m = di.get_materials_from_h5m(self.h5m_filename) + def checks(self, h5m_filename): + materials_in_h5m = di.get_materials_from_h5m(h5m_filename) # # checks all the required materials are present for reactor_material in self.correspondence_dict.keys(): if reactor_material not in materials_in_h5m: msg = ( f"material with tag {reactor_material} was not found in " - f"the dagmc h5m file. The DAGMC file {self.h5m_filename} " + f"the dagmc h5m file. The DAGMC file {h5m_filename} " f"contains the following material tags {materials_in_h5m}." ) raise ValueError(msg) diff --git a/openmc_dagmc_wrapper/__init__.py b/openmc_dagmc_wrapper/__init__.py index b54aebf..0bd2148 100644 --- a/openmc_dagmc_wrapper/__init__.py +++ b/openmc_dagmc_wrapper/__init__.py @@ -9,3 +9,5 @@ from .tallies import * from .Settings import FusionSettings + +from .model import Model diff --git a/openmc_dagmc_wrapper/mesh.py b/openmc_dagmc_wrapper/mesh.py index 4790283..a8a339f 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -9,14 +9,15 @@ def __init__( plane="xy", resolution=(400, 400), plane_slice_location=(-1, 1), - bounding_box=None # TODO replace this by [(xmin, xmax), (ymin, ymax)] + bounding_box=None # TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)] ): self.plane = plane self.resolution = resolution self.plane_slice_location = plane_slice_location super().__init__(mesh_id, name) self.set_dimension() - self.set_bounds(bounding_box) + if bounding_box is not None: + self.set_bounds(bounding_box) def set_dimension(self): if self.plane == "xy": diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py new file mode 100644 index 0000000..44abeee --- /dev/null +++ b/openmc_dagmc_wrapper/model.py @@ -0,0 +1,25 @@ +import openmc + +import openmc_dagmc_wrapper as odw + + +class Model(openmc.Model): + def __init__( + self, + geometry=None, + materials=None, + settings=None, + tallies=None, + plots=None + ): + super().__init__(geometry, materials, settings, tallies, plots) + self.materials.checks(self.geometry.h5m_filename) + self.check_tallies_meshes_corners() + + def check_tallies_meshes_corners(self): + for tally in self.tallies: + for filter in tally.filters: + if isinstance(filter, openmc.MeshFilter): + if isinstance(filter.mesh, odw.RegularMesh2D): + if filter.mesh.lower_left is None: + filter.mesh.set_bounds(self.geometry.corners()) From 321ad3b16ec4bd6a55d1367c3a532624021075ed Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 14:25:54 +0000 Subject: [PATCH 02/23] added docstrings --- openmc_dagmc_wrapper/model.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 44abeee..5bbf701 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -12,11 +12,27 @@ def __init__( tallies=None, plots=None ): + """Inits Model + + Args: + geometry (odw.Geometry, optional): Geometry information. Defaults + to None. + materials (odw.Materials, optional): Materials information. + Defaults to None. + settings (openmc.Settings, optional): Settings information. + Defaults to None. + tallies (openmc.Tallies, optional): Tallies information. + Defaults to None. + plots (openmc.Plots, optional): Plot information. Defaults to None. + """ super().__init__(geometry, materials, settings, tallies, plots) self.materials.checks(self.geometry.h5m_filename) self.check_tallies_meshes_corners() def check_tallies_meshes_corners(self): + """Iterates through tallies and check if they have a RegularMesh2D. + If the RegularMesh2D doesn't have corners, add them from the geometry. + """ for tally in self.tallies: for filter in tally.filters: if isinstance(filter, openmc.MeshFilter): From 4dc06cd16e92da5a6701fd1830bb366398798845 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 14:25:59 +0000 Subject: [PATCH 03/23] fixed comments --- examples/regular_2d_mesh_tally_example.py | 19 ++++++------------- examples/regular_3d_mesh_tally_example.py | 12 +++--------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/examples/regular_2d_mesh_tally_example.py b/examples/regular_2d_mesh_tally_example.py index 58277f9..056c0a2 100644 --- a/examples/regular_2d_mesh_tally_example.py +++ b/examples/regular_2d_mesh_tally_example.py @@ -24,12 +24,10 @@ # So a set of 6 CSG surfaces are automatically made and added to the geometry geometry = odw.Geometry(h5m_filename=h5m_filename) -# Creates the materials to use in the problem using by linking the material -# tags in the DAGMC h5m file with material definitions in the +# Creates the materials to use in the problem with material definitions in the # neutronics-material-maker. One could also use openmc.Material or nmm.Material # objects instead of the strings used here materials = odw.Materials( - h5m_filename=h5m_filename, correspondence_dict={ "blanket_mat": "Li4SiO4", "blanket_rear_wall_mat": "Be", @@ -43,11 +41,6 @@ }, ) -# 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. 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 # and scores) to be applied to the DAGMC geometry. By default the mesh will be @@ -56,12 +49,12 @@ tally1 = odw.MeshTally2D( tally_type="photon_effective_dose", - plane="xy", - bounding_box=my_bounding_box) + plane="xy" + ) tally2 = odw.MeshTally2D( tally_type="neutron_effective_dose", - plane="xy", - bounding_box=my_bounding_box) + plane="xy" + ) # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1, tally2]) @@ -79,7 +72,7 @@ settings.source = FusionRingSource(fuel="DT", radius=350) # no modifications are made to the default openmc.Model object -my_model = openmc.Model( +my_model = odw.Model( materials=materials, geometry=geometry, settings=settings, tallies=tallies ) statepoint_file = my_model.run() diff --git a/examples/regular_3d_mesh_tally_example.py b/examples/regular_3d_mesh_tally_example.py index 8cd8a05..cd3e20a 100644 --- a/examples/regular_3d_mesh_tally_example.py +++ b/examples/regular_3d_mesh_tally_example.py @@ -25,12 +25,10 @@ # So a set of 6 CSG surfaces are automatically made and added to the geometry geometry = odw.Geometry(h5m_filename=h5m_filename) -# Creates the materials to use in the problem using by linking the material -# tags in the DAGMC h5m file with material definitions in the +# Creates the materials to use in the problem with material definitions in the # neutronics-material-maker. One could also use openmc.Material or nmm.Material # objects instead of the strings used here materials = odw.Materials( - h5m_filename=h5m_filename, correspondence_dict={ "blanket_mat": "Li4SiO4", "blanket_rear_wall_mat": "Be", @@ -44,17 +42,13 @@ }, ) -# 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. 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 # applied across the entire geomtry with and the size of the geometry is # automatically found. tally1 = odw.MeshTally3D( - tally_type="neutron_effective_dose", bounding_box=my_bounding_box + tally_type="neutron_effective_dose" ) # no modifications are made to the default openmc.Tallies @@ -72,7 +66,7 @@ settings.source = FusionRingSource(fuel="DT", radius=350) # no modifications are made to the default openmc.Model object -my_model = openmc.Model( +my_model = odw.Model( materials=materials, geometry=geometry, settings=settings, tallies=tallies ) statepoint_file = my_model.run() From 0e6acf4ac20e5dba637138377535a7b9702656ea Mon Sep 17 00:00:00 2001 From: autopep8 Date: Tue, 15 Feb 2022 14:26:04 +0000 Subject: [PATCH 04/23] Automated autopep8 fixes --- openmc_dagmc_wrapper/mesh.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/mesh.py b/openmc_dagmc_wrapper/mesh.py index a8a339f..d52b521 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -9,7 +9,8 @@ def __init__( plane="xy", resolution=(400, 400), plane_slice_location=(-1, 1), - bounding_box=None # TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)] + # TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)] + bounding_box=None ): self.plane = plane self.resolution = resolution From 73fdc9e4bafa62eaa6f47bb36462cc2aad08c98c Mon Sep 17 00:00:00 2001 From: autopep8 Date: Tue, 15 Feb 2022 14:26:49 +0000 Subject: [PATCH 05/23] Automated autopep8 fixes --- examples/regular_2d_mesh_tally_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/regular_2d_mesh_tally_example.py b/examples/regular_2d_mesh_tally_example.py index 056c0a2..8e2b85f 100644 --- a/examples/regular_2d_mesh_tally_example.py +++ b/examples/regular_2d_mesh_tally_example.py @@ -50,11 +50,11 @@ tally1 = odw.MeshTally2D( tally_type="photon_effective_dose", plane="xy" - ) +) tally2 = odw.MeshTally2D( tally_type="neutron_effective_dose", plane="xy" - ) +) # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1, tally2]) From b6ef6f4ebd61b187b82c07db689f3c484bdd4796 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 14:27:25 +0000 Subject: [PATCH 06/23] added TODO --- openmc_dagmc_wrapper/Geometry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index f5615ab..2907510 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -117,6 +117,7 @@ def create_sphere_of_vacuum_surface(self): be used as an alternative to the traditionally DAGMC graveyard cell""" if self.graveyard_box is None: + # TODO this is not needed since imported at top level from dagmc_bounding_box import DagmcBoundingBox self.graveyard_box = DagmcBoundingBox(self.h5m_filename).corners() From 9a8dc22bca44adfbc96d8898e87745a2d024b69a Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 14:28:24 +0000 Subject: [PATCH 07/23] changed TODO --- openmc_dagmc_wrapper/Geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index 2907510..2262d24 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -117,7 +117,7 @@ def create_sphere_of_vacuum_surface(self): be used as an alternative to the traditionally DAGMC graveyard cell""" if self.graveyard_box is None: - # TODO this is not needed since imported at top level + # TODO this could be refactored using self.corners() from dagmc_bounding_box import DagmcBoundingBox self.graveyard_box = DagmcBoundingBox(self.h5m_filename).corners() From 769e65bdccb1b02cc927ba2d6d440e76399879ab Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 14:38:10 +0000 Subject: [PATCH 08/23] avoid redifining filter --- openmc_dagmc_wrapper/model.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 5bbf701..fc029f4 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -34,8 +34,10 @@ def check_tallies_meshes_corners(self): If the RegularMesh2D doesn't have corners, add them from the geometry. """ for tally in self.tallies: - for filter in tally.filters: - if isinstance(filter, openmc.MeshFilter): - if isinstance(filter.mesh, odw.RegularMesh2D): - if filter.mesh.lower_left is None: - filter.mesh.set_bounds(self.geometry.corners()) + for tally_filter in tally.filters: + if isinstance(tally_filter, openmc.MeshFilter): + if isinstance(tally_filter.mesh, odw.RegularMesh2D): + if tally_filter.mesh.lower_left is None: + tally_filter.mesh.set_bounds( + self.geometry.corners() + ) From 16fc3eb2b79b4a1397f04fc4d64425683102284a Mon Sep 17 00:00:00 2001 From: autopep8 Date: Tue, 15 Feb 2022 14:38:42 +0000 Subject: [PATCH 09/23] Automated autopep8 fixes --- openmc_dagmc_wrapper/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index fc029f4..705a7f9 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -40,4 +40,4 @@ def check_tallies_meshes_corners(self): if tally_filter.mesh.lower_left is None: tally_filter.mesh.set_bounds( self.geometry.corners() - ) + ) From 1f910a642455656bb202b5470abc3f0a46316c26 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 15 Feb 2022 15:17:05 +0000 Subject: [PATCH 10/23] test for upper_right too --- openmc_dagmc_wrapper/model.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 705a7f9..939a528 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -37,7 +37,11 @@ def check_tallies_meshes_corners(self): for tally_filter in tally.filters: if isinstance(tally_filter, openmc.MeshFilter): if isinstance(tally_filter.mesh, odw.RegularMesh2D): - if tally_filter.mesh.lower_left is None: + corners = [ + tally_filter.mesh.lower_left, + tally_filter.mesh.upper_right + ] + if None in corners: tally_filter.mesh.set_bounds( self.geometry.corners() ) From 28dfd87430a3621e289def6f741529f5f940efac Mon Sep 17 00:00:00 2001 From: autopep8 Date: Tue, 15 Feb 2022 15:17:37 +0000 Subject: [PATCH 11/23] Automated autopep8 fixes --- openmc_dagmc_wrapper/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 939a528..480b7b9 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -40,7 +40,7 @@ def check_tallies_meshes_corners(self): corners = [ tally_filter.mesh.lower_left, tally_filter.mesh.upper_right - ] + ] if None in corners: tally_filter.mesh.set_bounds( self.geometry.corners() From 4c062d57af0a9a363e7846ea25c51dee636a2b42 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 25 Feb 2022 23:48:50 +0000 Subject: [PATCH 12/23] tests running locally --- .gitignore | 9 +++++++-- tests/test_geometry.py | 17 ++++++++--------- tests/test_materials.py | 17 ++++++++--------- tests/test_neutronics_utils.py | 24 ++++++++++++------------ 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index f559df3..2d76c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -142,5 +142,10 @@ dmypy.json *.trelis *.out *.tar.gz -examples/neutronics_workflow-0.0.2/ -tests/neutronics_workflow-0.0.2/ \ No newline at end of file + +tests/example_01_single_volume_cell_tally/ +tests/example_02_multi_volume_cell_tally/ +tests/example_04_multi_volume_regular_mesh_tally/ +tests/example_05_3D_unstructured_mesh_tally/ +tests/output_files_produced.zip + diff --git a/tests/test_geometry.py b/tests/test_geometry.py index af7b68d..4fbd418 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -5,23 +5,22 @@ import openmc import openmc_dagmc_wrapper as odw - +import zipfile 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { "pf_coil_case_mat": "Be", diff --git a/tests/test_materials.py b/tests/test_materials.py index a55f673..8ad729b 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -5,23 +5,22 @@ import openmc import openmc_dagmc_wrapper as odw - +import zipfile class TestMaterial(unittest.TestCase): """Tests creation, functionality and extended features of the Material class""" 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { "pf_coil_case_mat": "Be", diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 8ffe909..1796905 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -1,5 +1,6 @@ import os import tarfile +import zipfile import unittest import urllib.request from pathlib import Path @@ -14,16 +15,15 @@ class TestNeutronicsUtilityFunctions(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_get_an_isotope_present_in_cross_sections_xml(self): """Checks that an isotope string is returned from the @@ -39,9 +39,9 @@ def test_get_an_isotope_present_in_cross_sections_xml_error_handeling( """Checks that an error message is raised if the OPENMC_CROSS_SECTIONS variable does not exist""" - def no_env_var(): - del os.environ["OPENMC_CROSS_SECTIONS"] - odw.utils.get_an_isotope_present_in_cross_sections_xml() + self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" + odw.utils.get_an_isotope_present_in_cross_sections_xml() cross_sections_xml = os.getenv("OPENMC_CROSS_SECTIONS") self.assertRaises(ValueError, no_env_var) @@ -150,7 +150,7 @@ def incorrect_type(): # """Tries to make extract points on to viewplane that is not accepted""" # def incorrect_viewplane(): - # """Inccorect view_plane should raise a ValueError""" + # """Incorrect view_plane should raise a ValueError""" # source = openmc.Source() # source.space = openmc.stats.Point((0, 0, 0)) From 7b468ba640ac18948e389609e58ab7e7a0822ae7 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 25 Feb 2022 23:49:23 +0000 Subject: [PATCH 13/23] Automated autopep8 fixes --- tests/test_geometry.py | 1 + tests/test_materials.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 4fbd418..241fef0 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -7,6 +7,7 @@ import openmc_dagmc_wrapper as odw import zipfile + class TestSettings(unittest.TestCase): """Tests the geometry.py file functionality""" diff --git a/tests/test_materials.py b/tests/test_materials.py index 8ad729b..68c70b9 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -7,6 +7,7 @@ import openmc_dagmc_wrapper as odw import zipfile + class TestMaterial(unittest.TestCase): """Tests creation, functionality and extended features of the Material class""" From aebfcde22be3d4b2f757752607b89dfa4892135b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 26 Feb 2022 00:09:23 +0000 Subject: [PATCH 14/23] updated download url --- tests/test_neutronics_utils.py | 6 +++--- tests/test_system/test_system_multi_volume.py | 17 ++++++++-------- .../test_system/test_system_single_volume.py | 20 ++++++++----------- tests/test_tallies/test_cell_tallies.py | 17 ++++++++-------- tests/test_tallies/test_mesh_tally_2d.py | 17 ++++++++-------- tests/test_tallies/test_mesh_tally_3d.py | 17 ++++++++-------- 6 files changed, 43 insertions(+), 51 deletions(-) diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 1796905..a6510db 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -39,9 +39,9 @@ def test_get_an_isotope_present_in_cross_sections_xml_error_handeling( """Checks that an error message is raised if the OPENMC_CROSS_SECTIONS variable does not exist""" - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" - self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" - odw.utils.get_an_isotope_present_in_cross_sections_xml() + def no_env_var(): + del os.environ["OPENMC_CROSS_SECTIONS"] + odw.utils.get_an_isotope_present_in_cross_sections_xml() cross_sections_xml = os.getenv("OPENMC_CROSS_SECTIONS") self.assertRaises(ValueError, no_env_var) diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index 5175005..5028bd0 100644 --- a/tests/test_system/test_system_multi_volume.py +++ b/tests/test_system/test_system_multi_volume.py @@ -3,7 +3,7 @@ import unittest import urllib.request from pathlib import Path - +import zipfile import openmc import openmc_dagmc_wrapper as odw @@ -13,16 +13,15 @@ class TestObjectNeutronicsArguments(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { "pf_coil_case_mat": "Be", diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 6c71247..f7107f0 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -3,7 +3,7 @@ import unittest import urllib.request from pathlib import Path - +import zipfile import neutronics_material_maker as nmm import openmc import openmc_dagmc_wrapper as odw @@ -16,16 +16,15 @@ class TestShape(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description = { "tungsten": "tungsten", @@ -66,7 +65,6 @@ def test_simulation_with_previous_h5m_file(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, correspondence_dict={ "mat1": "WC"}) @@ -95,7 +93,6 @@ def test_simulation_with_previous_h5m_file_with_graveyard_removed(self): geometry = odw.Geometry(h5m_filename="no_graveyard_dagmc_file.h5m") materials = odw.Materials( - h5m_filename="no_graveyard_dagmc_file.h5m", correspondence_dict={"mat1": "WC"}, ) @@ -121,7 +118,6 @@ def test_neutronics_component_simulation_with_openmc_mat(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, correspondence_dict={"mat1": test_mat}, ) diff --git a/tests/test_tallies/test_cell_tallies.py b/tests/test_tallies/test_cell_tallies.py index ed95143..8820460 100644 --- a/tests/test_tallies/test_cell_tallies.py +++ b/tests/test_tallies/test_cell_tallies.py @@ -2,7 +2,7 @@ import unittest import urllib.request from pathlib import Path - +import zipfile import openmc_dagmc_wrapper as odw @@ -11,16 +11,15 @@ class TestCellTallies(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_name(self): my_tally = odw.CellTally("heating", target=1) diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py index 3a6efd6..e7314b9 100644 --- a/tests/test_tallies/test_mesh_tally_2d.py +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -2,7 +2,7 @@ import unittest import urllib.request from pathlib import Path - +import zipfile import openmc import openmc_dagmc_wrapper as odw from openmc_plasma_source import FusionRingSource @@ -13,16 +13,15 @@ class TestMeshTally2D(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_incorrect_mesh_tally_2d(self): """Set a mesh_tally_2d that is not accepted which should raise an diff --git a/tests/test_tallies/test_mesh_tally_3d.py b/tests/test_tallies/test_mesh_tally_3d.py index 36d6a81..99959a5 100644 --- a/tests/test_tallies/test_mesh_tally_3d.py +++ b/tests/test_tallies/test_mesh_tally_3d.py @@ -2,7 +2,7 @@ import unittest import urllib.request from pathlib import Path - +import zipfile import openmc import openmc_dagmc_wrapper as odw @@ -12,16 +12,15 @@ class TestMeshTally3D(unittest.TestCase): 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") + if not Path("tests/output_files_produced.zip").is_file(): + url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" + urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") - tar.extractall("tests") - tar.close() + with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + zip_ref.extractall("tests") - 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.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_incorrect_mesh_tally_3d(self): """Set a mesh_tally_3d that is not accepted which should raise an From 755393ba65fc4ba4a8aed6d8b466b8fec0d3a0cd Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 12:20:47 +0000 Subject: [PATCH 15/23] fixed a few tests, removed complex graveyard process --- .gitignore | 1 + openmc_dagmc_wrapper/Geometry.py | 47 ++-------- setup.cfg | 5 +- tests/test_geometry.py | 1 - tests/test_materials.py | 31 +++--- .../test_system/test_system_single_volume.py | 94 +++++++------------ tests/test_tallies/test_mesh_tally_2d.py | 1 - 7 files changed, 59 insertions(+), 121 deletions(-) diff --git a/.gitignore b/.gitignore index 2d76c8d..bd05d54 100644 --- a/.gitignore +++ b/.gitignore @@ -149,3 +149,4 @@ tests/example_04_multi_volume_regular_mesh_tally/ tests/example_05_3D_unstructured_mesh_tally/ tests/output_files_produced.zip +_version.py diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index 2262d24..566ec18 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -7,10 +7,8 @@ class Geometry(openmc.Geometry): - """A openmc.Geometry object with a DAGMC Universe. If the model - requires a graveyard bounding box this will be automatically added. When - simulating a sector model reflecting surfaces can be added to complete the - boundary conditions. + """A openmc.Geometry object with a DAGMC Universe. When simulating a sector + model reflecting surfaces can be added to complete the boundary conditions. Args: h5m_filename: the filename of the h5m file containing the DAGMC @@ -18,21 +16,15 @@ class Geometry(openmc.Geometry): reflective_angles: if a sector model is being simulated this argument can be used to specify the angles (in radians) to use when creating reflecting surfaces for a sector model. - graveyard_box: If a certain size of graveyard is required then the - upper left and lower right corners can be specified. If this is not - specified then the code checks to see if a graveyard exists and if - none are found then it makes the graveyard to encompass the geometry """ def __init__( self, 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()) @@ -61,19 +53,15 @@ def make_root(self): # made if "graveyard" not in di.get_materials_from_h5m(self.h5m_filename): - # vac_surfs = self.create_cube_of_vacuum_surfaces() - # # creates a cube of surfaces for the boundary conditions - # region = +vac_surfs[0] & \ - # -vac_surfs[1] & \ - # +vac_surfs[2] & \ - # -vac_surfs[3] & \ - # +vac_surfs[4] & \ - # -vac_surfs[5] - vac_surf = self.create_sphere_of_vacuum_surface() + vac_surf = openmc.Sphere( + r=1000000, # set to 10km to be big enough for models + surface_id=99999999, # set to large surface id to avoid overlaps + boundary_type="vacuum" + ) region = -vac_surf containing_cell = openmc.Cell( - cell_id=9999, region=region, fill=dag_univ + cell_id=99999999, region=region, fill=dag_univ ) root = [containing_cell] else: @@ -111,22 +99,3 @@ def make_root(self): root = [containing_cell] return root - - def create_sphere_of_vacuum_surface(self): - """Creates a single vacuum surfaces that surround the geometry and can - be used as an alternative to the traditionally DAGMC graveyard cell""" - - if self.graveyard_box is None: - # TODO this could be refactored using self.corners() - from dagmc_bounding_box import DagmcBoundingBox - - self.graveyard_box = DagmcBoundingBox(self.h5m_filename).corners() - bbox = [[*self.graveyard_box[0]], [*self.graveyard_box[1]]] - - largest_radius = 3 * max(max(bbox[0]), max(bbox[1])) - - sphere_surface = openmc.Sphere( - r=largest_radius, surface_id=9999, boundary_type="vacuum" - ) - - return sphere_surface diff --git a/setup.cfg b/setup.cfg index 8575f82..d07e0d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,10 @@ install_requires= tests = pytest >= 5.4.3 openmc_data_downloader - # remove_dagmc_tags + openmc_plasma_source + remove_dagmc_tags + nbformat + nbconvert # defusedxml [flake8] diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 241fef0..7e95d35 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -38,7 +38,6 @@ def setUp(self): 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""" diff --git a/tests/test_materials.py b/tests/test_materials.py index 68c70b9..072fb7a 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -37,10 +37,7 @@ def setUp(self): def test_resulting_attributes_with_single_material_and_string(self): - my_material = odw.Materials( - correspondence_dict={ - "mat1": "Be"}, - h5m_filename=self.h5m_filename_smaller) + my_material = odw.Materials(correspondence_dict={"mat1": "Be"}) assert isinstance(my_material, openmc.Materials) assert len(my_material) == 1 @@ -52,7 +49,7 @@ def test_incorrect_materials(self): """Set a material as a string which should raise an error""" def incorrect_materials(): - odw.Materials(self.h5m_filename_smaller, "coucou") + odw.Materials("coucou") self.assertRaises(TypeError, incorrect_materials) @@ -60,30 +57,24 @@ def test_incorrect_materials_type(self): """Sets a material as an int which should raise an error""" def incorrect_materials_type(): - odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={"mat1": 23}, - ) + odw.Materials(correspondence_dict={"mat1": 23}) self.assertRaises(TypeError, incorrect_materials_type) def test_mat_not_in_h5m_file(self): def incorrect_material_tag(): - odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={"coucou": 23}, - ) + odw.Materials(correspondence_dict={"coucou": "23"}) self.assertRaises(ValueError, incorrect_material_tag) - def test_not_enough_materials_in_dict(self): - def incorrect_corres_dict(): - odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={}, - ) + # TODO this check has now moved to odw.Model so tallies, geometry and + # settings will need adding to construct a model object to trigger the + # ValueError + # def test_not_enough_materials_in_dict(self): + # def incorrect_corres_dict(): + # odw.Materials(correspondence_dict={}) - self.assertRaises(ValueError, incorrect_corres_dict) + # self.assertRaises(ValueError, incorrect_corres_dict) if __name__ == "__main__": diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index f7107f0..3df744c 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -129,11 +129,11 @@ def test_neutronics_component_simulation_with_openmc_mat(self): tallies=[my_tally], settings=self.settings, ) - h5m_filename = my_model.run() + statepoint_filename = my_model.run() self.settings.batches = 10 - assert h5m_filename.name == "statepoint.2.h5" + assert statepoint_filename.name == "statepoint.2.h5" - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) assert len(results.tallies.items()) == 1 def test_neutronics_component_simulation_with_nmm(self): @@ -145,10 +145,7 @@ def test_neutronics_component_simulation_with_nmm(self): test_mat = nmm.Material.from_library("Be") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={"mat1": test_mat}, - ) + materials = odw.Materials(correspondence_dict={"mat1": test_mat}) my_tally = odw.CellTally("heating", target=1) @@ -159,9 +156,9 @@ def test_neutronics_component_simulation_with_nmm(self): settings=self.settings, ) - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) assert len(results.tallies.items()) == 1 def test_incorrect_cell_tallies(self): @@ -193,10 +190,7 @@ def test_neutronics_component_cell_simulation_heating(self): mat.set_density("g/cm3", 2.1) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": mat}) + materials = odw.Materials(correspondence_dict={"mat1": mat}) my_tallies = odw.CellTallies( tally_types=[ "heating", @@ -212,9 +206,9 @@ def test_neutronics_component_cell_simulation_heating(self): settings=self.settings, ) # performs an openmc simulation on the model - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) # spectra add two tallies in this case (photons and neutrons) assert len(results.tallies.items()) == 5 assert len(results.meshes) == 0 @@ -230,10 +224,7 @@ def test_neutronics_spectra(self): mat.set_density("g/cm3", 2.1) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": mat}) + materials = odw.Materials(correspondence_dict={"mat1": mat}) my_tallies = odw.CellTallies( tally_types=[ "neutron_spectra", @@ -258,10 +249,7 @@ def test_neutronics_component_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_tallies = odw.MeshTallies2D( tally_types=["heating"], @@ -276,9 +264,9 @@ def test_neutronics_component_2d_mesh_simulation(self): settings=self.settings, ) # performs an openmc simulation on the model - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) print(results.meshes) assert len(results.meshes) == 3 assert len(results.tallies.items()) == 3 @@ -292,10 +280,7 @@ def test_neutronics_component_3d_mesh_simulation(self): os.system("rm *.vtk") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], @@ -309,14 +294,14 @@ def test_neutronics_component_3d_mesh_simulation(self): settings=self.settings, ) # performs an openmc simulation on the model - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) # ideally these tallies would share the same mesh and there would be 1 # mesh assert len(results.meshes) == 2 assert len(results.tallies.items()) == 2 - assert Path(h5m_filename).exists() is True + assert Path(statepoint_filename).exists() is True def test_neutronics_component_3d_and_2d_mesh_simulation(self): """Makes a neutronics model and simulates with a 3D and 2D mesh tally @@ -327,10 +312,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -350,9 +332,9 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): settings=self.settings, ) # performs an openmc simulation on the model - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) assert len(results.meshes) == 4 # one 3D and three 2D assert len(results.tallies.items()) == 4 # one 3D and three 2D @@ -366,10 +348,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -394,9 +373,9 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( ) # performs an openmc simulation on the model - h5m_filename = my_model.run() + statepoint_filename = my_model.run() - results = openmc.StatePoint(h5m_filename) + results = openmc.StatePoint(statepoint_filename) assert len(results.meshes) == 4 # one 3D and three 2D assert len(results.tallies.items()) == 4 # one 3D and three 2D @@ -408,10 +387,7 @@ def test_reactor_from_shapes_cell_tallies(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_tallies = odw.CellTallies(tally_types=["TBR", "heating", "flux"]) @@ -435,10 +411,7 @@ def test_cell_tallies_simulation_fast_flux(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_fast_flux", "neutron_fast_flux", "flux"] @@ -464,10 +437,7 @@ def test_cell_tallies_simulation_effective_dose(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat1": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_effective_dose", "neutron_effective_dose"] @@ -492,7 +462,6 @@ def test_cell_tallies_simulation_effective_dose(self): # geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) # materials = odw.Materials( - # h5m_filename=self.h5m_filename_smaller, # correspondence_dict={"mat1": "Be"}) # my_tallies = odw.CellTallies( @@ -529,11 +498,18 @@ def test_missing_h5m_file_error_handling(): os.system("touch tallies.xml") os.system("rm dagmc.h5m") - odw.Materials( - h5m_filename="dagmc.h5m", + materials = odw.Materials( correspondence_dict={ "mat1": "Be"}) + geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + openmc.model.Model( + geometry=geometry, + materials=materials, + tallies=[], + settings=self.settings + ) + self.assertRaises( FileNotFoundError, test_missing_h5m_file_error_handling) diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py index e7314b9..580914e 100644 --- a/tests/test_tallies/test_mesh_tally_2d.py +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -49,7 +49,6 @@ def test_shape_of_resulting_png(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( - h5m_filename=self.h5m_filename_smaller, correspondence_dict={ "mat1": "Be", }, From 7029896344173b144ad17bb16d141005b5aa587b Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 13:03:34 +0000 Subject: [PATCH 16/23] fixed resolution bug --- openmc_dagmc_wrapper/mesh.py | 33 ++++++++++--------- .../tallies/mesh_tallies/mesh_tally_2D.py | 11 ++++--- .../tallies/mesh_tallies/mesh_tally_3D.py | 14 ++++---- tests/test_system/test_system_multi_volume.py | 5 +-- .../test_system/test_system_single_volume.py | 32 +++++++++--------- tests/test_tallies/test_mesh_tally_2d.py | 14 ++++---- 6 files changed, 56 insertions(+), 53 deletions(-) diff --git a/openmc_dagmc_wrapper/mesh.py b/openmc_dagmc_wrapper/mesh.py index d52b521..6bdabed 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -23,26 +23,27 @@ def __init__( def set_dimension(self): if self.plane == "xy": self.dimension = [ - self.mesh_resolution[0], - self.mesh_resolution[1], + self.resolution[0], + self.resolution[1], 1, ] elif self.plane == "xz": self.dimension = [ - self.mesh_resolution[0], + self.resolution[0], 1, - self.mesh_resolution[1], + self.resolution[1], ] elif self.plane == "yz": self.dimension = [ 1, - self.mesh_resolution[0], - self.mesh_resolution[1], + self.resolution[0], + self.resolution[1], ] def set_bounds(self, bounding_box): + if self.plane == "xy": self.lower_left = [ bounding_box[0][0], @@ -50,33 +51,33 @@ def set_bounds(self, bounding_box): self.plane_slice_location[1], ] self.upper_right = [ - self.bounding_box[1][0], - self.bounding_box[1][1], + bounding_box[1][0], + bounding_box[1][1], self.plane_slice_location[0], ] elif self.plane == "xz": self.lower_left = [ - self.bounding_box[0][0], + bounding_box[0][0], self.plane_slice_location[1], - self.bounding_box[0][2], + bounding_box[0][2], ] self.upper_right = [ - self.bounding_box[1][0], + bounding_box[1][0], self.plane_slice_location[0], - self.bounding_box[1][2], + bounding_box[1][2], ] elif self.plane == "yz": self.lower_left = [ self.plane_slice_location[1], - self.bounding_box[0][1], - self.bounding_box[0][2], + bounding_box[0][1], + bounding_box[0][2], ] self.upper_right = [ self.plane_slice_location[0], - self.bounding_box[1][1], - self.bounding_box[1][2], + bounding_box[1][1], + bounding_box[1][2], ] diff --git a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py index d745936..893ac1e 100644 --- a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py +++ b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py @@ -12,7 +12,7 @@ class MeshTally2D(Tally): Args: tally_type (str): [description] plane (str): "xy", "xz", "yz" - mesh_resolution (list): [description] + resolution (list): [description] bounding_box ([type], optional): either a .h5m filename or [point1, point2]. """ @@ -23,15 +23,18 @@ def __init__( plane: str, bounding_box: List[Tuple[float]], plane_slice_location: Tuple[float, float] = (1, -1), - mesh_resolution: Tuple[float, float] = (400, 400), + resolution: Tuple[float, float] = (400, 400), ): mesh = RegularMesh2D( plane=plane, - resolution=mesh_resolution, + resolution=resolution, plane_slice_location=plane_slice_location, bounding_box=bounding_box ) + self.plane = plane + self.tally_type = tally_type + super().__init__(tally_type) self.name = self.tally_type + "_on_2D_mesh_" + self.plane self.filters.append(openmc.MeshFilter(mesh)) @@ -63,7 +66,7 @@ def __init__( MeshTally2D( tally_type=tally_type, plane=plane, - mesh_resolution=meshes_resolution, + resolution=meshes_resolution, bounding_box=bounding_box, ) ) diff --git a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_3D.py b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_3D.py index b246512..f26b115 100644 --- a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_3D.py +++ b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_3D.py @@ -11,17 +11,17 @@ def __init__( self, tally_type: str, bounding_box: List[Tuple[float]], - mesh_resolution=(100, 100, 100), + resolution=(100, 100, 100), **kwargs ): super().__init__(tally_type, **kwargs) - mesh = self.create_mesh(mesh_resolution, bounding_box) + mesh = self.create_mesh(resolution, bounding_box) self.filters.append(openmc.MeshFilter(mesh)) self.name = self.tally_type + "_on_3D_mesh" - def create_mesh(self, mesh_resolution, bounding_box): + def create_mesh(self, resolution, bounding_box): mesh = openmc.RegularMesh(name="3d_mesh") - mesh.dimension = mesh_resolution + mesh.dimension = resolution mesh.lower_left = bounding_box[0] mesh.upper_right = bounding_box[1] return mesh @@ -41,15 +41,17 @@ def __init__( self, tally_types: str, bounding_box: List[Tuple[float]], - meshes_resolution: Tuple[float] = (100, 100, 100), + resolution: Tuple[float] = (100, 100, 100), ): self.tallies = [] self.tally_types = tally_types + self.bounding_box = bounding_box + self.resolution = resolution for tally_type in self.tally_types: self.tallies.append( MeshTally3D( tally_type=tally_type, - mesh_resolution=meshes_resolution, + resolution=resolution, bounding_box=bounding_box, ) ) diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index 5028bd0..3ab4627 100644 --- a/tests/test_system/test_system_multi_volume.py +++ b/tests/test_system/test_system_multi_volume.py @@ -59,10 +59,7 @@ def test_cell_tally_simulation(self): os.system("rm statepoint*.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_bigger) - materials = odw.Materials( - h5m_filename=self.h5m_filename_bigger, - correspondence_dict=self.material_description_bigger, - ) + materials = odw.Materials(correspondence_dict=self.material_description_bigger) my_tally = odw.CellTally("TBR") my_model = openmc.model.Model( geometry=geometry, diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 3df744c..1b6624a 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -66,7 +66,7 @@ def test_simulation_with_previous_h5m_file(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( correspondence_dict={ - "mat1": "WC"}) + "mat_my_material": "WC"}) my_model = openmc.model.Model( geometry=geometry, @@ -93,7 +93,7 @@ def test_simulation_with_previous_h5m_file_with_graveyard_removed(self): geometry = odw.Geometry(h5m_filename="no_graveyard_dagmc_file.h5m") materials = odw.Materials( - correspondence_dict={"mat1": "WC"}, + correspondence_dict={"mat_my_material": "WC"}, ) my_model = openmc.model.Model( @@ -118,10 +118,10 @@ def test_neutronics_component_simulation_with_openmc_mat(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( - correspondence_dict={"mat1": test_mat}, + correspondence_dict={"mat_my_material": test_mat}, ) - my_tally = odw.CellTally("heating", target="mat1", materials=materials) + my_tally = odw.CellTally("heating", target="mat_my_material", materials=materials) self.settings.batches = 2 my_model = openmc.model.Model( geometry=geometry, @@ -145,7 +145,7 @@ def test_neutronics_component_simulation_with_nmm(self): test_mat = nmm.Material.from_library("Be") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": test_mat}) + materials = odw.Materials(correspondence_dict={"mat_my_material": test_mat}) my_tally = odw.CellTally("heating", target=1) @@ -190,7 +190,7 @@ def test_neutronics_component_cell_simulation_heating(self): mat.set_density("g/cm3", 2.1) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": mat}) + materials = odw.Materials(correspondence_dict={"mat_my_material": mat}) my_tallies = odw.CellTallies( tally_types=[ "heating", @@ -224,7 +224,7 @@ def test_neutronics_spectra(self): mat.set_density("g/cm3", 2.1) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": mat}) + materials = odw.Materials(correspondence_dict={"mat_my_material": mat}) my_tallies = odw.CellTallies( tally_types=[ "neutron_spectra", @@ -249,7 +249,7 @@ def test_neutronics_component_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies2D( tally_types=["heating"], @@ -280,7 +280,7 @@ def test_neutronics_component_3d_mesh_simulation(self): os.system("rm *.vtk") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], @@ -312,7 +312,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -348,7 +348,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -387,7 +387,7 @@ def test_reactor_from_shapes_cell_tallies(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies(tally_types=["TBR", "heating", "flux"]) @@ -411,7 +411,7 @@ def test_cell_tallies_simulation_fast_flux(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_fast_flux", "neutron_fast_flux", "flux"] @@ -437,7 +437,7 @@ def test_cell_tallies_simulation_effective_dose(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_effective_dose", "neutron_effective_dose"] @@ -462,7 +462,7 @@ def test_cell_tallies_simulation_effective_dose(self): # geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) # materials = odw.Materials( - # correspondence_dict={"mat1": "Be"}) + # correspondence_dict={"mat_my_material": "Be"}) # my_tallies = odw.CellTallies( # tally_types=["(n,Xt)", "heating", "flux"]) @@ -500,7 +500,7 @@ def test_missing_h5m_file_error_handling(): materials = odw.Materials( correspondence_dict={ - "mat1": "Be"}) + "mat_my_material": "Be"}) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) openmc.model.Model( diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py index 580914e..449bf89 100644 --- a/tests/test_tallies/test_mesh_tally_2d.py +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -50,26 +50,26 @@ def test_shape_of_resulting_png(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials( correspondence_dict={ - "mat1": "Be", + "mat_my_material": "Be", }, ) tally1 = odw.MeshTally2D( tally_type="neutron_flux", plane="xy", bounding_box=geometry.corners(), - mesh_resolution=(10, 200), + resolution=(10, 200), ) tally2 = odw.MeshTally2D( tally_type="neutron_flux", plane="xz", bounding_box=geometry.corners(), - mesh_resolution=(20, 100), + resolution=(20, 100), ) tally3 = odw.MeshTally2D( tally_type="neutron_flux", plane="yz", bounding_box=geometry.corners(), - mesh_resolution=(30, 500), + resolution=(30, 500), ) tallies = openmc.Tallies([tally1, tally2, tally3]) @@ -97,19 +97,19 @@ def test_correct_resolution(self): tally_type="neutron_flux", plane="xy", bounding_box=geometry.corners(), - mesh_resolution=(10, 20), + resolution=(10, 20), ) tally_yz = odw.MeshTally2D( tally_type="neutron_flux", plane="yz", bounding_box=geometry.corners(), - mesh_resolution=(10, 20), + resolution=(10, 20), ) tally_xz = odw.MeshTally2D( tally_type="neutron_flux", plane="xz", bounding_box=geometry.corners(), - mesh_resolution=(10, 20), + resolution=(10, 20), ) assert tally_xy.mesh.dimension == [10, 20, 1] From 82ceaec8222b4cf26df5e42aa64411fece73f179 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Wed, 2 Mar 2022 13:04:11 +0000 Subject: [PATCH 17/23] Automated autopep8 fixes --- tests/test_system/test_system_multi_volume.py | 3 +- .../test_system/test_system_single_volume.py | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index 3ab4627..f63c57b 100644 --- a/tests/test_system/test_system_multi_volume.py +++ b/tests/test_system/test_system_multi_volume.py @@ -59,7 +59,8 @@ def test_cell_tally_simulation(self): os.system("rm statepoint*.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_bigger) - materials = odw.Materials(correspondence_dict=self.material_description_bigger) + materials = odw.Materials( + correspondence_dict=self.material_description_bigger) my_tally = odw.CellTally("TBR") my_model = openmc.model.Model( geometry=geometry, diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 1b6624a..9b8d394 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -121,7 +121,10 @@ def test_neutronics_component_simulation_with_openmc_mat(self): correspondence_dict={"mat_my_material": test_mat}, ) - my_tally = odw.CellTally("heating", target="mat_my_material", materials=materials) + my_tally = odw.CellTally( + "heating", + target="mat_my_material", + materials=materials) self.settings.batches = 2 my_model = openmc.model.Model( geometry=geometry, @@ -145,7 +148,9 @@ def test_neutronics_component_simulation_with_nmm(self): test_mat = nmm.Material.from_library("Be") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": test_mat}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": test_mat}) my_tally = odw.CellTally("heating", target=1) @@ -249,7 +254,9 @@ def test_neutronics_component_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_tallies = odw.MeshTallies2D( tally_types=["heating"], @@ -280,7 +287,9 @@ def test_neutronics_component_3d_mesh_simulation(self): os.system("rm *.vtk") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], @@ -312,7 +321,9 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -348,7 +359,9 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -387,7 +400,9 @@ def test_reactor_from_shapes_cell_tallies(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_tallies = odw.CellTallies(tally_types=["TBR", "heating", "flux"]) @@ -411,7 +426,9 @@ def test_cell_tallies_simulation_fast_flux(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_fast_flux", "neutron_fast_flux", "flux"] @@ -437,7 +454,9 @@ def test_cell_tallies_simulation_effective_dose(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_effective_dose", "neutron_effective_dose"] From 439f217a72427b2d18c0e07c77d6dbc7fb86be5e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 14:10:26 +0000 Subject: [PATCH 18/23] adding missing attributes --- openmc_dagmc_wrapper/mesh.py | 1 + .../tallies/mesh_tallies/mesh_tally_2D.py | 4 ++-- tests/test_system/test_system_multi_volume.py | 17 ++++++++--------- tests/test_system/test_system_single_volume.py | 1 - 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/openmc_dagmc_wrapper/mesh.py b/openmc_dagmc_wrapper/mesh.py index 6bdabed..455cd10 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -15,6 +15,7 @@ def __init__( self.plane = plane self.resolution = resolution self.plane_slice_location = plane_slice_location + self.bounding_box = bounding_box super().__init__(mesh_id, name) self.set_dimension() if bounding_box is not None: diff --git a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py index 893ac1e..51f7dbb 100644 --- a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py +++ b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py @@ -25,7 +25,7 @@ def __init__( plane_slice_location: Tuple[float, float] = (1, -1), resolution: Tuple[float, float] = (400, 400), ): - mesh = RegularMesh2D( + self.mesh = RegularMesh2D( plane=plane, resolution=resolution, plane_slice_location=plane_slice_location, @@ -37,7 +37,7 @@ def __init__( super().__init__(tally_type) self.name = self.tally_type + "_on_2D_mesh_" + self.plane - self.filters.append(openmc.MeshFilter(mesh)) + self.filters.append(openmc.MeshFilter(self.mesh)) class MeshTallies2D: diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index 3ab4627..7804452 100644 --- a/tests/test_system/test_system_multi_volume.py +++ b/tests/test_system/test_system_multi_volume.py @@ -24,15 +24,14 @@ def setUp(self): self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/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", + 'mat_blanket': "Be", + 'mat_blanket_rear_wall': "Be", + 'mat_center_column_shield': "Be", + 'mat_divertor_lower': "Be", + 'mat_divertor_upper': "Be", + 'mat_firstwall': "Be", + 'mat_inboard_tf_coils': "Be", + 'mat_plasma': "Be" } self.material_description_smaller = { diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 1b6624a..ebe2b78 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -1,5 +1,4 @@ import os -import tarfile import unittest import urllib.request from pathlib import Path From c458566da1aa218e7ab3c50be7a7dba33e76294c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 14:13:11 +0000 Subject: [PATCH 19/23] [skip ci] sorted imports --- tests/test_geometry.py | 2 +- tests/test_materials.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 7e95d35..7aec5df 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -1,11 +1,11 @@ import tarfile import unittest import urllib.request +import zipfile from pathlib import Path import openmc import openmc_dagmc_wrapper as odw -import zipfile class TestSettings(unittest.TestCase): diff --git a/tests/test_materials.py b/tests/test_materials.py index 072fb7a..a999b98 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -1,11 +1,10 @@ -import tarfile import unittest import urllib.request +import zipfile from pathlib import Path import openmc import openmc_dagmc_wrapper as odw -import zipfile class TestMaterial(unittest.TestCase): From ac6eb7da7426a3b370013dfab7f5c55a5806bc74 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 15:07:23 +0000 Subject: [PATCH 20/23] tallies are not meshes so no bounding_box attribute --- openmc_dagmc_wrapper/Geometry.py | 6 ++- openmc_dagmc_wrapper/model.py | 4 ++ openmc_dagmc_wrapper/utils.py | 10 +++- tests/test_geometry.py | 13 ++++++ .../test_system/test_system_single_volume.py | 46 +++++++++---------- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index 566ec18..76da5ac 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -2,8 +2,10 @@ import dagmc_h5m_file_inspector as di import openmc -from numpy import cos, sin from dagmc_bounding_box import DagmcBoundingBox +from numpy import cos, sin + +from .utils import check_files_exists class Geometry(openmc.Geometry): @@ -24,9 +26,9 @@ def __init__( reflective_angles: Tuple[float, float] = None, ): self.h5m_filename = h5m_filename + check_files_exists(h5m_filename) self.reflective_angles = reflective_angles self.dagmc_bounding_box = DagmcBoundingBox(h5m_filename) - super().__init__(root=self.make_root()) def corners( diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 480b7b9..2f41119 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -1,6 +1,9 @@ +from pathlib import Path + import openmc import openmc_dagmc_wrapper as odw +from .utils import check_files_exists class Model(openmc.Model): @@ -26,6 +29,7 @@ def __init__( plots (openmc.Plots, optional): Plot information. Defaults to None. """ super().__init__(geometry, materials, settings, tallies, plots) + check_files_exists(self.geometry.h5m_filename) self.materials.checks(self.geometry.h5m_filename) self.check_tallies_meshes_corners() diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index e7978ca..dd7caa1 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -1,9 +1,15 @@ import os -import openmc +from pathlib import Path -import neutronics_material_maker as nmm import dagmc_h5m_file_inspector as di +import neutronics_material_maker as nmm +import openmc + + +def check_files_exists(filename): + if not Path(filename).is_file(): + raise FileNotFoundError('file not found') def create_material(material_tag: str, material_entry): if isinstance(material_entry, str): diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 7aec5df..b064ce6 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -72,3 +72,16 @@ def test_corners_expand_increases_size(self): 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] + + def test_geometry_with_missing_h5m_file(self): + """Creates Geometry objects and to check if error handeling is working""" + + def test_missing_h5m_file_error_handling(): + """Attempts to simulate without a dagmc_smaller.h5m file which + should fail with a FileNotFoundError""" + + odw.Geometry(h5m_filename='not_file_here.h5m') + + self.assertRaises( + FileNotFoundError, + test_missing_h5m_file_error_handling) \ No newline at end of file diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 30fb8e0..9f43c64 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -67,7 +67,7 @@ def test_simulation_with_previous_h5m_file(self): correspondence_dict={ "mat_my_material": "WC"}) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[], @@ -95,7 +95,7 @@ def test_simulation_with_previous_h5m_file_with_graveyard_removed(self): correspondence_dict={"mat_my_material": "WC"}, ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[], @@ -125,7 +125,7 @@ def test_neutronics_component_simulation_with_openmc_mat(self): target="mat_my_material", materials=materials) self.settings.batches = 2 - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[my_tally], @@ -153,7 +153,7 @@ def test_neutronics_component_simulation_with_nmm(self): my_tally = odw.CellTally("heating", target=1) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[my_tally], @@ -203,7 +203,7 @@ def test_neutronics_component_cell_simulation_heating(self): "neutron_spectra", "photon_spectra"]) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -234,7 +234,7 @@ def test_neutronics_spectra(self): "neutron_spectra", "photon_spectra"]) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -263,7 +263,7 @@ def test_neutronics_component_2d_mesh_simulation(self): bounding_box=geometry.corners(), ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -295,7 +295,7 @@ def test_neutronics_component_3d_mesh_simulation(self): bounding_box=geometry.corners(), ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -335,7 +335,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): bounding_box=geometry.corners(), ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[my_3d_tally] + my_2d_tallies.tallies, @@ -373,11 +373,12 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( bounding_box=[(5, 5, 5), (15, 15, 15)], ) - assert my_3d_tally.bounding_box == [(0, 0, 0), (10, 10, 10)] - for tally in my_2d_tallies.tallies: - assert tally.bounding_box == [(5, 5, 5), (15, 15, 15)] + # Removed as tallies are not meshes + # assert my_3d_tally.bounding_box == [(0, 0, 0), (10, 10, 10)] + # for tally in my_2d_tallies.tallies: + # assert tally.bounding_box == [(5, 5, 5), (15, 15, 15)] - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[my_3d_tally] + my_2d_tallies.tallies, @@ -405,7 +406,7 @@ def test_reactor_from_shapes_cell_tallies(self): my_tallies = odw.CellTallies(tally_types=["TBR", "heating", "flux"]) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -433,7 +434,7 @@ def test_cell_tallies_simulation_fast_flux(self): tally_types=["photon_fast_flux", "neutron_fast_flux", "flux"] ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -461,7 +462,7 @@ def test_cell_tallies_simulation_effective_dose(self): tally_types=["photon_effective_dose", "neutron_effective_dose"] ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -485,7 +486,7 @@ def test_cell_tallies_simulation_effective_dose(self): # my_tallies = odw.CellTallies( # tally_types=["(n,Xt)", "heating", "flux"]) - # my_model = openmc.model.Model( + # my_model = openmc.Model( # geometry=geometry, # materials=materials, # tallies=my_tallies.tallies, @@ -505,10 +506,6 @@ def test_missing_h5m_file_error_handling(): """Attempts to simulate without a dagmc_smaller.h5m file which should fail with a FileNotFoundError""" - import shutil - - shutil.copy(self.h5m_filename_smaller, ".") - # creates xml files so that the code passes the xml file check os.system("touch geometry.xml") os.system("touch materials.xml") @@ -516,12 +513,11 @@ def test_missing_h5m_file_error_handling(): os.system("touch tallies.xml") os.system("rm dagmc.h5m") - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - openmc.model.Model( + geometry.h5m_filename = 'changed_to_file_that_does_not_exist' + odw.Model( geometry=geometry, materials=materials, tallies=[], From 22f728465381056d5eddb928e09e39742b30dcc4 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Wed, 2 Mar 2022 15:07:54 +0000 Subject: [PATCH 21/23] Automated autopep8 fixes --- openmc_dagmc_wrapper/utils.py | 1 + tests/test_geometry.py | 2 +- tests/test_system/test_system_single_volume.py | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index dd7caa1..5679fb3 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -11,6 +11,7 @@ def check_files_exists(filename): if not Path(filename).is_file(): raise FileNotFoundError('file not found') + def create_material(material_tag: str, material_entry): if isinstance(material_entry, str): openmc_material = nmm.Material.from_library( diff --git a/tests/test_geometry.py b/tests/test_geometry.py index b064ce6..663f9a2 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -84,4 +84,4 @@ def test_missing_h5m_file_error_handling(): self.assertRaises( FileNotFoundError, - test_missing_h5m_file_error_handling) \ No newline at end of file + test_missing_h5m_file_error_handling) diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 9f43c64..4cad97d 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -513,7 +513,9 @@ def test_missing_h5m_file_error_handling(): os.system("touch tallies.xml") os.system("rm dagmc.h5m") - materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) + materials = odw.Materials( + correspondence_dict={ + "mat_my_material": "Be"}) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) geometry.h5m_filename = 'changed_to_file_that_does_not_exist' From 265cb269397fe4eb266902837cbaa80611d23166 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 2 Mar 2022 15:11:02 +0000 Subject: [PATCH 22/23] pep8 format --- .github/workflows/autopep8.yml | 24 ------ .github/workflows/black.yml | 32 +++++++ examples/cell_tally_example.py | 10 +-- examples/regular_2d_mesh_tally_example.py | 10 +-- examples/regular_3d_mesh_tally_example.py | 4 +- openmc_dagmc_wrapper/Geometry.py | 5 +- openmc_dagmc_wrapper/Tally.py | 4 +- openmc_dagmc_wrapper/mesh.py | 6 +- openmc_dagmc_wrapper/model.py | 13 +-- openmc_dagmc_wrapper/tallies/cell_tally.py | 6 +- .../tallies/mesh_tallies/mesh_tally_2D.py | 2 +- .../tallies/mesh_tallies/tet_mesh_tallies.py | 5 +- openmc_dagmc_wrapper/utils.py | 3 +- tests/notebook_testing.py | 5 +- tests/test_geometry.py | 12 +-- tests/test_materials.py | 6 +- tests/test_neutronics_utils.py | 9 +- tests/test_system/test_system_multi_volume.py | 25 +++--- .../test_system/test_system_single_volume.py | 83 ++++++------------- tests/test_tallies/test_cell_tallies.py | 6 +- tests/test_tallies/test_mesh_tally_2d.py | 19 ++--- tests/test_tallies/test_mesh_tally_3d.py | 10 +-- 22 files changed, 126 insertions(+), 173 deletions(-) delete mode 100644 .github/workflows/autopep8.yml create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/autopep8.yml b/.github/workflows/autopep8.yml deleted file mode 100644 index bc55247..0000000 --- a/.github/workflows/autopep8.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: autopep8 -on: pull_request -jobs: - autopep8: - # Check if the PR is not from a fork - if: github.event.pull_request.head.repo.full_name == github.repository - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - ref: ${{ github.head_ref }} - - name: autopep8 - id: autopep8 - uses: peter-evans/autopep8@v1 - with: - args: --exclude=make_faceteted_neutronics_model.py --exit-code --recursive --in-place --aggressive --aggressive . - - name: Commit autopep8 changes - if: steps.autopep8.outputs.exit-code == 2 - run: | - git config --global user.name 'autopep8' - git config --global user.email 'autopep8@users.noreply.github.com' - git commit -am "Automated autopep8 fixes" - git push diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..309e529 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,32 @@ +name: black + +on: + push: + paths: + - '**.py' + +defaults: + run: + shell: bash + +jobs: + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install black + run: | + python -m pip install --upgrade pip + pip install black + - name: Run black + run: | + black . + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "[skip ci] Apply formatting changes" diff --git a/examples/cell_tally_example.py b/examples/cell_tally_example.py index 47708f9..a747f12 100644 --- a/examples/cell_tally_example.py +++ b/examples/cell_tally_example.py @@ -47,16 +47,12 @@ # scores) to be applied to a DAGMC material or a volume # This cell tally applies a TBR tally to the volume(s) labeled with the # blanket_mat tag in the DAGMC geometry -tally1 = odw.CellTally( - tally_type="TBR", - target="blanket_mat", - materials=materials) +tally1 = odw.CellTally(tally_type="TBR", target="blanket_mat", materials=materials) # This cell tally obtains the neutron fast flux on all volumes in the problem tally2 = odw.CellTallies( - tally_types=["neutron_fast_flux"], - targets="all_volumes", - h5m_filename=h5m_filename) + tally_types=["neutron_fast_flux"], targets="all_volumes", h5m_filename=h5m_filename +) # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1] + tally2.tallies) diff --git a/examples/regular_2d_mesh_tally_example.py b/examples/regular_2d_mesh_tally_example.py index 8e2b85f..09eece1 100644 --- a/examples/regular_2d_mesh_tally_example.py +++ b/examples/regular_2d_mesh_tally_example.py @@ -47,14 +47,8 @@ # applied across the entire geomtry with and the size of the geometry is # automatically found. -tally1 = odw.MeshTally2D( - tally_type="photon_effective_dose", - plane="xy" -) -tally2 = odw.MeshTally2D( - tally_type="neutron_effective_dose", - plane="xy" -) +tally1 = odw.MeshTally2D(tally_type="photon_effective_dose", plane="xy") +tally2 = odw.MeshTally2D(tally_type="neutron_effective_dose", plane="xy") # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1, tally2]) diff --git a/examples/regular_3d_mesh_tally_example.py b/examples/regular_3d_mesh_tally_example.py index cd3e20a..d938bad 100644 --- a/examples/regular_3d_mesh_tally_example.py +++ b/examples/regular_3d_mesh_tally_example.py @@ -47,9 +47,7 @@ # and scores) to be applied to the DAGMC geometry. By default the mesh will be # applied across the entire geomtry with and the size of the geometry is # automatically found. -tally1 = odw.MeshTally3D( - tally_type="neutron_effective_dose" -) +tally1 = odw.MeshTally3D(tally_type="neutron_effective_dose") # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1]) diff --git a/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index 76da5ac..89718e6 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -58,7 +58,7 @@ def make_root(self): vac_surf = openmc.Sphere( r=1000000, # set to 10km to be big enough for models surface_id=99999999, # set to large surface id to avoid overlaps - boundary_type="vacuum" + boundary_type="vacuum", ) region = -vac_surf @@ -95,8 +95,7 @@ def make_root(self): vac_surf = self.create_sphere_of_vacuum_surface() region = -vac_surf & -reflective_1 & +reflective_2 - containing_cell = openmc.Cell( - cell_id=9999, region=region, fill=dag_univ) + containing_cell = openmc.Cell(cell_id=9999, region=region, fill=dag_univ) root = [containing_cell] diff --git a/openmc_dagmc_wrapper/Tally.py b/openmc_dagmc_wrapper/Tally.py index 7a26971..db01c96 100644 --- a/openmc_dagmc_wrapper/Tally.py +++ b/openmc_dagmc_wrapper/Tally.py @@ -120,9 +120,7 @@ def compute_filters(tally_type): energy_function_filter_n = openmc.EnergyFunctionFilter( energy_bins_n, dose_coeffs_n ) - additional_filters = [ - neutron_particle_filter, - energy_function_filter_n] + additional_filters = [neutron_particle_filter, energy_function_filter_n] elif tally_type == "photon_effective_dose": energy_function_filter_p = openmc.EnergyFunctionFilter( energy_bins_p, dose_coeffs_p diff --git a/openmc_dagmc_wrapper/mesh.py b/openmc_dagmc_wrapper/mesh.py index 455cd10..d430394 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -5,12 +5,12 @@ class RegularMesh2D(openmc.RegularMesh): def __init__( self, mesh_id=None, - name='', + name="", plane="xy", resolution=(400, 400), plane_slice_location=(-1, 1), # TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)] - bounding_box=None + bounding_box=None, ): self.plane = plane self.resolution = resolution @@ -83,7 +83,7 @@ def set_bounds(self, bounding_box): class UnstructuredMesh(openmc.UnstructuredMesh): - def __init__(self, filename, mesh_id=None, name='', length_multiplier=1): + def __init__(self, filename, mesh_id=None, name="", length_multiplier=1): if filename.endswith(".exo"): # requires a exo file export from cubit library = "libmesh" diff --git a/openmc_dagmc_wrapper/model.py b/openmc_dagmc_wrapper/model.py index 2f41119..62e3fad 100644 --- a/openmc_dagmc_wrapper/model.py +++ b/openmc_dagmc_wrapper/model.py @@ -8,12 +8,7 @@ class Model(openmc.Model): def __init__( - self, - geometry=None, - materials=None, - settings=None, - tallies=None, - plots=None + self, geometry=None, materials=None, settings=None, tallies=None, plots=None ): """Inits Model @@ -43,9 +38,7 @@ def check_tallies_meshes_corners(self): if isinstance(tally_filter.mesh, odw.RegularMesh2D): corners = [ tally_filter.mesh.lower_left, - tally_filter.mesh.upper_right + tally_filter.mesh.upper_right, ] if None in corners: - tally_filter.mesh.set_bounds( - self.geometry.corners() - ) + tally_filter.mesh.set_bounds(self.geometry.corners()) diff --git a/openmc_dagmc_wrapper/tallies/cell_tally.py b/openmc_dagmc_wrapper/tallies/cell_tally.py index 88cc473..f5b5e87 100644 --- a/openmc_dagmc_wrapper/tallies/cell_tally.py +++ b/openmc_dagmc_wrapper/tallies/cell_tally.py @@ -115,7 +115,5 @@ def __init__( for score in self.tally_types: for target in all_targets: self.tallies.append( - CellTally( - tally_type=score, - target=target, - materials=materials)) + CellTally(tally_type=score, target=target, materials=materials) + ) diff --git a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py index 51f7dbb..1c4bc00 100644 --- a/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py +++ b/openmc_dagmc_wrapper/tallies/mesh_tallies/mesh_tally_2D.py @@ -29,7 +29,7 @@ def __init__( plane=plane, resolution=resolution, plane_slice_location=plane_slice_location, - bounding_box=bounding_box + bounding_box=bounding_box, ) self.plane = plane diff --git a/openmc_dagmc_wrapper/tallies/mesh_tallies/tet_mesh_tallies.py b/openmc_dagmc_wrapper/tallies/mesh_tallies/tet_mesh_tallies.py index d35c0dc..235f6e7 100644 --- a/openmc_dagmc_wrapper/tallies/mesh_tallies/tet_mesh_tallies.py +++ b/openmc_dagmc_wrapper/tallies/mesh_tallies/tet_mesh_tallies.py @@ -37,7 +37,4 @@ def __init__(self, tally_types, filenames): self.tally_types = tally_types for score in self.tally_types: for filename in filenames: - self.tallies.append( - TetMeshTally( - tally_type=score, - filename=filename)) + self.tallies.append(TetMeshTally(tally_type=score, filename=filename)) diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index dd7caa1..4a33aeb 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -9,7 +9,8 @@ def check_files_exists(filename): if not Path(filename).is_file(): - raise FileNotFoundError('file not found') + raise FileNotFoundError("file not found") + def create_material(material_tag: str, material_entry): if isinstance(material_entry, str): diff --git a/tests/notebook_testing.py b/tests/notebook_testing.py index c3f96c1..ae4b7df 100644 --- a/tests/notebook_testing.py +++ b/tests/notebook_testing.py @@ -21,10 +21,7 @@ def notebook_run(path): ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=800) try: - ep.preprocess( - note_book, { - "metadata": { - "path": this_file_directory}}) + ep.preprocess(note_book, {"metadata": {"path": this_file_directory}}) except CellExecutionError as e: if "SKIP" in e.traceback: diff --git a/tests/test_geometry.py b/tests/test_geometry.py index b064ce6..f9d4093 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -17,10 +17,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { @@ -80,8 +82,6 @@ def test_missing_h5m_file_error_handling(): """Attempts to simulate without a dagmc_smaller.h5m file which should fail with a FileNotFoundError""" - odw.Geometry(h5m_filename='not_file_here.h5m') + odw.Geometry(h5m_filename="not_file_here.h5m") - self.assertRaises( - FileNotFoundError, - test_missing_h5m_file_error_handling) \ No newline at end of file + self.assertRaises(FileNotFoundError, test_missing_h5m_file_error_handling) diff --git a/tests/test_materials.py b/tests/test_materials.py index a999b98..cb95e1b 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -16,10 +16,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index a6510db..52a5335 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -19,10 +19,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_get_an_isotope_present_in_cross_sections_xml(self): @@ -34,8 +36,7 @@ def test_get_an_isotope_present_in_cross_sections_xml(self): # could be an isotope such as Ag107 or H3 or and element such as H assert len(isotope) in [1, 2, 3, 4, 5] - def test_get_an_isotope_present_in_cross_sections_xml_error_handeling( - self): + def test_get_an_isotope_present_in_cross_sections_xml_error_handeling(self): """Checks that an error message is raised if the OPENMC_CROSS_SECTIONS variable does not exist""" diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index b0de9e3..dbab72a 100644 --- a/tests/test_system/test_system_multi_volume.py +++ b/tests/test_system/test_system_multi_volume.py @@ -17,21 +17,23 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description_bigger = { - 'mat_blanket': "Be", - 'mat_blanket_rear_wall': "Be", - 'mat_center_column_shield': "Be", - 'mat_divertor_lower': "Be", - 'mat_divertor_upper': "Be", - 'mat_firstwall': "Be", - 'mat_inboard_tf_coils': "Be", - 'mat_plasma': "Be" + "mat_blanket": "Be", + "mat_blanket_rear_wall": "Be", + "mat_center_column_shield": "Be", + "mat_divertor_lower": "Be", + "mat_divertor_upper": "Be", + "mat_firstwall": "Be", + "mat_inboard_tf_coils": "Be", + "mat_plasma": "Be", } self.material_description_smaller = { @@ -58,8 +60,7 @@ def test_cell_tally_simulation(self): os.system("rm statepoint*.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_bigger) - materials = odw.Materials( - correspondence_dict=self.material_description_bigger) + materials = odw.Materials(correspondence_dict=self.material_description_bigger) my_tally = odw.CellTally("TBR") my_model = openmc.model.Model( geometry=geometry, diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 9f43c64..35bcd4a 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -19,10 +19,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" self.material_description = { @@ -63,15 +65,11 @@ def test_simulation_with_previous_h5m_file(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "WC"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "WC"}) my_model = openmc.Model( - geometry=geometry, - materials=materials, - tallies=[], - settings=self.settings) + geometry=geometry, materials=materials, tallies=[], settings=self.settings + ) statepoint_file = my_model.run() @@ -96,10 +94,8 @@ def test_simulation_with_previous_h5m_file_with_graveyard_removed(self): ) my_model = openmc.Model( - geometry=geometry, - materials=materials, - tallies=[], - settings=self.settings) + geometry=geometry, materials=materials, tallies=[], settings=self.settings + ) statepoint_file = my_model.run() @@ -121,9 +117,8 @@ def test_neutronics_component_simulation_with_openmc_mat(self): ) my_tally = odw.CellTally( - "heating", - target="mat_my_material", - materials=materials) + "heating", target="mat_my_material", materials=materials + ) self.settings.batches = 2 my_model = openmc.Model( geometry=geometry, @@ -147,9 +142,7 @@ def test_neutronics_component_simulation_with_nmm(self): test_mat = nmm.Material.from_library("Be") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": test_mat}) + materials = odw.Materials(correspondence_dict={"mat_my_material": test_mat}) my_tally = odw.CellTally("heating", target=1) @@ -196,12 +189,8 @@ def test_neutronics_component_cell_simulation_heating(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials(correspondence_dict={"mat_my_material": mat}) my_tallies = odw.CellTallies( - tally_types=[ - "heating", - "flux", - "TBR", - "neutron_spectra", - "photon_spectra"]) + tally_types=["heating", "flux", "TBR", "neutron_spectra", "photon_spectra"] + ) my_model = openmc.Model( geometry=geometry, @@ -229,10 +218,7 @@ def test_neutronics_spectra(self): geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) materials = odw.Materials(correspondence_dict={"mat_my_material": mat}) - my_tallies = odw.CellTallies( - tally_types=[ - "neutron_spectra", - "photon_spectra"]) + my_tallies = odw.CellTallies(tally_types=["neutron_spectra", "photon_spectra"]) my_model = openmc.Model( geometry=geometry, @@ -253,9 +239,7 @@ def test_neutronics_component_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies2D( tally_types=["heating"], @@ -286,9 +270,7 @@ def test_neutronics_component_3d_mesh_simulation(self): os.system("rm *.vtk") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], @@ -320,9 +302,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -348,8 +328,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self): assert len(results.meshes) == 4 # one 3D and three 2D assert len(results.tallies.items()) == 4 # one 3D and three 2D - def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( - self): + def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points(self): """Makes a neutronics model and simulates with a 3D and 2D mesh tally and checks that the vtk and png files are produced. This checks the mesh ID values don't overlap""" @@ -358,9 +337,7 @@ def test_neutronics_component_3d_and_2d_mesh_simulation_with_corner_points( os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -400,9 +377,7 @@ def test_reactor_from_shapes_cell_tallies(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies(tally_types=["TBR", "heating", "flux"]) @@ -426,9 +401,7 @@ def test_cell_tallies_simulation_fast_flux(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_fast_flux", "neutron_fast_flux", "flux"] @@ -454,9 +427,7 @@ def test_cell_tallies_simulation_effective_dose(self): os.system("rm summary.h5") geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( tally_types=["photon_effective_dose", "neutron_effective_dose"] @@ -516,17 +487,15 @@ def test_missing_h5m_file_error_handling(): materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) - geometry.h5m_filename = 'changed_to_file_that_does_not_exist' + geometry.h5m_filename = "changed_to_file_that_does_not_exist" odw.Model( geometry=geometry, materials=materials, tallies=[], - settings=self.settings + settings=self.settings, ) - self.assertRaises( - FileNotFoundError, - test_missing_h5m_file_error_handling) + self.assertRaises(FileNotFoundError, test_missing_h5m_file_error_handling) if __name__ == "__main__": diff --git a/tests/test_tallies/test_cell_tallies.py b/tests/test_tallies/test_cell_tallies.py index 8820460..7405db9 100644 --- a/tests/test_tallies/test_cell_tallies.py +++ b/tests/test_tallies/test_cell_tallies.py @@ -15,10 +15,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_name(self): diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py index 449bf89..3687842 100644 --- a/tests/test_tallies/test_mesh_tally_2d.py +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -17,10 +17,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_incorrect_mesh_tally_2d(self): @@ -29,8 +31,8 @@ def test_incorrect_mesh_tally_2d(self): def incorrect_mesh_tally_2d(): odw.MeshTally2D( - "coucou", bounding_box=[ - (10, 10, 10), (-10, -10, -10)], plane="xy") + "coucou", bounding_box=[(10, 10, 10), (-10, -10, -10)], plane="xy" + ) self.assertRaises(ValueError, incorrect_mesh_tally_2d) @@ -81,17 +83,14 @@ def test_shape_of_resulting_png(self): settings.source = FusionRingSource(fuel="DT", radius=1) my_model = openmc.Model( - materials=materials, - geometry=geometry, - settings=settings, - tallies=tallies) + materials=materials, geometry=geometry, settings=settings, tallies=tallies + ) statepoint_file = my_model.run() assert Path(statepoint_file).exists() def test_correct_resolution(self): - """Tests that the mesh resolution is in accordance with the plane - """ + """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", diff --git a/tests/test_tallies/test_mesh_tally_3d.py b/tests/test_tallies/test_mesh_tally_3d.py index 99959a5..be4a58d 100644 --- a/tests/test_tallies/test_mesh_tally_3d.py +++ b/tests/test_tallies/test_mesh_tally_3d.py @@ -16,10 +16,12 @@ def setUp(self): url = "https://github.com/fusion-energy/fusion_neutronics_workflow/releases/download/0.0.8/output_files_produced.zip" urllib.request.urlretrieve(url, "tests/output_files_produced.zip") - with zipfile.ZipFile("tests/output_files_produced.zip", 'r') as zip_ref: + with zipfile.ZipFile("tests/output_files_produced.zip", "r") as zip_ref: zip_ref.extractall("tests") - self.h5m_filename_smaller = "tests/example_01_single_volume_cell_tally/dagmc.h5m" + self.h5m_filename_smaller = ( + "tests/example_01_single_volume_cell_tally/dagmc.h5m" + ) self.h5m_filename_bigger = "tests/example_02_multi_volume_cell_tally/dagmc.h5m" def test_incorrect_mesh_tally_3d(self): @@ -27,9 +29,7 @@ def test_incorrect_mesh_tally_3d(self): error""" def incorrect_mesh_tally_3d(): - odw.MeshTally3D( - "coucou", bounding_box=[ - (10, 10, 10), (-10, -10, -10)]) + odw.MeshTally3D("coucou", bounding_box=[(10, 10, 10), (-10, -10, -10)]) self.assertRaises(ValueError, incorrect_mesh_tally_3d) From 0c3f8bc3630118d10f77643d82e6f35792c6f0dc Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 2 Mar 2022 15:19:54 +0000 Subject: [PATCH 23/23] [skip ci] Apply formatting changes --- openmc_dagmc_wrapper/utils.py | 1 - tests/test_geometry.py | 4 +--- tests/test_system/test_system_single_volume.py | 4 +--- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index b6d6f70..4a33aeb 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -12,7 +12,6 @@ def check_files_exists(filename): raise FileNotFoundError("file not found") - def create_material(material_tag: str, material_entry): if isinstance(material_entry, str): openmc_material = nmm.Material.from_library( diff --git a/tests/test_geometry.py b/tests/test_geometry.py index a029ccb..f9d4093 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -84,6 +84,4 @@ def test_missing_h5m_file_error_handling(): odw.Geometry(h5m_filename="not_file_here.h5m") - self.assertRaises( - FileNotFoundError, - test_missing_h5m_file_error_handling) + self.assertRaises(FileNotFoundError, test_missing_h5m_file_error_handling) diff --git a/tests/test_system/test_system_single_volume.py b/tests/test_system/test_system_single_volume.py index 7fc52f8..35bcd4a 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -484,9 +484,7 @@ def test_missing_h5m_file_error_handling(): os.system("touch tallies.xml") os.system("rm dagmc.h5m") - materials = odw.Materials( - correspondence_dict={ - "mat_my_material": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) geometry.h5m_filename = "changed_to_file_that_does_not_exist"