Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ docs/source/pythonapi/examples/mgxs
docs/source/pythonapi/examples/tracks
docs/source/pythonapi/examples/fission-rates
docs/source/pythonapi/examples/plots

# Cython files
*.c
*.html
*.so
72 changes: 61 additions & 11 deletions docs/source/pythonapi/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ Functions
.. autosummary::
:toctree: generated
:nosignatures:
:template: myfunction.rst

openmc.model.create_triso_lattice
openmc.model.pack_trisos
Expand All @@ -341,16 +342,6 @@ Functions
:mod:`openmc.data` -- Nuclear Data Interface
--------------------------------------------

Physical Data
-------------

.. autosummary::
:toctree: generated
:nosignatures:
:template: myfunction.rst

openmc.data.atomic_mass

Core Classes
------------

Expand All @@ -363,11 +354,23 @@ Core Classes
openmc.data.Reaction
openmc.data.Product
openmc.data.Tabulated1D
openmc.data.FissionEnergyRelease
openmc.data.ThermalScattering
openmc.data.CoherentElastic
openmc.data.FissionEnergyRelease
openmc.data.DataLibrary

Core Functions
--------------

.. autosummary::
:toctree: generated
:nosignatures:
:template: myfunction.rst

openmc.data.atomic_mass
openmc.data.write_compact_458_library

Angle-Energy Distributions
--------------------------

Expand All @@ -381,6 +384,7 @@ Angle-Energy Distributions
openmc.data.CorrelatedAngleEnergy
openmc.data.UncorrelatedAngleEnergy
openmc.data.NBodyPhaseSpace
openmc.data.LaboratoryAngleEnergy
openmc.data.AngleDistribution
openmc.data.EnergyDistribution
openmc.data.ArbitraryTabulated
Expand All @@ -393,6 +397,24 @@ Angle-Energy Distributions
openmc.data.LevelInelastic
openmc.data.ContinuousTabular

Resonance Data
--------------

.. autosummary::
:toctree: generated
:nosignatures:
:template: myclass.rst

openmc.data.Resonances
openmc.data.ResonanceRange
openmc.data.SingleLevelBreitWigner
openmc.data.MultiLevelBreitWigner
openmc.data.ReichMoore
openmc.data.RMatrixLimited
openmc.data.ParticlePair
openmc.data.SpinGroup
openmc.data.Unresolved

ACE Format
----------

Expand All @@ -413,9 +435,37 @@ Functions
.. autosummary::
:toctree: generated
:nosignatures:
:template: myfunction.rst

openmc.data.ace.ascii_to_binary
openmc.data.write_compact_458_library

ENDF Format
-----------

Classes
+++++++

.. autosummary::
:toctree: generated
:nosignatures:
:template: myclass.rst

openmc.data.endf.Evaluation

Functions
+++++++++

.. autosummary::
:toctree: generated
:nosignatures:
:template: myfunction.rst

openmc.data.endf.float_endf
openmc.data.endf.get_cont_record
openmc.data.endf.get_head_record
openmc.data.endf.get_tab1_record
openmc.data.endf.get_tab2_record
openmc.data.endf.get_text_record

.. _Jupyter: https://jupyter.org/
.. _NumPy: http://www.numpy.org/
Expand Down
2 changes: 2 additions & 0 deletions openmc/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .ace import *
from .angle_distribution import *
from .function import *
from .endf import *
from .energy_distribution import *
from .product import *
from .angle_energy import *
Expand All @@ -15,3 +16,4 @@
from .urr import *
from .library import *
from .fission_energy import *
from .resonance import *
110 changes: 109 additions & 1 deletion openmc/data/angle_distribution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from collections import Iterable
from io import StringIO
from numbers import Real
from warnings import warn

import numpy as np

import openmc.checkvalue as cv
from openmc.mixin import EqualityMixin
from openmc.stats import Univariate, Tabular, Uniform
from openmc.stats import Univariate, Tabular, Uniform, Legendre
from .function import INTERPOLATION_SCHEME
from .endf import get_head_record, get_cont_record, get_tab1_record, \
get_list_record, get_tab2_record


class AngleDistribution(EqualityMixin):
Expand Down Expand Up @@ -199,3 +203,107 @@ def from_ace(cls, ace, location_dist, location_start):
mu.append(mu_i)

return cls(energy, mu)

@classmethod
def from_endf(cls, ev, mt):
"""Generate an angular distribution from an ENDF evaluation

Parameters
----------
ev : openmc.data.endf.Evaluation
ENDF evaluation
mt : int
The MT value of the reaction to get angular distributions for

Returns
-------
openmc.data.AngleDistribution
Angular distribution

"""
file_obj = StringIO(ev.section[4, mt])

# Read HEAD record
items = get_head_record(file_obj)
lvt = items[2]
ltt = items[3]

# Read CONT record
items = get_cont_record(file_obj)
li = items[2]
nk = items[4]
center_of_mass = (items[3] == 2)

