mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Add test for Chain.from_endf. Remove tqdm dependence.
This commit is contained in:
parent
7622a1a394
commit
ab00421c0e
5 changed files with 35 additions and 30 deletions
|
|
@ -26,7 +26,7 @@ MOCK_MODULES = [
|
|||
'numpy.ctypeslib', 'scipy', 'scipy.sparse', 'scipy.sparse.linalg',
|
||||
'scipy.interpolate', 'scipy.integrate', 'scipy.optimize', 'scipy.special',
|
||||
'scipy.stats', 'scipy.spatial', 'h5py', 'pandas', 'uncertainties',
|
||||
'matplotlib', 'matplotlib.pyplot', 'tqdm', 'openmoc',
|
||||
'matplotlib', 'matplotlib.pyplot', 'openmoc',
|
||||
'openmc.data.reconstruct'
|
||||
]
|
||||
sys.modules.update((mod_name, MagicMock()) for mod_name in MOCK_MODULES)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import io
|
|||
import re
|
||||
import os
|
||||
from math import pi
|
||||
from pathlib import PurePath
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Iterable
|
||||
|
||||
|
|
@ -299,8 +300,8 @@ class Evaluation(object):
|
|||
|
||||
"""
|
||||
def __init__(self, filename_or_obj):
|
||||
if isinstance(filename_or_obj, str):
|
||||
fh = open(filename_or_obj, 'r')
|
||||
if isinstance(filename_or_obj, (str, PurePath)):
|
||||
fh = open(str(filename_or_obj), 'r')
|
||||
else:
|
||||
fh = filename_or_obj
|
||||
self.section = {}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ try:
|
|||
except ImportError:
|
||||
import xml.etree.ElementTree as ET
|
||||
_have_lxml = False
|
||||
from tqdm import tqdm
|
||||
import scipy.sparse as sp
|
||||
|
||||
import openmc.data
|
||||
|
|
@ -153,34 +152,31 @@ class Chain(object):
|
|||
chain = cls()
|
||||
|
||||
# Create dictionary mapping target to filename
|
||||
print('Processing neutron sub-library files...')
|
||||
reactions = {}
|
||||
with tqdm(neutron_files) as pbar:
|
||||
for f in pbar:
|
||||
pbar.set_description('Processing {}'.format(os.path.basename(f)))
|
||||
evaluation = openmc.data.endf.Evaluation(f)
|
||||
name = evaluation.gnd_name
|
||||
reactions[name] = {}
|
||||
for mf, mt, nc, mod in evaluation.reaction_list:
|
||||
if mf == 3:
|
||||
file_obj = StringIO(evaluation.section[3, mt])
|
||||
openmc.data.endf.get_head_record(file_obj)
|
||||
q_value = openmc.data.endf.get_cont_record(file_obj)[1]
|
||||
reactions[name][mt] = q_value
|
||||
for f in neutron_files:
|
||||
evaluation = openmc.data.endf.Evaluation(f)
|
||||
name = evaluation.gnd_name
|
||||
reactions[name] = {}
|
||||
for mf, mt, nc, mod in evaluation.reaction_list:
|
||||
if mf == 3:
|
||||
file_obj = StringIO(evaluation.section[3, mt])
|
||||
openmc.data.endf.get_head_record(file_obj)
|
||||
q_value = openmc.data.endf.get_cont_record(file_obj)[1]
|
||||
reactions[name][mt] = q_value
|
||||
|
||||
# Determine what decay and FPY nuclides are available
|
||||
print('Processing decay sub-library files...')
|
||||
decay_data = {}
|
||||
with tqdm(decay_files) as pbar:
|
||||
for f in pbar:
|
||||
pbar.set_description('Processing {}'.format(os.path.basename(f)))
|
||||
data = openmc.data.Decay(f)
|
||||
decay_data[data.nuclide['name']] = data
|
||||
for f in decay_files:
|
||||
data = openmc.data.Decay(f)
|
||||
decay_data[data.nuclide['name']] = data
|
||||
|
||||
print('Processing fission product yield sub-library files...')
|
||||
fpy_data = {}
|
||||
with tqdm(fpy_files) as pbar:
|
||||
for f in pbar:
|
||||
pbar.set_description('Processing {}'.format(os.path.basename(f)))
|
||||
data = openmc.data.FissionProductYields(f)
|
||||
fpy_data[data.nuclide['name']] = data
|
||||
for f in fpy_files:
|
||||
data = openmc.data.FissionProductYields(f)
|
||||
fpy_data[data.nuclide['name']] = data
|
||||
|
||||
print('Creating depletion_chain...')
|
||||
missing_daughter = []
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -57,7 +57,7 @@ kwargs = {
|
|||
# Required dependencies
|
||||
'install_requires': [
|
||||
'numpy>=1.9', 'h5py', 'scipy', 'ipython', 'matplotlib',
|
||||
'pandas', 'lxml', 'uncertainties', 'tqdm'
|
||||
'pandas', 'lxml', 'uncertainties'
|
||||
],
|
||||
|
||||
# Optional dependencies
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import os
|
|||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from openmc.data import zam, ATOMIC_SYMBOL
|
||||
from openmc.deplete import comm, Chain, reaction_rates, nuclide
|
||||
import pytest
|
||||
|
||||
from tests import cdtemp
|
||||
|
||||
_ENDF_DATA = Path(os.environ['OPENMC_ENDF_DATA'])
|
||||
|
||||
_TEST_CHAIN = """\
|
||||
<depletion_chain>
|
||||
|
|
@ -63,9 +65,15 @@ def test_len():
|
|||
|
||||
|
||||
def test_from_endf():
|
||||
"""Test depletion chain building from ENDF. Empty at the moment until we figure
|
||||
out a good way to unit-test this."""
|
||||
pass
|
||||
"""Test depletion chain building from ENDF files"""
|
||||
decay_data = (_ENDF_DATA / 'decay').glob('*.endf')
|
||||
fpy_data = (_ENDF_DATA / 'nfy').glob('*.endf')
|
||||
neutron_data = (_ENDF_DATA / 'neutrons').glob('*.endf')
|
||||
chain = Chain.from_endf(decay_data, fpy_data, neutron_data)
|
||||
|
||||
assert len(chain) == len(chain.nuclides) == len(chain.nuclide_dict) == 3821
|
||||
for nuc in chain.nuclides:
|
||||
assert nuc == chain[nuc.name]
|
||||
|
||||
|
||||
def test_from_xml(simple_chain):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue