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/.gitignore b/.gitignore index f559df3..bd05d54 100644 --- a/.gitignore +++ b/.gitignore @@ -142,5 +142,11 @@ 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 + +_version.py 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 58277f9..09eece1 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,25 +41,14 @@ }, ) -# 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 # 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", - bounding_box=my_bounding_box) -tally2 = odw.MeshTally2D( - tally_type="neutron_effective_dose", - plane="xy", - bounding_box=my_bounding_box) +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]) @@ -79,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() diff --git a/examples/regular_3d_mesh_tally_example.py b/examples/regular_3d_mesh_tally_example.py index 8cd8a05..d938bad 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,18 +42,12 @@ }, ) -# 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 -) +tally1 = odw.MeshTally3D(tally_type="neutron_effective_dose") # no modifications are made to the default openmc.Tallies tallies = openmc.Tallies([tally1]) @@ -72,7 +64,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/openmc_dagmc_wrapper/Geometry.py b/openmc_dagmc_wrapper/Geometry.py index f5615ab..89718e6 100644 --- a/openmc_dagmc_wrapper/Geometry.py +++ b/openmc_dagmc_wrapper/Geometry.py @@ -2,15 +2,15 @@ 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): - """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,23 +18,17 @@ 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 + check_files_exists(h5m_filename) self.reflective_angles = reflective_angles - self.graveyard_box = graveyard_box self.dagmc_bounding_box = DagmcBoundingBox(h5m_filename) - super().__init__(root=self.make_root()) def corners( @@ -61,19 +55,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: @@ -105,27 +95,8 @@ 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] 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: - 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/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/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/__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..d430394 100644 --- a/openmc_dagmc_wrapper/mesh.py +++ b/openmc_dagmc_wrapper/mesh.py @@ -5,42 +5,46 @@ class RegularMesh2D(openmc.RegularMesh): def __init__( self, mesh_id=None, - name='', + name="", plane="xy", resolution=(400, 400), plane_slice_location=(-1, 1), - bounding_box=None # TODO replace this by [(xmin, xmax), (ymin, ymax)] + # TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)] + bounding_box=None, ): 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() - self.set_bounds(bounding_box) + if bounding_box is not None: + self.set_bounds(bounding_box) 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], @@ -48,38 +52,38 @@ 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], ] 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 new file mode 100644 index 0000000..62e3fad --- /dev/null +++ b/openmc_dagmc_wrapper/model.py @@ -0,0 +1,44 @@ +from pathlib import Path + +import openmc + +import openmc_dagmc_wrapper as odw +from .utils import check_files_exists + + +class Model(openmc.Model): + def __init__( + self, geometry=None, materials=None, settings=None, 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) + check_files_exists(self.geometry.h5m_filename) + 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 tally_filter in tally.filters: + if isinstance(tally_filter, openmc.MeshFilter): + if isinstance(tally_filter.mesh, odw.RegularMesh2D): + corners = [ + tally_filter.mesh.lower_left, + tally_filter.mesh.upper_right, + ] + if None in 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 d745936..1c4bc00 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,18 +23,21 @@ 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( + self.mesh = RegularMesh2D( plane=plane, - resolution=mesh_resolution, + resolution=resolution, plane_slice_location=plane_slice_location, - bounding_box=bounding_box + 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)) + self.filters.append(openmc.MeshFilter(self.mesh)) class MeshTallies2D: @@ -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/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 e7978ca..4a33aeb 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -1,8 +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): 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/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 af7b68d..f9d4093 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -1,6 +1,7 @@ import tarfile import unittest import urllib.request +import zipfile from pathlib import Path import openmc @@ -12,16 +13,17 @@ class TestSettings(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", @@ -38,7 +40,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""" @@ -73,3 +74,14 @@ 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) diff --git a/tests/test_materials.py b/tests/test_materials.py index a55f673..cb95e1b 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -1,6 +1,6 @@ -import tarfile import unittest import urllib.request +import zipfile from pathlib import Path import openmc @@ -12,16 +12,17 @@ class TestMaterial(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", @@ -37,10 +38,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 +50,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 +58,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_neutronics_utils.py b/tests/test_neutronics_utils.py index 8ffe909..52a5335 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,17 @@ 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 @@ -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""" @@ -150,7 +151,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)) diff --git a/tests/test_system/test_system_multi_volume.py b/tests/test_system/test_system_multi_volume.py index 5175005..dbab72a 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,27 +13,27 @@ 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", - "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 = { @@ -60,10 +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( - 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 6c71247..35bcd4a 100644 --- a/tests/test_system/test_system_single_volume.py +++ b/tests/test_system/test_system_single_volume.py @@ -1,9 +1,8 @@ import os -import tarfile 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 +15,17 @@ 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", @@ -65,16 +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( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "WC"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "WC"}) - my_model = openmc.model.Model( - geometry=geometry, - materials=materials, - tallies=[], - settings=self.settings) + my_model = openmc.Model( + geometry=geometry, materials=materials, tallies=[], settings=self.settings + ) statepoint_file = my_model.run() @@ -95,15 +90,12 @@ 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"}, + correspondence_dict={"mat_my_material": "WC"}, ) - my_model = openmc.model.Model( - geometry=geometry, - materials=materials, - tallies=[], - settings=self.settings) + my_model = openmc.Model( + geometry=geometry, materials=materials, tallies=[], settings=self.settings + ) statepoint_file = my_model.run() @@ -121,23 +113,24 @@ 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}, + 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( + my_model = openmc.Model( geometry=geometry, materials=materials, 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): @@ -149,23 +142,20 @@ 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={"mat_my_material": test_mat}) my_tally = odw.CellTally("heating", target=1) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=[my_tally], 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): @@ -197,28 +187,21 @@ 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={"mat_my_material": mat}) my_tallies = odw.CellTallies( - tally_types=[ - "heating", - "flux", - "TBR", - "neutron_spectra", - "photon_spectra"]) - - my_model = openmc.model.Model( + tally_types=["heating", "flux", "TBR", "neutron_spectra", "photon_spectra"] + ) + + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, 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 @@ -234,16 +217,10 @@ 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}) - my_tallies = odw.CellTallies( - tally_types=[ - "neutron_spectra", - "photon_spectra"]) + materials = odw.Materials(correspondence_dict={"mat_my_material": mat}) + my_tallies = odw.CellTallies(tally_types=["neutron_spectra", "photon_spectra"]) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, @@ -262,10 +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( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies2D( tally_types=["heating"], @@ -273,16 +247,16 @@ 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, 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 @@ -296,31 +270,28 @@ 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={"mat_my_material": "Be"}) my_tallies = odw.MeshTallies3D( tally_types=["heating", "(n,Xt)"], bounding_box=geometry.corners(), ) - my_model = openmc.model.Model( + my_model = openmc.Model( geometry=geometry, materials=materials, tallies=my_tallies.tallies, 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 @@ -331,10 +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( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -347,21 +315,20 @@ 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, 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 - 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""" @@ -370,10 +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( - h5m_filename=self.h5m_filename_smaller, - correspondence_dict={ - "mat1": "Be"}) + materials = odw.Materials(correspondence_dict={"mat_my_material": "Be"}) my_3d_tally = odw.MeshTally3D( tally_type="heating", @@ -386,11 +350,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, @@ -398,9 +363,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 @@ -412,14 +377,11 @@ 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={"mat_my_material": "Be"}) 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, @@ -439,16 +401,13 @@ 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={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( 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, @@ -468,16 +427,13 @@ 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={"mat_my_material": "Be"}) my_tallies = odw.CellTallies( 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, @@ -496,13 +452,12 @@ 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"}) + # correspondence_dict={"mat_my_material": "Be"}) # 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, @@ -522,10 +477,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") @@ -533,14 +484,18 @@ def test_missing_h5m_file_error_handling(): os.system("touch tallies.xml") os.system("rm dagmc.h5m") - odw.Materials( - h5m_filename="dagmc.h5m", - correspondence_dict={ - "mat1": "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" + odw.Model( + geometry=geometry, + materials=materials, + tallies=[], + 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 ed95143..7405db9 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,17 @@ 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..3687842 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,17 @@ 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 @@ -30,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) @@ -50,28 +51,27 @@ 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", + "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]) @@ -83,35 +83,32 @@ 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", 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] diff --git a/tests/test_tallies/test_mesh_tally_3d.py b/tests/test_tallies/test_mesh_tally_3d.py index 36d6a81..be4a58d 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,25 +12,24 @@ 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 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)