From e6cc4516c2ecee3908cb85fd30105d540fefa0cf Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 Sep 2021 15:34:53 +0100 Subject: [PATCH 01/29] added fast flux as an options --- openmc_dagmc_wrapper/neutronics_model.py | 32 ++++++++++++++++++++---- tests/test_neutronics_model.py | 30 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 8b0c87e..0320f6a 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -171,7 +171,8 @@ def cell_tallies(self, value): "flux", "spectra", "absorption", - "effective_dose"] + + "effective_dose", + "fast_flux"] + list( REACTION_MT.keys()) + list( @@ -394,9 +395,9 @@ def export_xml( Defaults to None which uses the NeutronicsModel.mesh_tally_2d attribute. cell_tallies: the cell based tallies to calculate, options include - TBR, heating, flux, MT numbers, effective_dose and OpenMC - standard scores such as (n,Xa) which is helium production are - also supported + TBR, heating, flux, MT numbers, effective_dose, fast_flux and + OpenMC standard scores such as (n,Xa) which is helium production + are also supported https://docs.openmc.org/en/latest/usersguide/tallies.html#scores. Defaults to None which uses the NeutronicsModel.cell_tallies attribute. @@ -505,6 +506,7 @@ def export_xml( mesh_xyz.upper_right = self.mesh_3d_corners[1] for standard_tally in self.mesh_tally_3d: + if standard_tally == "effective_dose": energy_bins_n, dose_coeffs_n = openmc.data.dose_coefficients( particle="neutron", @@ -665,6 +667,27 @@ def export_xml( self.tallies.append(tally) self._add_tally_for_every_material(suffix, score) + elif standard_tally == "fast_flux": + + energy_bins = [1e6, 1000e6] + energy_filter = openmc.EnergyFilter(energy_bins) + + neutron_particle_filter = openmc.ParticleFilter([ + "neutron"]) + self._add_tally_for_every_material( + "neutron_spectra", + "flux", + [neutron_particle_filter, energy_filter], + ) + if self.photon_transport is True: + photon_particle_filter = openmc.ParticleFilter([ + "photon"]) + self._add_tally_for_every_material( + "photon_spectra", + "flux", + [photon_particle_filter, energy_filter], + ) + elif standard_tally == "spectra": energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"] @@ -699,7 +722,6 @@ def export_xml( energy_function_filter_n = openmc.EnergyFunctionFilter( energy_bins_n, dose_coeffs_n ) - # energy_function_filter_p = openmc.EnergyFunctionFilter(energy_bins_p, dose_coeffs_p) self._add_tally_for_every_material( "neutron_effective_dose", diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 37db834..cd40043 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -562,6 +562,36 @@ def test_reactor_from_shapes_cell_tallies(self): assert isinstance(my_model.results["TBR"]["result"], float) assert Path("results.json").exists() is True + def test_cell_tallies_simulation_fast_flux(self): + """Performs simulation with h5m file and tallies neutron and photon + fast flux. Checks that entries exist in the results.""" + + os.system("rm results.json") + + my_model = openmc_dagmc_wrapper.NeutronicsModel( + h5m_filename=self.h5m_filename_smaller, + source=self.source, + materials={"mat1": "Be"}, + cell_tallies=["fast_flux"], + photon_transport=True, + ) + + # starts the neutronics simulation + my_model.simulate( + simulation_batches=2, + simulation_particles_per_batch=10, + ) + + my_model.process_results( + fusion_power=1e9, + fusion_energy_per_pulse=1.2e6 + ) + + assert isinstance( + my_model.results["mat1_neutron_fast_flux"]["result"], + float, + ) + def test_cell_tallies_simulation_effective_dose(self): """Performs simulation with h5m file and tallies neutron and photon dose. Checks that entries exist in the results.""" From 7944c4fc16558a03f9fac1fe80286f562e9d1d06 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 09:33:20 +0100 Subject: [PATCH 02/29] refactored making use of dagmc_h5m_file_inspector --- openmc_dagmc_wrapper/neutronics_model.py | 41 +++++++------ openmc_dagmc_wrapper/utils.py | 73 ------------------------ setup.py | 3 +- tests/test_neutronics_utils.py | 53 ++++------------- 4 files changed, 32 insertions(+), 138 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 8b0c87e..03aaeaf 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -2,19 +2,17 @@ from pathlib import Path from typing import List, Optional, Tuple, Union +import dagmc_h5m_file_inspector as di import neutronics_material_maker as nmm import openmc import openmc.lib # needed to find bounding box of h5m file import plotly.graph_objects as go from openmc.data import REACTION_MT, REACTION_NAME -from .utils import ( - create_initial_particles, - extract_points_from_initial_source, - get_neutronics_results_from_statepoint_file, - silently_remove_file, - plotly_trace, -) +from .utils import (create_initial_particles, + extract_points_from_initial_source, + get_neutronics_results_from_statepoint_file, plotly_trace, + silently_remove_file) class NeutronicsModel: @@ -31,8 +29,8 @@ class NeutronicsModel: neutronics-material-maker.Material or neutronics-material-maker.MultiMaterial. All components within the geometry object must be accounted for. Material tags required - for a Reactor or Shape can be obtained with .material_tags() and - material_tag respectively. + for a Reactor or Shape can be obtained using the python package + dagmc_h5m_file_inspector cell_tallies: the cell based tallies to calculate, options include spectra, TBR, heating, flux, MT numbers and OpenMC standard scores such as (n,Xa) which is helium production are also supported @@ -273,19 +271,20 @@ def create_material(self, material_tag: str, material_entry): return openmc_material def create_openmc_materials(self): + + materials_in_h5m = di.get_materials_from_h5m(self.h5m_filename) # # checks all the required materials are present - # for reactor_material in self.geometry.material_tags: - # if reactor_material not in self.materials.keys(): - # raise ValueError( - # "material included by the reactor model has not \ - # been added", reactor_material) - - # # checks that no extra materials we added - # for reactor_material in self.materials.keys(): - # if reactor_material not in self.geometry.material_tags: - # raise ValueError( - # "material has been added that is not needed for this \ - # reactor model", reactor_material) + for reactor_material in self.materials.items(): + if reactor_material not in materials_in_h5m: + msg = (f"material with tag {reactor_material} was not found in" + "the dagmc h5m file") + raise ValueError(msg) + + if len(materials_in_h5m) != len(self.materials.keys()): + msg = (f"the NeutronicsModel.materials does not match the material" + "tags in the dagmc h5m file. Materials in h5m file " + f"{materials_in_h5m}. Materials provided {self.materials.keys()}") + raise ValueError(msg) silently_remove_file("materials.xml") diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index acb19c3..ad4c348 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -81,13 +81,6 @@ def plotly_trace( return trace -def load_moab_file(filename: str): - """Loads a h5m into a Moab Core object and returns the object""" - moab_core = core.Core() - moab_core.load_file(filename) - return moab_core - - def silently_remove_file(filename: str): """Allows files to be deleted without printing warning messages int the terminal. input XML files for OpenMC are deleted prior to running @@ -98,72 +91,6 @@ def silently_remove_file(filename: str): pass # in some cases the file will not exist -def find_volume_ids_in_h5m(filename: Optional[str] = "dagmc.h5m") -> List[str]: - """Reads in a DAGMC h5m file and uses PyMoab to find the volume ids of the - volumes in the file - - Arguments: - filename: - - Returns: - The filename of the h5m file created - """ - - # create a new PyMOAB instance and load the specified DAGMC file - moab_core = load_moab_file(filename) - - # retrieve the category tag on the instance - cat_tag = moab_core.tag_get_handle(types.CATEGORY_TAG_NAME) - - # get the id tag - gid_tag = moab_core.tag_get_handle(types.GLOBAL_ID_TAG_NAME) - - # get the set of entities using the provided category tag name - # (0 means search on the instance's root set) - ents = moab_core.get_entities_by_type_and_tag( - 0, types.MBENTITYSET, [cat_tag], ["Volume"] - ) - - # retrieve the IDs of the entities - ids = moab_core.tag_get_data(gid_tag, ents).flatten() - - return sorted(list(ids)) - - -def find_material_groups_in_h5m( - filename: Optional[str] = "dagmc.h5m") -> List[str]: - """Reads in a DAGMC h5m file and uses mbsize to find the names of the - material groups in the file - - Arguments: - filename: - - Returns: - The filename of the h5m file created - """ - - try: - terminal_output = subprocess.check_output( - "mbsize -ll {} | grep 'mat:'".format(filename), - shell=True, - universal_newlines=True, - ) - except BaseException: - raise ValueError( - "mbsize failed, check MOAB is install and the MOAB/build/bin " - "folder is in the path directory (Linux and Mac) or set as an " - "enviromental varible (Windows)" - ) - - list_of_mats = terminal_output.split() - list_of_mats = list(filter(lambda a: a != "=", list_of_mats)) - list_of_mats = list(filter(lambda a: a != "NAME", list_of_mats)) - list_of_mats = list(filter(lambda a: a != "EXTRA_NAME0", list_of_mats)) - list_of_mats = list(set(list_of_mats)) - - return list_of_mats - - def _save_2d_mesh_tally_as_png(score: str, filename: str, tally) -> str: """Extracts 2D mesh tally results from a tally and saves the result as a png image. diff --git a/setup.py b/setup.py index be69475..e57344a 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,8 @@ "plotly", "defusedxml", "nbformat", - "nbconvert" + "nbconvert", + "dagmc_h5m_file_inspector", ], # openmc, dagmc, moab are also needed and embree and double down are also # optionally needed but not avaible on PyPi diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 30905df..1fd9aea 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -8,20 +8,20 @@ import requests -class TestNeutronicsUtilityFunctions(unittest.TestCase): - def setUp(self): +# class TestNeutronicsUtilityFunctions(unittest.TestCase): +# def setUp(self): - url = "https://github.com/fusion-energy/neutronics_workflow/raw/main/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" +# url = "https://github.com/fusion-energy/neutronics_workflow/raw/main/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" - local_filename = "dagmc_bigger.h5m" +# local_filename = "dagmc_bigger.h5m" - if not Path(local_filename).is_file(): +# if not Path(local_filename).is_file(): - r = requests.get(url, stream=True) - with open(local_filename, "wb") as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: - f.write(chunk) +# r = requests.get(url, stream=True) +# with open(local_filename, "wb") as f: +# for chunk in r.iter_content(chunk_size=1024): +# if chunk: +# f.write(chunk) # def test_create_initial_source_file(self): # """Creates an initial_source.h5 from a point source""" @@ -83,39 +83,6 @@ def setUp(self): # self.assertRaises(ValueError, incorrect_viewplane) - def test_find_materials_in_h5_file(self): - """exports a h5m with specific material tags and checks they are - found using the find_material_groups_in_h5m utility function""" - - list_of_mats = openmc_dagmc_wrapper.find_material_groups_in_h5m( - filename="dagmc_bigger.h5m" - ) - - assert len(list_of_mats) == 10 - assert "mat:pf_coil_case_mat" in list_of_mats - assert "mat:center_column_shield_mat" in list_of_mats - assert "mat:blanket_rear_wall_mat" in list_of_mats - assert "mat:divertor_mat" in list_of_mats - assert "mat:graveyard" in list_of_mats - assert "mat:tf_coil_mat" in list_of_mats - assert "mat:pf_coil_mat" in list_of_mats - assert "mat:inboard_tf_coils_mat" in list_of_mats - assert "mat:blanket_mat" in list_of_mats - assert "mat:firstwall_mat" in list_of_mats - - def test_find_volume_ids_in_h5_file(self): - """exports a h5m with a known number of volumes and checks they are - found using the find_volume_ids_in_h5m utility function""" - - list_of_mats = openmc_dagmc_wrapper.find_volume_ids_in_h5m( - filename="dagmc_bigger.h5m" - ) - - assert len(list_of_mats) == len( - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] - ) - assert 1 in list_of_mats - # def test_create_initial_particles(self): # """Creates an initial source file using create_initial_particles utility # and checks the file exists and that the points are correct""" From ef39a4c3849c59d704550c7c102a1fa5cbb5154a Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 08:36:18 +0000 Subject: [PATCH 03/29] Automated autopep8 fixes --- openmc_dagmc_wrapper/neutronics_model.py | 7 +- tests/test_neutronics_utils.py | 120 +++++++++++------------ 2 files changed, 64 insertions(+), 63 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 03aaeaf..19372f9 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -281,9 +281,10 @@ def create_openmc_materials(self): raise ValueError(msg) if len(materials_in_h5m) != len(self.materials.keys()): - msg = (f"the NeutronicsModel.materials does not match the material" - "tags in the dagmc h5m file. Materials in h5m file " - f"{materials_in_h5m}. Materials provided {self.materials.keys()}") + msg = ( + f"the NeutronicsModel.materials does not match the material" + "tags in the dagmc h5m file. Materials in h5m file " + f"{materials_in_h5m}. Materials provided {self.materials.keys()}") raise ValueError(msg) silently_remove_file("materials.xml") diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 1fd9aea..9f99ff9 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -23,88 +23,88 @@ # if chunk: # f.write(chunk) - # def test_create_initial_source_file(self): - # """Creates an initial_source.h5 from a point source""" +# def test_create_initial_source_file(self): +# """Creates an initial_source.h5 from a point source""" - # os.system("rm *.h5") +# os.system("rm *.h5") - # source = openmc.Source() - # source.space = openmc.stats.Point((0, 0, 0)) - # source.energy = openmc.stats.Discrete([14e6], [1]) +# source = openmc.Source() +# source.space = openmc.stats.Point((0, 0, 0)) +# source.energy = openmc.stats.Discrete([14e6], [1]) - # openmc_dagmc_wrapper.create_initial_particles(source, 100) +# openmc_dagmc_wrapper.create_initial_particles(source, 100) - # assert Path("initial_source.h5").exists() is True +# assert Path("initial_source.h5").exists() is True - # def test_extract_points_from_initial_source(self): - # """Creates an initial_source.h5 from a point source reads in the file - # and checks the first point is 0, 0, 0 as expected.""" +# def test_extract_points_from_initial_source(self): +# """Creates an initial_source.h5 from a point source reads in the file +# and checks the first point is 0, 0, 0 as expected.""" - # os.system("rm *.h5") +# os.system("rm *.h5") - # source = openmc.Source() - # source.space = openmc.stats.Point((0, 0, 0)) - # source.energy = openmc.stats.Discrete([14e6], [1]) +# source = openmc.Source() +# source.space = openmc.stats.Point((0, 0, 0)) +# source.energy = openmc.stats.Discrete([14e6], [1]) - # openmc_dagmc_wrapper.create_initial_particles(source, 10) +# openmc_dagmc_wrapper.create_initial_particles(source, 10) - # for view_plane in ["XZ", "XY", "YZ", "YX", "ZY", "ZX", "RZ", "XYZ"]: +# for view_plane in ["XZ", "XY", "YZ", "YX", "ZY", "ZX", "RZ", "XYZ"]: - # points = openmc_dagmc_wrapper.extract_points_from_initial_source( - # view_plane=view_plane - # ) +# points = openmc_dagmc_wrapper.extract_points_from_initial_source( +# view_plane=view_plane +# ) - # assert len(points) == 10 +# assert len(points) == 10 - # for point in points: - # if view_plane == "XYZ": - # assert len(point) == 3 - # assert point[0] == 0 - # assert point[1] == 0 - # assert point[2] == 0 - # else: - # assert len(point) == 2 - # assert point[0] == 0 - # assert point[1] == 0 +# for point in points: +# if view_plane == "XYZ": +# assert len(point) == 3 +# assert point[0] == 0 +# assert point[1] == 0 +# assert point[2] == 0 +# else: +# assert len(point) == 2 +# assert point[0] == 0 +# assert point[1] == 0 - # def test_extract_points_from_initial_source_incorrect_view_plane(self): - # """Tries to make extract points on to viewplane that is not accepted""" +# def test_extract_points_from_initial_source_incorrect_view_plane(self): +# """Tries to make extract points on to viewplane that is not accepted""" - # def incorrect_viewplane(): - # """Inccorect view_plane should raise a ValueError""" +# def incorrect_viewplane(): +# """Inccorect view_plane should raise a ValueError""" - # source = openmc.Source() - # source.space = openmc.stats.Point((0, 0, 0)) - # source.energy = openmc.stats.Discrete([14e6], [1]) +# source = openmc.Source() +# source.space = openmc.stats.Point((0, 0, 0)) +# source.energy = openmc.stats.Discrete([14e6], [1]) - # openmc_dagmc_wrapper.create_initial_particles(source, 10) +# openmc_dagmc_wrapper.create_initial_particles(source, 10) - # openmc_dagmc_wrapper.extract_points_from_initial_source(view_plane="coucou") +# openmc_dagmc_wrapper.extract_points_from_initial_source(view_plane="coucou") - # self.assertRaises(ValueError, incorrect_viewplane) +# self.assertRaises(ValueError, incorrect_viewplane) - # def test_create_initial_particles(self): - # """Creates an initial source file using create_initial_particles utility - # and checks the file exists and that the points are correct""" +# def test_create_initial_particles(self): +# """Creates an initial source file using create_initial_particles utility +# and checks the file exists and that the points are correct""" - # os.system("rm *.h5") +# os.system("rm *.h5") - # source = openmc.Source() - # source.space = openmc.stats.Point((1, 2, 3)) - # source.energy = openmc.stats.Discrete([14e6], [1]) - # source.angle = openmc.stats.Isotropic() +# source = openmc.Source() +# source.space = openmc.stats.Point((1, 2, 3)) +# source.energy = openmc.stats.Discrete([14e6], [1]) +# source.angle = openmc.stats.Isotropic() - # source_file = openmc_dagmc_wrapper.create_initial_particles( - # source=source, number_of_source_particles=10 - # ) +# source_file = openmc_dagmc_wrapper.create_initial_particles( +# source=source, number_of_source_particles=10 +# ) - # assert source_file == "initial_source.h5" - # assert Path(source_file).exists() is True +# assert source_file == "initial_source.h5" +# assert Path(source_file).exists() is True - # points = openmc_dagmc_wrapper.extract_points_from_initial_source( - # view_plane="XYZ", input_filename=source_file - # ) +# points = openmc_dagmc_wrapper.extract_points_from_initial_source( +# view_plane="XYZ", input_filename=source_file +# ) - # assert len(points) == 10 - # for point in points: - # assert point == (1, 2, 3) +# assert len(points) == 10 +# for point in points: +# assert point == (1, 2, 3) From 610fccc72eb555d1024e42ee4a4f9aa681075145 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 09:36:56 +0100 Subject: [PATCH 04/29] removed non existent functions from init --- openmc_dagmc_wrapper/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openmc_dagmc_wrapper/__init__.py b/openmc_dagmc_wrapper/__init__.py index aaf3d03..64ea672 100644 --- a/openmc_dagmc_wrapper/__init__.py +++ b/openmc_dagmc_wrapper/__init__.py @@ -1,6 +1,4 @@ from .utils import get_neutronics_results_from_statepoint_file -from .utils import find_material_groups_in_h5m -from .utils import find_volume_ids_in_h5m from .utils import create_initial_particles from .utils import extract_points_from_initial_source from .utils import silently_remove_file From aaeb4e08f85a65db75d75f55fe71a2f48f90adf2 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 09:57:33 +0100 Subject: [PATCH 05/29] getting h5m files from release --- tests/test_neutronics_model.py | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 37db834..257565c 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -1,7 +1,7 @@ import os import unittest from pathlib import Path - +import tarfile import neutronics_material_maker as nmm import openmc import openmc_dagmc_wrapper @@ -14,18 +14,16 @@ class TestShape(unittest.TestCase): def setUp(self): - url = "https://github.com/fusion-energy/neutronics_workflow/raw/main/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" - - local_filename = "dagmc_bigger.h5m" + if not Path("tests/v0.0.1.tar.gz").is_file(): + url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.1.tar.gz" + urllib.request.urlretrieve(url, "tests/v0.0.1.tar.gz") - if not Path(local_filename).is_file(): - r = requests.get(url, stream=True) - with open(local_filename, "wb") as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: - f.write(chunk) + tar = tarfile.open("tests/v0.0.1.tar.gz", "r:gz") + tar.extractall("tests") + tar.close() - self.h5m_filename_bigger = local_filename + self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" self.material_description = { "tungsten": "tungsten", @@ -34,19 +32,6 @@ def setUp(self): "copper": "copper", } - url = "https://github.com/fusion-energy/neutronics_workflow/raw/main/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" - - local_filename = "dagmc_smaller.h5m" - - if not Path(local_filename).is_file(): - r = requests.get(url, stream=True) - with open(local_filename, "wb") as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: # filter out keep-alive new chunks - f.write(chunk) - - self.h5m_filename_smaller = local_filename - # makes the openmc neutron source at x,y,z 0, 0, 0 with isotropic # directions and 14MeV neutrons source = openmc.Source() From b081a9872fbbefb16450f3e576d21b4bcdd5c121 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 10:02:53 +0100 Subject: [PATCH 06/29] added missing package (urllib) --- tests/test_neutronics_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 257565c..362ce2d 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -5,8 +5,7 @@ import neutronics_material_maker as nmm import openmc import openmc_dagmc_wrapper -import requests - +import urllib.request class TestShape(unittest.TestCase): """Tests the NeutronicsModel with a Shape as the geometry input From acd2a59f653693a7304774ea6185297bebc51849 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 09:03:21 +0000 Subject: [PATCH 07/29] Automated autopep8 fixes --- tests/test_neutronics_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 362ce2d..4b0740b 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -7,6 +7,7 @@ import openmc_dagmc_wrapper import urllib.request + class TestShape(unittest.TestCase): """Tests the NeutronicsModel with a Shape as the geometry input including neutronics simulations using""" From 7438402db73c9653bad99a4071e4b54dae9c8b5d Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 10:32:41 +0100 Subject: [PATCH 08/29] removed 2nd testing class --- openmc_dagmc_wrapper/neutronics_model.py | 7 ++++- tests/test_neutronics_model.py | 38 ++++++++---------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 19372f9..cfff21f 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -121,7 +121,12 @@ def h5m_filename(self): @h5m_filename.setter def h5m_filename(self, value): if isinstance(value, str): - self._h5m_filename = value + if not Path(value).is_file(): + msg = f"h5m_filename provided ({value}) does not exist" + raise TypeError(msg) + + + self._h5m_filename = value else: msg = "NeutronicsModelFromReactor.h5m_filename should be a string" raise TypeError(msg) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 362ce2d..42a511d 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -39,6 +39,16 @@ def setUp(self): source.energy = openmc.stats.Discrete([14e6], [1]) self.source = source + self.blanket_material = nmm.Material.from_mixture( + fracs=[0.8, 0.2], + materials=[ + nmm.Material.from_library("SiC"), + nmm.Material.from_library("eurofer"), + ], + ) + + + def simulation_with_previous_h5m_file(self): """This performs a simulation using previously created h5m file""" @@ -731,37 +741,13 @@ def test_missing_h5m_file_error_handling(): test_missing_h5m_file_error_handling) -class TestNeutronicsBallReactor(unittest.TestCase): - """Tests the NeutronicsModel with a BallReactor as the geometry input - including neutronics simulations""" - - def setUp(self): - - # makes a homogenised material for the blanket from lithium lead and - # eurofer - self.blanket_material = nmm.Material.from_mixture( - fracs=[0.8, 0.2], - materials=[ - nmm.Material.from_library("SiC"), - nmm.Material.from_library("eurofer"), - ], - ) - - self.source = openmc.Source() - # sets the location of the source to x=0 y=0 z=0 - self.source.space = openmc.stats.Point((0, 0, 0)) - # sets the direction to isotropic - self.source.angle = openmc.stats.Isotropic() - # sets the energy distribution to 100% 14MeV neutrons - self.source.energy = openmc.stats.Discrete([14e6], [1]) - def test_neutronics_model_attributes(self): """Makes a BallReactor neutronics model and simulates the TBR""" # makes the neutronics material my_model = openmc_dagmc_wrapper.NeutronicsModel( source=openmc.Source(), - h5m_filename="placeholder.h5m", + h5m_filename=self.h5m_filename_smaller, materials={ "inboard_tf_coils_mat": "copper", "mat1": "WC", @@ -773,7 +759,7 @@ def test_neutronics_model_attributes(self): cell_tallies=["TBR", "flux", "heating"], ) - assert my_model.h5m_filename == "placeholder.h5m" + assert my_model.h5m_filename == self.h5m_filename_smaller assert my_model.materials == { "inboard_tf_coils_mat": "copper", From 367bc6d97477fdd11312ee100a8912bdfa3c925b Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 09:33:45 +0000 Subject: [PATCH 09/29] Automated autopep8 fixes --- openmc_dagmc_wrapper/neutronics_model.py | 1 - tests/test_neutronics_model.py | 3 --- 2 files changed, 4 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index cfff21f..d2c9ce6 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -125,7 +125,6 @@ def h5m_filename(self, value): msg = f"h5m_filename provided ({value}) does not exist" raise TypeError(msg) - self._h5m_filename = value else: msg = "NeutronicsModelFromReactor.h5m_filename should be a string" diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 17a9441..3ff2794 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -48,8 +48,6 @@ def setUp(self): ], ) - - def simulation_with_previous_h5m_file(self): """This performs a simulation using previously created h5m file""" @@ -741,7 +739,6 @@ def test_missing_h5m_file_error_handling(): FileNotFoundError, test_missing_h5m_file_error_handling) - def test_neutronics_model_attributes(self): """Makes a BallReactor neutronics model and simulates the TBR""" From 4daf6748a125d28cde745345a4981c4de423ab57 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 10:44:36 +0100 Subject: [PATCH 10/29] fixing _h5m_filename bug --- openmc_dagmc_wrapper/neutronics_model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index cfff21f..bf6fcd3 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -124,9 +124,7 @@ def h5m_filename(self, value): if not Path(value).is_file(): msg = f"h5m_filename provided ({value}) does not exist" raise TypeError(msg) - - - self._h5m_filename = value + self._h5m_filename = value else: msg = "NeutronicsModelFromReactor.h5m_filename should be a string" raise TypeError(msg) From 41f1cbe2b0b05e1fb658c894e84a1457bf9f0dca Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 11:43:07 +0100 Subject: [PATCH 11/29] removed test for from dir --- tests/test_neutronics_model.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 3ff2794..a92b668 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -7,7 +7,6 @@ import openmc_dagmc_wrapper import urllib.request - class TestShape(unittest.TestCase): """Tests the NeutronicsModel with a Shape as the geometry input including neutronics simulations using""" @@ -22,8 +21,8 @@ def setUp(self): tar.extractall("tests") tar.close() - self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" - self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_bigger = "neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_smaller = "neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" self.material_description = { "tungsten": "tungsten", @@ -48,6 +47,7 @@ def setUp(self): ], ) + def simulation_with_previous_h5m_file(self): """This performs a simulation using previously created h5m file""" @@ -739,6 +739,7 @@ def test_missing_h5m_file_error_handling(): FileNotFoundError, test_missing_h5m_file_error_handling) + def test_neutronics_model_attributes(self): """Makes a BallReactor neutronics model and simulates the TBR""" From a6dd5e15085dbcf48e095acd55393b09f9f18bd7 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 10:43:36 +0000 Subject: [PATCH 12/29] Automated autopep8 fixes --- tests/test_neutronics_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index a92b668..ce3b005 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -7,6 +7,7 @@ import openmc_dagmc_wrapper import urllib.request + class TestShape(unittest.TestCase): """Tests the NeutronicsModel with a Shape as the geometry input including neutronics simulations using""" @@ -47,7 +48,6 @@ def setUp(self): ], ) - def simulation_with_previous_h5m_file(self): """This performs a simulation using previously created h5m file""" @@ -739,7 +739,6 @@ def test_missing_h5m_file_error_handling(): FileNotFoundError, test_missing_h5m_file_error_handling) - def test_neutronics_model_attributes(self): """Makes a BallReactor neutronics model and simulates the TBR""" From d776b86e7445d1d0330b624bc18a8140c2ca894d Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 11:46:07 +0100 Subject: [PATCH 13/29] added tests folder back to dir --- tests/test_neutronics_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index a92b668..eb2d326 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -21,8 +21,8 @@ def setUp(self): tar.extractall("tests") tar.close() - self.h5m_filename_bigger = "neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" - self.h5m_filename_smaller = "neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" self.material_description = { "tungsten": "tungsten", From d46bb2e94597c250f290494d73b26bdb5d073046 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 12:34:58 +0100 Subject: [PATCH 14/29] allowing tet mesh file to be none --- openmc_dagmc_wrapper/neutronics_model.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index bf6fcd3..77297eb 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -123,7 +123,7 @@ def h5m_filename(self, value): if isinstance(value, str): if not Path(value).is_file(): msg = f"h5m_filename provided ({value}) does not exist" - raise TypeError(msg) + raise FileNotFoundError(msg) self._h5m_filename = value else: msg = "NeutronicsModelFromReactor.h5m_filename should be a string" @@ -135,7 +135,12 @@ def tet_mesh_filename(self): @tet_mesh_filename.setter def tet_mesh_filename(self, value): - if isinstance(value, (str, type(None))): + if isinstance(value, str): + if not Path(value).is_file(): + msg = f"tet_mesh_filename provided ({value}) does not exist" + raise FileNotFoundError(msg) + self._tet_mesh_filename = value + if isinstance(value, type(None)): self._tet_mesh_filename = value else: msg = "NeutronicsModelFromReactor.tet_mesh_filename should be a string" From f60c51e4a365caca54ae3ee8f0dcf9c50f24fa55 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 12:39:51 +0100 Subject: [PATCH 15/29] changed bash to pytest cmd --- .github/workflows/ci_with_install.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 9addc87..4dbb71c 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -24,5 +24,12 @@ jobs: python setup.py install - name: run tests run: | - bash run_tests.sh + apt-get install tree + tree tests + pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xmlpytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + tree tests curl -s https://codecov.io/bash From 3490cdf7874b76f0de691bf18ba0f9ae40dcf117 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 12:43:26 +0100 Subject: [PATCH 16/29] corrected long line typo --- .github/workflows/ci_with_install.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 4dbb71c..04fdede 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -28,7 +28,8 @@ jobs: tree tests pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xmlpytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml tree tests From 69004eaa49671658b22c25e80fd006f59a5a67ff Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 12:57:04 +0100 Subject: [PATCH 17/29] changed order of pytests --- .github/workflows/ci_with_install.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 04fdede..f222d8c 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -26,11 +26,12 @@ jobs: run: | apt-get install tree tree tests - pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + tree tests pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml tree tests curl -s https://codecov.io/bash From cb07887af566a0e4c42aa76ac37f9d81f7dbc339 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 13:09:08 +0100 Subject: [PATCH 18/29] wget to download h5m test files --- .github/workflows/ci_with_install.yml | 28 +++++++++++++++++---------- tests/test_neutronics_model.py | 7 +++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index f222d8c..9cbb22a 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -25,13 +25,21 @@ jobs: - name: run tests run: | apt-get install tree - tree tests - pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - tree tests - pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - tree tests - curl -s https://codecov.io/bash + wget https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.1.tar.gz + tar -xvzf v0.0.1.tar.gz -C tests + tree + pytest tests/test_neutronics_model.py -vv + + # - name: run tests + # run: | + # apt-get install tree + # tree tests + # pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # tree tests + # pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # tree tests + # curl -s https://codecov.io/bash diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 3ff2794..1da1f5c 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -720,8 +720,11 @@ 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, '.') + my_model = openmc_dagmc_wrapper.NeutronicsModel( - h5m_filename=self.h5m_filename_smaller, + h5m_filename='dagmc.h5m', source=self.source, materials={"mat1": "WC"}, ) @@ -731,7 +734,7 @@ def test_missing_h5m_file_error_handling(): os.system("touch materials.xml") os.system("touch settings.xml") os.system("touch tallies.xml") - os.system("rm dagmc_smaller.h5m") + os.system("rm dagmc.h5m") my_model.simulate() From 85a7ca70fe4d70272b9b2d8dcd0073aac95df022 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 15:41:37 +0100 Subject: [PATCH 19/29] renamed h5m files --- tests/test_neutronics_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 1da1f5c..ff036f2 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -22,8 +22,8 @@ def setUp(self): tar.extractall("tests") tar.close() - self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" - self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.1/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.1/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" self.material_description = { "tungsten": "tungsten", From 799d30f66b918ca40707f170f748508392d5b887 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 15:57:57 +0100 Subject: [PATCH 20/29] checking key instead of items --- openmc_dagmc_wrapper/neutronics_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 77297eb..e570234 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -282,7 +282,7 @@ def create_openmc_materials(self): materials_in_h5m = di.get_materials_from_h5m(self.h5m_filename) # # checks all the required materials are present - for reactor_material in self.materials.items(): + for reactor_material in self.materials.keys(): if reactor_material not in materials_in_h5m: msg = (f"material with tag {reactor_material} was not found in" "the dagmc h5m file") From 5ab7d21c70199b6e1c7bb6b5bfab650e48cbffcc Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 16:04:56 +0100 Subject: [PATCH 21/29] added -1 to materials len if graveyard found --- openmc_dagmc_wrapper/neutronics_model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index e570234..fadf034 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -288,7 +288,12 @@ def create_openmc_materials(self): "the dagmc h5m file") raise ValueError(msg) - if len(materials_in_h5m) != len(self.materials.keys()): + if 'graveyard' in materials_in_h5m: + required_number_of_materials = len(materials_in_h5m) -1 + else: + required_number_of_materials = len(materials_in_h5m) + + if required_number_of_materials != len(self.materials.keys()): msg = ( f"the NeutronicsModel.materials does not match the material" "tags in the dagmc h5m file. Materials in h5m file " From 1a1ce163f161190e50fae3840d7dba1d9b6f2384 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 15:05:28 +0000 Subject: [PATCH 22/29] Automated autopep8 fixes --- openmc_dagmc_wrapper/neutronics_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index fadf034..bb53013 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -289,7 +289,7 @@ def create_openmc_materials(self): raise ValueError(msg) if 'graveyard' in materials_in_h5m: - required_number_of_materials = len(materials_in_h5m) -1 + required_number_of_materials = len(materials_in_h5m) - 1 else: required_number_of_materials = len(materials_in_h5m) From fd7b170163f47a7cd1289c4d7548931bbc1fc703 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 16:08:26 +0100 Subject: [PATCH 23/29] added all the tests back --- .github/workflows/ci_with_install.yml | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 9cbb22a..96117d4 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -22,24 +22,13 @@ jobs: - name: install package run: | python setup.py install + - name: run tests run: | - apt-get install tree - wget https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.1.tar.gz - tar -xvzf v0.0.1.tar.gz -C tests - tree - pytest tests/test_neutronics_model.py -vv - - # - name: run tests - # run: | - # apt-get install tree - # tree tests - # pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # tree tests - # pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - # tree tests - # curl -s https://codecov.io/bash + pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + curl -s https://codecov.io/bash From 4c4c6dc37971045a8df6b5b2285642418176b40c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 16:15:47 +0100 Subject: [PATCH 24/29] removed gravyard material --- tests/test_shape_neutronics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_shape_neutronics.py b/tests/test_shape_neutronics.py index 15c0110..1669bcc 100644 --- a/tests/test_shape_neutronics.py +++ b/tests/test_shape_neutronics.py @@ -30,7 +30,6 @@ def setUp(self): "center_column_shield_mat": "Be", "blanket_rear_wall_mat": "Be", "divertor_mat": "Be", - "graveyard": "Be", "tf_coil_mat": "Be", "pf_coil_mat": "Be", "inboard_tf_coils_mat": "Be", From 125236e626ef67e3b0100114312e5c642ff9dfb5 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 16:25:19 +0100 Subject: [PATCH 25/29] removed graveyard in test materials --- openmc_dagmc_wrapper/neutronics_model.py | 4 ++-- tests/test_reactor_neutronics.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index bb53013..b444ea5 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -284,7 +284,7 @@ def create_openmc_materials(self): # # checks all the required materials are present for reactor_material in self.materials.keys(): if reactor_material not in materials_in_h5m: - msg = (f"material with tag {reactor_material} was not found in" + msg = (f"material with tag {reactor_material} was not found in " "the dagmc h5m file") raise ValueError(msg) @@ -295,7 +295,7 @@ def create_openmc_materials(self): if required_number_of_materials != len(self.materials.keys()): msg = ( - f"the NeutronicsModel.materials does not match the material" + f"the NeutronicsModel.materials does not match the material " "tags in the dagmc h5m file. Materials in h5m file " f"{materials_in_h5m}. Materials provided {self.materials.keys()}") raise ValueError(msg) diff --git a/tests/test_reactor_neutronics.py b/tests/test_reactor_neutronics.py index dddbf6c..ed67759 100644 --- a/tests/test_reactor_neutronics.py +++ b/tests/test_reactor_neutronics.py @@ -29,7 +29,6 @@ def setUp(self): "center_column_shield_mat": "Be", "blanket_rear_wall_mat": "Be", "divertor_mat": "Be", - "graveyard": "Be", "tf_coil_mat": "Be", "pf_coil_mat": "Be", "inboard_tf_coils_mat": "Be", From 4ea5fd946c57aaca21637eb967f657a2991ac82d Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 15:25:56 +0000 Subject: [PATCH 26/29] Automated autopep8 fixes --- openmc_dagmc_wrapper/neutronics_model.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index b444ea5..935a27c 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -284,8 +284,9 @@ def create_openmc_materials(self): # # checks all the required materials are present for reactor_material in self.materials.keys(): if reactor_material not in materials_in_h5m: - msg = (f"material with tag {reactor_material} was not found in " - "the dagmc h5m file") + msg = ( + f"material with tag {reactor_material} was not found in " + "the dagmc h5m file") raise ValueError(msg) if 'graveyard' in materials_in_h5m: From f1c77bcbb990b95da1e897c75b417af269ca2eea Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 Sep 2021 16:33:37 +0100 Subject: [PATCH 27/29] removed utils testing --- .circleci/config.yml | 18 +++++++++--------- .github/workflows/ci_with_install.yml | 2 +- run_tests.sh | 2 +- tests/test_neutronics_utils.py | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b91af56..24ca930 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,33 +18,33 @@ jobs: - run: name: run test_NeutronicModel command: - pytest tests/test_neutronics_model.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - run: name: run test_shape_neutronics command: - pytest tests/test_shape_neutronics.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - run: name: run test_reactor_neutronics command: - pytest tests/test_reactor_neutronics.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - - run: - name: run test_neutronics_utils - command: - pytest tests/test_neutronics_utils.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml + # - run: + # name: run test_neutronics_utils + # command: + # pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - run: name: run test_example_neutronics_simulations command: - pytest tests/test_example_neutronics_simulations.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml + pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml # TODO add example notebooks # - run: # name: run notebook_testing # command: - # pytest tests/notebook_testing.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml + # pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml - store_test_results: diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 96117d4..d84bd77 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -29,6 +29,6 @@ jobs: pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml - pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml + # pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml curl -s https://codecov.io/bash diff --git a/run_tests.sh b/run_tests.sh index b7ffab5..3231442 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -4,4 +4,4 @@ pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml -pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml +# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 9f99ff9..37ad17d 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -1,11 +1,11 @@ -import json -import os -import unittest -from pathlib import Path - -import openmc -import openmc_dagmc_wrapper -import requests +# import json +# import os +# import unittest +# from pathlib import Path + +# import openmc +# import openmc_dagmc_wrapper +# import requests # class TestNeutronicsUtilityFunctions(unittest.TestCase): From e3462ed5c2a4ac46235857c8617b42fa21823e10 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 10 Sep 2021 22:35:42 +0100 Subject: [PATCH 28/29] changed keys and local tests pass --- openmc_dagmc_wrapper/neutronics_model.py | 18 +++++++++++------- openmc_dagmc_wrapper/utils.py | 23 ++++++++++++++++++----- tests/test_neutronics_model.py | 20 +++++++++++++------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 6c9c382..c991bdd 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -689,7 +689,7 @@ def export_xml( neutron_particle_filter = openmc.ParticleFilter([ "neutron"]) self._add_tally_for_every_material( - "neutron_spectra", + "neutron_fast_flux", "flux", [neutron_particle_filter, energy_filter], ) @@ -697,7 +697,7 @@ def export_xml( photon_particle_filter = openmc.ParticleFilter([ "photon"]) self._add_tally_for_every_material( - "photon_spectra", + "photon_fast_flux", "flux", [photon_particle_filter, energy_filter], ) @@ -767,6 +767,9 @@ def export_xml( suffix = standard_tally self._add_tally_for_every_material(suffix, score) + # todo add photon tallys for standard tallies + # if self.photon_transport: + # make the model from geometry, materials, settings and tallies model = openmc.model.Model(geom, self.mats, settings, self.tallies) @@ -849,6 +852,12 @@ def simulate( ) raise TypeError(msg) + if not Path(self.h5m_filename).is_file(): + msg = f"""{self.h5m_filename} file was not found. Please set + export_h5m to True or use the export_h5m() methods to create + the dagmc.h5m file""" + raise FileNotFoundError(msg) + if export_xml is True: self.export_xml( simulation_batches=simulation_batches, @@ -871,11 +880,6 @@ def simulate( ) raise FileNotFoundError(msg) - if not Path(self.h5m_filename).is_file(): - msg = f"""{self.h5m_filename} file was not found. Please set - export_h5m to True or use the export_h5m() methods to create - the dagmc.h5m file""" - raise FileNotFoundError(msg) # Deletes summary.h5m if it already exists. # This avoids permission problems when trying to overwrite the file diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index ad4c348..7a94f4a 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -205,15 +205,22 @@ def get_neutronics_results_from_statepoint_file( * number_of_neutrons_in_pulse, } - # todo add fast flux tally - # energies = [0.1e6, 100e6] 0.1MeV to 100MeV - # energy_filter = openmc.EnergyFilter(energies) + elif tally.name.endswith("fast_flux"): + + data_frame = tally.get_pandas_dataframe() + tally_result = data_frame["mean"].sum() + tally_std_dev = data_frame["std. dev."].sum() + results[tally.name]["fast flux per source particle"] = { + "result": tally_result, + "std. dev.": tally_std_dev, + } + elif tally.name.endswith("flux"): data_frame = tally.get_pandas_dataframe() tally_result = data_frame["mean"].sum() tally_std_dev = data_frame["std. dev."].sum() - results[tally.name]["Flux per source particle"] = { + results[tally.name]["flux per source particle"] = { "result": tally_result, "std. dev.": tally_std_dev, } @@ -222,7 +229,7 @@ def get_neutronics_results_from_statepoint_file( data_frame = tally.get_pandas_dataframe() tally_result = data_frame["mean"] tally_std_dev = data_frame["std. dev."] - results[tally.name]["Flux per source particle"] = { + results[tally.name]["flux per source particle"] = { "energy": openmc.mgxs.GROUP_STRUCTURES["CCFE-709"].tolist(), "result": tally_result.tolist(), "std. dev.": tally_std_dev.tolist(), @@ -331,6 +338,12 @@ def get_neutronics_results_from_statepoint_file( return results +#to do find particles from tally +# def find_particle_from_tally(tally): +# for filter in talliy.filters: +# if isinstance(filter, openmc.ParticleFilter): +# return filter.bins[0] +# return None def write_3d_mesh_tally_to_vtk( xs: np.linspace, diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index eaddf36..5457984 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -348,16 +348,16 @@ def test_neutronics_component_cell_simulation_heating(self): # extracts the heat from the results dictionary heat = my_model.results["mat1_heating"]["Watts"]["result"] - flux = my_model.results["mat1_flux"]["Flux per source particle"]["result"] + flux = my_model.results["mat1_flux"]["flux per source particle"]["result"] mat_tbr = my_model.results["mat1_TBR"]["result"] tbr = my_model.results["TBR"]["result"] spectra_neutrons = my_model.results["mat1_neutron_spectra"][ - "Flux per source particle" + "flux per source particle" ]["result"] spectra_photons = my_model.results["mat1_photon_spectra"][ - "Flux per source particle" + "flux per source particle" ]["result"] - energy = my_model.results["mat1_photon_spectra"]["Flux per source particle"][ + energy = my_model.results["mat1_photon_spectra"]["flux per source particle"][ "energy" ] @@ -565,14 +565,14 @@ def test_cell_tallies_simulation_fast_flux(self): h5m_filename=self.h5m_filename_smaller, source=self.source, materials={"mat1": "Be"}, - cell_tallies=["fast_flux"], + cell_tallies=["fast_flux", "flux"], photon_transport=True, ) # starts the neutronics simulation my_model.simulate( simulation_batches=2, - simulation_particles_per_batch=10, + simulation_particles_per_batch=1000, ) my_model.process_results( @@ -581,9 +581,15 @@ def test_cell_tallies_simulation_fast_flux(self): ) assert isinstance( - my_model.results["mat1_neutron_fast_flux"]["result"], + my_model.results["mat1_neutron_fast_flux"]["fast flux per source particle"]["result"], float, ) + assert isinstance( + my_model.results["mat1_flux"]["flux per source particle"]["result"], + float, + ) + + assert my_model.results["mat1_flux"]["flux per source particle"]["result"] > my_model.results["mat1_neutron_fast_flux"]["fast flux per source particle"]["result"] def test_cell_tallies_simulation_effective_dose(self): """Performs simulation with h5m file and tallies neutron and photon From 525d4a85ce90f70b763d85f9c174c5cad4369803 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 10 Sep 2021 21:36:08 +0000 Subject: [PATCH 29/29] Automated autopep8 fixes --- openmc_dagmc_wrapper/neutronics_model.py | 1 - openmc_dagmc_wrapper/utils.py | 3 ++- tests/test_neutronics_model.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index c991bdd..c365f09 100644 --- a/openmc_dagmc_wrapper/neutronics_model.py +++ b/openmc_dagmc_wrapper/neutronics_model.py @@ -880,7 +880,6 @@ def simulate( ) raise FileNotFoundError(msg) - # Deletes summary.h5m if it already exists. # This avoids permission problems when trying to overwrite the file silently_remove_file("summary.h5") diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index 7a94f4a..22848b6 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -338,13 +338,14 @@ def get_neutronics_results_from_statepoint_file( return results -#to do find particles from tally +# to do find particles from tally # def find_particle_from_tally(tally): # for filter in talliy.filters: # if isinstance(filter, openmc.ParticleFilter): # return filter.bins[0] # return None + def write_3d_mesh_tally_to_vtk( xs: np.linspace, ys: np.linspace, diff --git a/tests/test_neutronics_model.py b/tests/test_neutronics_model.py index 5457984..c2c25e2 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -589,7 +589,8 @@ def test_cell_tallies_simulation_fast_flux(self): float, ) - assert my_model.results["mat1_flux"]["flux per source particle"]["result"] > my_model.results["mat1_neutron_fast_flux"]["fast flux per source particle"]["result"] + assert my_model.results["mat1_flux"]["flux per source particle"]["result"] > my_model.results[ + "mat1_neutron_fast_flux"]["fast flux per source particle"]["result"] def test_cell_tallies_simulation_effective_dose(self): """Performs simulation with h5m file and tallies neutron and photon