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 9addc87..d84bd77 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -22,7 +22,13 @@ jobs: - name: install package run: | python setup.py install + - name: run tests run: | - bash run_tests.sh + 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 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 diff --git a/openmc_dagmc_wrapper/neutronics_model.py b/openmc_dagmc_wrapper/neutronics_model.py index 8b0c87e..c365f09 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 @@ -123,6 +121,9 @@ def h5m_filename(self): @h5m_filename.setter 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 FileNotFoundError(msg) self._h5m_filename = value else: msg = "NeutronicsModelFromReactor.h5m_filename should be a string" @@ -134,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" @@ -171,7 +177,8 @@ def cell_tallies(self, value): "flux", "spectra", "absorption", - "effective_dose"] + + "effective_dose", + "fast_flux"] + list( REACTION_MT.keys()) + list( @@ -273,19 +280,27 @@ 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.keys(): + 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 '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 " + f"{materials_in_h5m}. Materials provided {self.materials.keys()}") + raise ValueError(msg) silently_remove_file("materials.xml") @@ -394,9 +409,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 +520,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 +681,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_fast_flux", + "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_fast_flux", + "flux", + [photon_particle_filter, energy_filter], + ) + elif standard_tally == "spectra": energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"] @@ -699,7 +736,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", @@ -731,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) @@ -813,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, @@ -835,12 +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 silently_remove_file("summary.h5") diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index acb19c3..22848b6 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. @@ -278,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, } @@ -295,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(), @@ -404,6 +338,13 @@ 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/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/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_model.py b/tests/test_neutronics_model.py index 37db834..c2c25e2 100644 --- a/tests/test_neutronics_model.py +++ b/tests/test_neutronics_model.py @@ -1,11 +1,11 @@ import os import unittest from pathlib import Path - +import tarfile import neutronics_material_maker as nmm import openmc import openmc_dagmc_wrapper -import requests +import urllib.request class TestShape(unittest.TestCase): @@ -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_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", @@ -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() @@ -55,6 +40,14 @@ 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""" @@ -355,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" ] @@ -562,6 +555,43 @@ 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", "flux"], + photon_transport=True, + ) + + # starts the neutronics simulation + my_model.simulate( + simulation_batches=2, + simulation_particles_per_batch=1000, + ) + + my_model.process_results( + fusion_power=1e9, + fusion_energy_per_pulse=1.2e6 + ) + + assert isinstance( + 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 dose. Checks that entries exist in the results.""" @@ -727,8 +757,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"}, ) @@ -738,7 +771,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() @@ -746,38 +779,13 @@ def test_missing_h5m_file_error_handling(): FileNotFoundError, 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", @@ -789,7 +797,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", diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 30905df..37ad17d 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -1,143 +1,110 @@ -import json -import os -import unittest -from pathlib import Path +# import json +# import os +# import unittest +# from pathlib import Path -import openmc -import openmc_dagmc_wrapper -import requests +# import openmc +# import openmc_dagmc_wrapper +# 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""" +# 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_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""" +# 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""" - list_of_mats = openmc_dagmc_wrapper.find_material_groups_in_h5m( - filename="dagmc_bigger.h5m" - ) +# os.system("rm *.h5") - 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 +# source = openmc.Source() +# source.space = openmc.stats.Point((1, 2, 3)) +# source.energy = openmc.stats.Discrete([14e6], [1]) +# source.angle = openmc.stats.Isotropic() - 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""" +# source_file = openmc_dagmc_wrapper.create_initial_particles( +# source=source, number_of_source_particles=10 +# ) - list_of_mats = openmc_dagmc_wrapper.find_volume_ids_in_h5m( - filename="dagmc_bigger.h5m" - ) +# assert source_file == "initial_source.h5" +# assert Path(source_file).exists() is True - 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 +# points = openmc_dagmc_wrapper.extract_points_from_initial_source( +# view_plane="XYZ", input_filename=source_file +# ) - # 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") - - # 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 - # ) - - # 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 - # ) - - # 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) 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", 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",