diff --git a/openmc_dagmc_wrapper/Tally.py b/openmc_dagmc_wrapper/Tally.py index 9bb1bfc..901dc51 100644 --- a/openmc_dagmc_wrapper/Tally.py +++ b/openmc_dagmc_wrapper/Tally.py @@ -6,7 +6,7 @@ from openmc.data import REACTION_MT, REACTION_NAME from openmc_dagmc_wrapper import Materials -from .utils import create_material, silently_remove_file, find_bounding_box +from .utils import find_bounding_box class Tally(openmc.Tally): @@ -33,8 +33,12 @@ def tally_type(self, value): output_options = ( [ "TBR", - "heating", "flux", + "heating", + "photon_heating", + "neutron_heating", + "neutron_flux", + "photon_flux", "absorption", "neutron_effective_dose", "photon_effective_dose", @@ -57,6 +61,9 @@ def tally_type(self, value): def set_score(self): flux_scores = [ + "flux", + "neutron_flux", + "photon_flux", "neutron_fast_flux", "photon_fast_flux", "neutron_spectra", @@ -141,11 +148,11 @@ class CellTallies: Usage: my_mats = odw.Materials(....) my_tallies = odw.CellTallies( - tally_types=['TBR', "flux"], + tally_types=['TBR', "neutron_flux"], target=["Be", 2], materials=my_mats ) - my_tallies = odw.CellTallies(tally_types=['TBR', "flux"], target=[2]) + my_tallies = odw.CellTallies(tally_types=['TBR', "neutron_flux"], target=[2]) Args: tally_types ([type]): [description] @@ -451,7 +458,17 @@ def compute_filters(tally_type): neutron_particle_filter = openmc.ParticleFilter(["neutron"]) additional_filters = [] - if tally_type == "neutron_fast_flux": + if tally_type == "neutron_flux": + additional_filters = [neutron_particle_filter] + elif tally_type == "photon_flux": + additional_filters = [photon_particle_filter] + + elif tally_type == "neutron_heating": + additional_filters = [neutron_particle_filter] + elif tally_type == "photon_heating": + additional_filters = [photon_particle_filter] + + elif tally_type == "neutron_fast_flux": energy_bins = [1e6, 1000e6] energy_filter = openmc.EnergyFilter(energy_bins) additional_filters = [neutron_particle_filter, energy_filter] @@ -459,6 +476,7 @@ def compute_filters(tally_type): energy_bins = [1e6, 1000e6] energy_filter = openmc.EnergyFilter(energy_bins) additional_filters = [photon_particle_filter, energy_filter] + elif tally_type == "neutron_spectra": energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"] energy_filter = openmc.EnergyFilter(energy_bins) @@ -467,6 +485,7 @@ def compute_filters(tally_type): energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"] energy_filter = openmc.EnergyFilter(energy_bins) additional_filters = [photon_particle_filter, energy_filter] + elif tally_type == "neutron_effective_dose": energy_function_filter_n = openmc.EnergyFunctionFilter( energy_bins_n, dose_coeffs_n diff --git a/openmc_dagmc_wrapper/utils.py b/openmc_dagmc_wrapper/utils.py index 840424e..4d52ada 100644 --- a/openmc_dagmc_wrapper/utils.py +++ b/openmc_dagmc_wrapper/utils.py @@ -175,7 +175,6 @@ def process_results( # access the tallies for tally in statepoint.tallies.values(): - print(f"processing {tally.name}") if tally.name.endswith("TBR"): data_frame = tally.get_pandas_dataframe() @@ -322,7 +321,6 @@ def process_results( ",", "-"), ) elif "_on_3D_mesh" in tally.name: - print(f"processing {tally.name}") mesh_id = 1 mesh = statepoint.meshes[mesh_id] diff --git a/tests/test_tallies/test_mesh_tally_2d.py b/tests/test_tallies/test_mesh_tally_2d.py new file mode 100644 index 0000000..5981523 --- /dev/null +++ b/tests/test_tallies/test_mesh_tally_2d.py @@ -0,0 +1,93 @@ + +import tarfile +import unittest +import urllib.request +from pathlib import Path + +import openmc +import openmc_dagmc_wrapper as odw +from openmc_plasma_source import FusionRingSource + + +class TestMeshTally2D(unittest.TestCase): + """Tests the MeshTally2D class functionality""" + + def setUp(self): + + if not Path("tests/v0.0.2.tar.gz").is_file(): + url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz" + urllib.request.urlretrieve(url, "tests/v0.0.2.tar.gz") + + tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz") + tar.extractall("tests") + tar.close() + + self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" + self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" + + def test_incorrect_mesh_tally_2d(self): + """Set a mesh_tally_2d that is not accepted which should raise an + error""" + def incorrect_mesh_tally_2d(): + odw.MeshTally2D("coucou", plane="xy") + + self.assertRaises(ValueError, incorrect_mesh_tally_2d) + + def test_incorrect_mesh_tally_2d_type(self): + """Set a mesh_tally_2d that is the wrong type which should raise an + error""" + def incorrect_mesh_tally_2d_type(): + odw.MeshTally2D(1, plane="xy") + + self.assertRaises(TypeError, incorrect_mesh_tally_2d_type) + + def test_shape_of_resulting_png(self): + """Runs a simulation with a 2d mesh tally and checks png images are + produced""" + + geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller) + materials = odw.Materials( + h5m_filename=self.h5m_filename_smaller, + correspondence_dict={ + "mat1": "Be", + }, + ) + tally1 = odw.MeshTally2D( + tally_type="neutron_flux", + plane="xy", + bounding_box=self.h5m_filename_smaller, + mesh_resolution=(10, 200) + ) + tally2 = odw.MeshTally2D( + tally_type="neutron_flux", + plane="xz", + bounding_box=self.h5m_filename_smaller, + mesh_resolution=(20, 100) + ) + tally3 = odw.MeshTally2D( + tally_type="neutron_flux", + plane="yz", + bounding_box=self.h5m_filename_smaller, + mesh_resolution=(30, 500) + ) + + tallies = openmc.Tallies([tally1, tally2, tally3]) + + settings = odw.FusionSettings() + settings.batches = 2 + settings.particles = 100 + settings.photon_transport = False + settings.source = FusionRingSource(fuel="DT", radius=1) + + my_model = openmc.Model( + materials=materials, + geometry=geometry, + settings=settings, + tallies=tallies) + statepoint_file = my_model.run() + + odw.process_results(statepoint_file, fusion_power=1e9) + + assert Path('neutron_flux_on_2D_mesh_xy.png').exists() + assert Path('neutron_flux_on_2D_mesh_xz.png').exists() + assert Path('neutron_flux_on_2D_mesh_yz.png').exists() diff --git a/tests/test_tallies/test_mesh_tallies.py b/tests/test_tallies/test_mesh_tally_3d.py similarity index 81% rename from tests/test_tallies/test_mesh_tallies.py rename to tests/test_tallies/test_mesh_tally_3d.py index 1585496..f0fa27c 100644 --- a/tests/test_tallies/test_mesh_tallies.py +++ b/tests/test_tallies/test_mesh_tally_3d.py @@ -1,3 +1,4 @@ + import tarfile import unittest import urllib.request @@ -7,8 +8,8 @@ import openmc_dagmc_wrapper as odw -class TestMeshTallies(unittest.TestCase): - """Tests the MeshTallies class functionality""" +class TestMeshTally3D(unittest.TestCase): + """Tests the MeshTally3D class functionality""" def setUp(self): @@ -23,22 +24,6 @@ def setUp(self): self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m" self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m" - def test_incorrect_mesh_tally_2d(self): - """Set a mesh_tally_2d that is not accepted which should raise an - error""" - def incorrect_mesh_tally_2d(): - odw.MeshTally2D("coucou", plane="xy") - - self.assertRaises(ValueError, incorrect_mesh_tally_2d) - - def test_incorrect_mesh_tally_2d_type(self): - """Set a mesh_tally_2d that is the wrong type which should raise an - error""" - def incorrect_mesh_tally_2d_type(): - odw.MeshTally2D(1, plane="xy") - - self.assertRaises(TypeError, incorrect_mesh_tally_2d_type) - def test_incorrect_mesh_tally_3d(self): """Set a mesh_tally_3d that is not accepted which should raise an error"""