From fe04a839c289acc094ef97dd111eb65d2c4836ae Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 5 Oct 2022 14:28:18 -0500 Subject: [PATCH 1/2] Make sure Material.decay_photon_energy works with no unstable nuclides --- openmc/data/decay.py | 12 ++++++------ openmc/material.py | 11 ++++++----- tests/unit_tests/test_material.py | 6 ++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/openmc/data/decay.py b/openmc/data/decay.py index d7ededf33d..801ef44105 100644 --- a/openmc/data/decay.py +++ b/openmc/data/decay.py @@ -1,10 +1,9 @@ from collections.abc import Iterable from io import StringIO from math import log -from pathlib import Path import re +from typing import Optional from warnings import warn -from xml.etree import ElementTree as ET import numpy as np from uncertainties import ufloat, UFloat @@ -579,7 +578,7 @@ class Decay(EqualityMixin): _DECAY_PHOTON_ENERGY = {} -def decay_photon_energy(nuclide: str) -> Univariate: +def decay_photon_energy(nuclide: str) -> Optional[Univariate]: """Get photon energy distribution resulting from the decay of a nuclide This function relies on data stored in a depletion chain. Before calling it @@ -595,9 +594,10 @@ def decay_photon_energy(nuclide: str) -> Univariate: Returns ------- - openmc.stats.Univariate - Distribution of energies in [eV] of photons emitted from decay. Note - that the probabilities represent intensities, given as [decay/sec]. + openmc.stats.Univariate or None + Distribution of energies in [eV] of photons emitted from decay, or None + if no photon source exists. Note that the probabilities represent + intensities, given as [decay/sec]. """ if not _DECAY_PHOTON_ENERGY: chain_file = openmc.config.get('chain_file') diff --git a/openmc/material.py b/openmc/material.py index 16b5a3048a..e99eec52c4 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -92,10 +92,11 @@ class Material(IDManagerMixin): fissionable_mass : float Mass of fissionable nuclides in the material in [g]. Requires that the :attr:`volume` attribute is set. - decay_photon_energy : openmc.stats.Univariate + decay_photon_energy : openmc.stats.Univariate or None Energy distribution of photons emitted from decay of unstable nuclides - within the material. The integral of this distribution is the total - intensity of the photon source in [decay/sec]. + within the material, or None if no photon source exists. The integral of + this distribution is the total intensity of the photon source in + [decay/sec]. .. versionadded:: 0.14.0 @@ -264,7 +265,7 @@ class Material(IDManagerMixin): return density*self.volume @property - def decay_photon_energy(self) -> Univariate: + def decay_photon_energy(self) -> Optional[Univariate]: atoms = self.get_nuclide_atoms() dists = [] probs = [] @@ -273,7 +274,7 @@ class Material(IDManagerMixin): if source_per_atom is not None: dists.append(source_per_atom) probs.append(num_atoms) - return openmc.data.combine_distributions(dists, probs) + return openmc.data.combine_distributions(dists, probs) if dists else None @classmethod def from_hdf5(cls, group: h5py.Group): diff --git a/tests/unit_tests/test_material.py b/tests/unit_tests/test_material.py index 58df246ddd..80935d68d0 100644 --- a/tests/unit_tests/test_material.py +++ b/tests/unit_tests/test_material.py @@ -573,3 +573,9 @@ def test_decay_photon_energy(): assert src.integral() == pytest.approx(sum( intensity(decay_photon_energy(nuc)) for nuc in m.get_nuclides() )) + + # A material with no unstable nuclides should have no decay photon source + stable = openmc.Material() + stable.add_nuclide('Gd156', 1.0) + stable.volume = 1.0 + assert stable.decay_photon_energy is None From 3779db43b82b0e938c0bc104b1474a98ce581bc9 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 6 Oct 2022 14:55:01 +0100 Subject: [PATCH 2/2] assume cython is present --- setup.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 477f29dec9..eec3313536 100755 --- a/setup.py +++ b/setup.py @@ -5,11 +5,7 @@ import sys import numpy as np from setuptools import setup, find_packages -try: - from Cython.Build import cythonize - have_cython = True -except ImportError: - have_cython = False +from Cython.Build import cythonize # Determine shared library suffix @@ -76,13 +72,9 @@ kwargs = { 'test': ['pytest', 'pytest-cov', 'colorama'], 'vtk': ['vtk'], }, + # Cython is used to add resonance reconstruction and fast float_endf + 'ext_modules': cythonize('openmc/data/*.pyx'), + 'include_dirs': [np.get_include()] } -# If Cython is present, add resonance reconstruction and fast float_endf -if have_cython: - kwargs.update({ - 'ext_modules': cythonize('openmc/data/*.pyx'), - 'include_dirs': [np.get_include()] - }) - setup(**kwargs)