Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added testing and working for nuclides #4

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions openmc/deplete/coupled_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import copy
from warnings import warn
from typing import Optional

import numpy as np
from uncertainties import ufloat
Expand All @@ -33,18 +34,19 @@
__all__ = ["CoupledOperator", "Operator", "OperatorResult"]


def _find_cross_sections(model):
def _find_cross_sections(model: Optional[str] = None):
"""Determine cross sections to use for depletion

Parameters
----------
model : openmc.model.Model
model : openmc.model.Model, optional
Reactor model

"""
if model.materials and model.materials.cross_sections is not None:
# Prefer info from Model class if available
return model.materials.cross_sections
if model:
if model.materials and model.materials.cross_sections is not None:
# Prefer info from Model class if available
return model.materials.cross_sections

# otherwise fallback to environment variable
cross_sections = openmc.config.get("cross_sections")
Expand All @@ -67,7 +69,7 @@ def _get_nuclides_with_data(cross_sections):
Returns
-------
nuclides : set of str
Set of nuclide names that have cross secton data
Set of nuclide names that have cross section data

"""
nuclides = set()
Expand Down
27 changes: 7 additions & 20 deletions openmc/deplete/microxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ def _resolve_chain_file_path(chain_file:str):
return chain_file


def _resolve_openmc_data_path(openmc_data_path: str=None):
if not openmc_data_path:
if 'cross_sections' not in openmc.config:
raise ValueError("`openmc_data_path` is not defined nor `openmc.config['cross_sections']` is defined.")
else:
openmc_data_path = openmc.config['cross_sections']
return openmc_data_path



def get_microxs_and_flux(
model: openmc.Model,
domains,
Expand Down Expand Up @@ -216,8 +206,7 @@ def from_multi_group_flux(
energies: Union[Iterable[float], str],
multi_group_flux: Sequence[float],
chain_file: Optional[PathLike] = None,
openmc_data_path: Optional[PathLike] = None,
temperature: int=294,
temperature: float=294.,
nuclides: Optional[Iterable[str]] = None,
):
"""Generated MicroXS object from a known flux and a chain file.
Expand All @@ -235,9 +224,6 @@ def from_multi_group_flux(
chain_file : str, optional
Path to the depletion chain XML file that will be used in
depletion simulation. Defaults to ``openmc.config['chain_file']``.
openmc_data_path : str, optional
Path to the cross section XML file that contains data library paths.
Defaults to ``openmc.config['cross_sections']``.
temperature : int, optional
Temperature for cross section evaluation in [K].
nuclides : list of str
Expand All @@ -249,7 +235,7 @@ def from_multi_group_flux(
MicroXS
"""

check_type("temperature", temperature, int)
check_type("temperature", temperature, (int, float))
# if energy is string then use group structure of that name
if isinstance(energies, str):
energies = openmc.EnergyFilter.from_group_structure(energies).values
Expand All @@ -266,15 +252,15 @@ def from_multi_group_flux(
chain_file_path = _resolve_chain_file_path(chain_file)
chain = openmc.deplete.Chain.from_xml(chain_file_path)

openmc_data_path = _resolve_openmc_data_path(openmc_data_path)
cross_sections = openmc.data.DataLibrary.from_xml(openmc_data_path)
cross_sections = _find_cross_sections(model=None)
data_lib = openmc.data.DataLibrary.from_xml(cross_sections)
nuclides_with_data = _get_nuclides_with_data(cross_sections)

# get reactions and nuclides from chain file
if not nuclides:
nuclides = chain.nuclides
nuclides = chain.nuclides
nuclides = [nuc.name for nuc in nuclides]
reactions = chain.reactions
nuclides = [nuc.name for nuc in nuclides]
if 'fission' in reactions:
# send to back
reactions.append(reactions.pop(reactions.index('fission')))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elegant.

Expand Down Expand Up @@ -308,6 +294,7 @@ def from_multi_group_flux(
settings.particles = 1
settings.batches = 1
settings.output = {'summary': False}

model = openmc.Model(geometry, materials, settings)
model.export_to_model_xml()

Expand Down
2 changes: 1 addition & 1 deletion openmc/lib/nuclide.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def collapse_rate(self, MT, temperature, energy, flux):
energy : iterable of float
Energy group boundaries in [eV]
flux : iterable of float
Flux in each energt group (not normalized per eV)
Flux in each energy group (not normalized per eV)

Returns
-------
Expand Down
13 changes: 13 additions & 0 deletions tests/unit_tests/test_deplete_microxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_csv():

def test_from_multi_group_flux():

# test with energy group structure from string
microxs = MicroXS.from_multi_group_flux(
energies='CASMO-4',
multi_group_flux=[1.1e-7, 1.2e-6, 1.3e-5, 1.4e-4],
Expand All @@ -68,10 +69,22 @@ def test_from_multi_group_flux():
)
assert isinstance(microxs, MicroXS)

# test with energy group structure as floats
microxs = MicroXS.from_multi_group_flux(
energies=[0., 6.25e-1, 5.53e3, 8.21e5, 2.e7],
multi_group_flux=[1.1e-7, 1.2e-6, 1.3e-5, 1.4e-4],
temperature=293,
chain_file=Path(__file__).parents[1] / 'chain_simple.xml'
)
assert isinstance(microxs, MicroXS)

# test with nuclides provided
microxs = MicroXS.from_multi_group_flux(
energies=[0., 6.25e-1, 5.53e3, 8.21e5, 2.e7],
multi_group_flux=[1.1e-7, 1.2e-6, 1.3e-5, 1.4e-4],
temperature=293,
chain_file=Path(__file__).parents[1] / 'chain_simple.xml',
nuclides=['Gd157']
)
assert microxs.nuclides == ['Gd157']
assert isinstance(microxs, MicroXS)