From 685bb953f0a2f029c81345680b89455305a5c437 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 3 May 2023 15:07:58 +0100 Subject: [PATCH] finding number of atoms --- src/openmc_depletion_plotter/__init__.py | 2 +- src/openmc_depletion_plotter/results.py | 4 ++-- src/openmc_depletion_plotter/utils.py | 10 ++++++---- tests/test_python_api.py | 16 +++++++++++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/openmc_depletion_plotter/__init__.py b/src/openmc_depletion_plotter/__init__.py index beddf83..fe32711 100644 --- a/src/openmc_depletion_plotter/__init__.py +++ b/src/openmc_depletion_plotter/__init__.py @@ -21,7 +21,7 @@ from .utils import get_atoms_activity_from_material from .utils import find_most_abundant_nuclides_in_material from .utils import find_most_abundant_nuclides_in_materials -from .utils import get_nuclide_atom_densities_from_materials +from .utils import get_nuclide_atoms_from_materials from .utils import find_most_active_nuclides_in_material from .utils import find_most_active_nuclides_in_materials from .utils import get_nuclide_activities_from_materials diff --git a/src/openmc_depletion_plotter/results.py b/src/openmc_depletion_plotter/results.py index bb9b627..8d42f9b 100644 --- a/src/openmc_depletion_plotter/results.py +++ b/src/openmc_depletion_plotter/results.py @@ -7,7 +7,7 @@ from .utils import find_total_activity_in_materials from .utils import stable_nuclides from .utils import create_base_plot -from .utils import get_nuclide_atom_densities_from_materials +from .utils import get_nuclide_atoms_from_materials from .utils import find_most_abundant_nuclides_in_materials from .utils import find_total_nuclides_in_materials import plotly.graph_objects as go @@ -184,7 +184,7 @@ def plot_atoms_vs_time( else: nuclides = most_abundant - all_nuclides_with_atoms = get_nuclide_atom_densities_from_materials( + all_nuclides_with_atoms = get_nuclide_atoms_from_materials( nuclides=nuclides, materials=all_materials ) diff --git a/src/openmc_depletion_plotter/utils.py b/src/openmc_depletion_plotter/utils.py index f024234..51d2156 100644 --- a/src/openmc_depletion_plotter/utils.py +++ b/src/openmc_depletion_plotter/utils.py @@ -238,6 +238,8 @@ def find_most_abundant_nuclides_in_material( excluded_isotopes = exclude.get_nuclides() non_excluded_nucs = {} + # get_nuclide_atom_densities does not need volume and can be used instead + # of get_nuclide_atoms here as have a single material for key, value in material.get_nuclide_atom_densities().items(): if key not in excluded_isotopes: if key not in non_excluded_nucs.keys(): @@ -271,7 +273,7 @@ def find_total_nuclides_in_materials( for material in materials: material_atom_densities = 0 - for key, value in material.get_nuclide_atom_densities().items(): + for key, value in material.get_nuclide_atoms().items(): if key not in excluded_isotopes: material_atom_densities += value materials_atom_densities.append(material_atom_densities) @@ -293,7 +295,7 @@ def find_most_abundant_nuclides_in_materials( excluded_isotopes = exclude.get_nuclides() for material in materials: - for key, value in material.get_nuclide_atom_densities().items(): + for key, value in material.get_nuclide_atoms().items(): if key not in excluded_isotopes: if key not in non_excluded_nucs.keys(): non_excluded_nucs[key] = value @@ -310,12 +312,12 @@ def find_most_abundant_nuclides_in_materials( return list(sorted_dict.keys()) -def get_nuclide_atom_densities_from_materials(nuclides, materials): +def get_nuclide_atoms_from_materials(nuclides, materials): all_nuclides_with_atoms = {} for isotope in nuclides: all_quants = [] for material in materials: - quants = material.get_nuclide_atom_densities() # units are atom/b-cm + quants = material.get_nuclide_atoms() if isotope in quants.keys(): quant = quants[isotope] else: diff --git a/tests/test_python_api.py b/tests/test_python_api.py index 2990519..ed16805 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -2,7 +2,7 @@ from openmc_depletion_plotter import find_most_abundant_nuclides_in_materials from openmc_depletion_plotter import find_most_active_nuclides_in_material from openmc_depletion_plotter import find_most_active_nuclides_in_materials -from openmc_depletion_plotter import get_nuclide_atom_densities_from_materials +from openmc_depletion_plotter import get_nuclide_atoms_from_materials import openmc @@ -64,10 +64,12 @@ def test_two_identical_materials(): my_mat = openmc.Material() my_mat.add_nuclide("Li6", 1) my_mat.add_nuclide("Li7", 0.5) + my_mat.volume = 1 my_mat_2 = openmc.Material() my_mat_2.add_nuclide("Li6", 1) my_mat_2.add_nuclide("Li7", 0.5) + my_mat_2.volume = 1 nucs = find_most_abundant_nuclides_in_materials( materials=[my_mat, my_mat_2], @@ -81,10 +83,12 @@ def test_two_similar_materials(): my_mat = openmc.Material() my_mat.add_nuclide("Li6", 0.5) my_mat.add_nuclide("Li7", 0.5) + my_mat.volume = 1 my_mat_2 = openmc.Material() my_mat_2.add_nuclide("Li6", 0.6) my_mat_2.add_nuclide("Li7", 0.7) + my_mat_2.volume = 1 nucs = find_most_abundant_nuclides_in_materials( materials=[my_mat, my_mat_2], @@ -98,10 +102,12 @@ def test_openmc_material(): my_mat = openmc.Material() my_mat.add_nuclide("Li6", 0.5) my_mat.add_nuclide("Li7", 0.5) + my_mat.volume = 1 my_mat_2 = openmc.Material() my_mat_2.add_nuclide("Fe56", 0.6) my_mat_2.add_nuclide("Be9", 0.6) + my_mat_2.volume = 1 nucs = find_most_abundant_nuclides_in_materials( materials=[my_mat, my_mat_2], exclude=my_mat @@ -115,10 +121,12 @@ def test_openmc_material_shared_isotope(): my_mat = openmc.Material() my_mat.add_nuclide("Li6", 0.5) my_mat.add_nuclide("Li7", 0.5) + my_mat.volume = 1 my_mat_2 = openmc.Material() my_mat_2.add_nuclide("Fe56", 0.6) my_mat_2.add_nuclide("Li7", 0.6) + my_mat_2.volume = 1 nucs = find_most_abundant_nuclides_in_materials( materials=[my_mat, my_mat_2], exclude=my_mat @@ -127,17 +135,19 @@ def test_openmc_material_shared_isotope(): assert nucs == ["Fe56"] -def test_get_nuclide_atom_densities_from_materials(): +def test_get_nuclide_atoms_from_materials(): my_mat = openmc.Material() my_mat.add_nuclide("Li6", 0.5) my_mat.add_nuclide("Li7", 0.5) + my_mat.volume = 1 my_mat_2 = openmc.Material() my_mat_2.add_nuclide("Fe56", 0.6) my_mat_2.add_nuclide("Li7", 0.6) + my_mat_2.volume = 1 - nucs = get_nuclide_atom_densities_from_materials( + nucs = get_nuclide_atoms_from_materials( nuclides=["Li6", "Fe56"], materials=[my_mat, my_mat_2] )