# Check for obsolete energy transformation matrix. If present, just skip
# it and keep reading
if lvt > 0:
warn('Obsolete energy transformation matrix in MF=4 angular '
'distribution.')
for _ in range((nk + 5)//6):
file_obj.readline()

if ltt == 0 and li == 1:
# Purely isotropic
energy = np.array([0., ev.info['energy_max']])
mu = [Uniform(-1., 1.), Uniform(-1., 1.)]

elif ltt == 1 and li == 0:
# Legendre polynomial coefficients
params, tab2 = get_tab2_record(file_obj)
n_energy = params[5]

energy = np.zeros(n_energy)
mu = []
for i in range(n_energy):
items, al = get_list_record(file_obj)
temperature = items[0]
energy[i] = items[1]
coefficients = np.asarray([1.0] + al)
mu.append(Legendre(coefficients))

elif ltt == 2 and li == 0:
# Tabulated probability distribution
params, tab2 = get_tab2_record(file_obj)
n_energy = params[5]

energy = np.zeros(n_energy)
mu = []
for i in range(n_energy):
params, f = get_tab1_record(file_obj)
temperature = params[0]
energy[i] = params[1]
if f.n_regions > 1:
raise NotImplementedError('Angular distribution with multiple '
'interpolation regions not supported.')
mu.append(Tabular(f.x, f.y, INTERPOLATION_SCHEME[f.interpolation[0]]))

elif ltt == 3 and li == 0:
# Legendre for low energies / tabulated for high energies
params, tab2 = get_tab2_record(file_obj)
n_energy_legendre = params[5]

energy_legendre = np.zeros(n_energy_legendre)
mu = []
for i in range(n_energy_legendre):
items, al = get_list_record(file_obj)
temperature = items[0]
energy_legendre[i] = items[1]
coefficients = np.asarray([1.0] + al)
mu.append(Legendre(coefficients))

params, tab2 = get_tab2_record(file_obj)
n_energy_tabulated = params[5]

energy_tabulated = np.zeros(n_energy_tabulated)
for i in range(n_energy_tabulated):
params, f = get_tab1_record(file_obj)
temperature = params[0]
energy_tabulated[i] = params[1]
if f.n_regions > 1:
raise NotImplementedError('Angular distribution with multiple '
'interpolation regions not supported.')
mu.append(Tabular(f.x, f.y, INTERPOLATION_SCHEME[f.interpolation[0]]))

energy = np.concatenate((energy_legendre, energy_tabulated))

return AngleDistribution(energy, mu)
3 changes: 2 additions & 1 deletion openmc/data/angle_energy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABCMeta, abstractmethod
from io import StringIO

import openmc.data
from openmc.mixin import EqualityMixin
Expand Down Expand Up @@ -40,7 +41,7 @@ def from_hdf5(group):

@staticmethod
def from_ace(ace, location_dist, location_start, rx=None):
"""Generate an AngleEnergy object from ACE data
"""Generate an angle-energy distribution from ACE data

Parameters
----------
Expand Down
53 changes: 52 additions & 1 deletion openmc/data/correlated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import numpy as np

import openmc.checkvalue as cv
from openmc.stats import Tabular, Univariate, Discrete, Mixture, Uniform
from openmc.stats import Tabular, Univariate, Discrete, Mixture, \
Uniform, Legendre
from .function import INTERPOLATION_SCHEME
from .angle_energy import AngleEnergy
from .endf import get_list_record, get_tab2_record


class CorrelatedAngleEnergy(AngleEnergy):
Expand Down Expand Up @@ -405,3 +407,52 @@ def from_ace(cls, ace, idx, ldis):
mu.append(mu_i)

return cls(breakpoints, interpolation, energy, energy_out, mu)

@classmethod
def from_endf(cls, file_obj):
"""Generate correlated angle-energy distribution from an ENDF evaluation

Parameters
----------
file_obj : file-like object
ENDF file positioned at the start of a section for a correlated
angle-energy distribution

Returns
-------
openmc.data.CorrelatedAngleEnergy
Correlated angle-energy distribution

"""
params, tab2 = get_tab2_record(file_obj)
lep = params[3]
ne = params[5]
energy = np.zeros(ne)
n_discrete_energies = np.zeros(ne, dtype=int)
energy_out = []
mu = []
for i in range(ne):
items, values = get_list_record(file_obj)
energy[i] = items[1]
n_discrete_energies[i] = items[2]
# TODO: separate out discrete lines
n_angle = items[3]
n_energy_out = items[5]
values = np.asarray(values)
values.shape = (n_energy_out, n_angle + 2)

# Outgoing energy distribution at the i-th incoming energy
eout_i = values[:,0]
eout_p_i = values[:,1]
energy_out_i = Tabular(eout_i, eout_p_i, INTERPOLATION_SCHEME[lep],
ignore_negative=True)
energy_out.append(energy_out_i)

# Legendre coefficients used for angular distributions
mu_i = []
for j in range(n_energy_out):
mu_i.append(Legendre(values[j,1:]))
mu.append(mu_i)

return cls(tab2.breakpoints, tab2.interpolation, energy,
energy_out, mu)
Loading