Added tests and fixed code accordingly

This commit is contained in:
Adam Nelson 2020-10-22 14:13:32 -05:00
parent 6f4da06580
commit d2c00b4f1b
12 changed files with 45629 additions and 818 deletions

View file

@ -30,6 +30,7 @@ Multi-group Cross Sections
:template: myclassinherit.rst
openmc.mgxs.MGXS
openmc.mgxs.MatrixMGXS
openmc.mgxs.AbsorptionXS
openmc.mgxs.CaptureXS
openmc.mgxs.Chi
@ -45,6 +46,9 @@ Multi-group Cross Sections
openmc.mgxs.ScatterProbabilityMatrix
openmc.mgxs.TotalXS
openmc.mgxs.TransportXS
openmc.mgxs.ArbitraryXS
openmc.mgxs.ArbitraryMatrixXS
openmc.mgxs.MeshSurfaceMGXS
Multi-delayed-group Cross Sections
----------------------------------
@ -55,6 +59,7 @@ Multi-delayed-group Cross Sections
:template: myclassinherit.rst
openmc.mgxs.MDGXS
openmc.mgxs.MatrixMDGXS
openmc.mgxs.ChiDelayed
openmc.mgxs.DelayedNuFissionXS
openmc.mgxs.DelayedNuFissionMatrixXS

View file

@ -199,7 +199,7 @@ enum ReactionType {
N_3N3HE = 177,
N_4N3HE = 178,
N_3N2P = 179,
N_3N3A = 180,
N_3N2A = 180,
N_3NPA = 181,
N_DT = 182,
N_NPD = 183,

View file

@ -56,7 +56,7 @@ REACTION_NAME = {1: '(n,total)', 2: '(n,elastic)', 4: '(n,level)',
301: 'heating', 444: 'damage-energy',
649: '(n,pc)', 699: '(n,dc)', 749: '(n,tc)', 799: '(n,3Hec)',
849: '(n,ac)', 891: '(n,2nc)', 901: 'heating-local'}
REACTION_NAME.update({i: '(n,n{})'.format(i - 50) for i in range(50, 91)})
REACTION_NAME.update({i: '(n,n{})'.format(i - 50) for i in range(51, 91)})
REACTION_NAME.update({i: '(n,p{})'.format(i - 600) for i in range(600, 649)})
REACTION_NAME.update({i: '(n,d{})'.format(i - 650) for i in range(650, 699)})
REACTION_NAME.update({i: '(n,t{})'.format(i - 700) for i in range(700, 749)})

View file

@ -277,7 +277,9 @@ class Library:
@mgxs_types.setter
def mgxs_types(self, mgxs_types):
all_mgxs_types = openmc.mgxs.MGXS_TYPES + openmc.mgxs.MDGXS_TYPES
all_mgxs_types = openmc.mgxs.MGXS_TYPES + openmc.mgxs.MDGXS_TYPES + \
openmc.mgxs.ARBITRARY_VECTOR_TYPES + \
openmc.mgxs.ARBITRARY_MATRIX_TYPES
if mgxs_types == 'all':
self._mgxs_types = all_mgxs_types
else:

View file

@ -8,7 +8,7 @@ import h5py
import numpy as np
import openmc
from openmc.data import REACTION_MT
from openmc.data import REACTION_MT, REACTION_NAME, FISSION_MTS
import openmc.checkvalue as cv
from ..tallies import ESTIMATOR_TYPES
from . import EnergyGroups
@ -43,6 +43,22 @@ MGXS_TYPES = (
'nu-diffusion-coefficient'
)
# Some scores from REACTION_MT are not supported, or are simply overkill to
# support and test (like inelastic levels), remoev those from consideration
_BAD_SCORES = ["(n,misc)", "(n,absorption)", "(n,total)", "fission"]
_BAD_SCORES += [REACTION_NAME[mt] for mt in FISSION_MTS]
ARBITRARY_VECTOR_TYPES = [k for k in REACTION_MT.keys() if k not in _BAD_SCORES]
ARBITRARY_VECTOR_TYPES = tuple(ARBITRARY_VECTOR_TYPES)
ARBITRARY_MATRIX_TYPES = []
for rxn in ARBITRARY_VECTOR_TYPES:
# Preclude the fission channels from being treated as a matrix
if rxn not in [REACTION_NAME[mt] for mt in FISSION_MTS]:
split_rxn = rxn.strip("()").split(",")
if len(split_rxn) > 1 and "n" in split_rxn[1]:
# Then there is a neutron product, so it can also be a matrix
ARBITRARY_MATRIX_TYPES.append(rxn + " matrix")
ARBITRARY_MATRIX_TYPES = tuple(ARBITRARY_MATRIX_TYPES)
# Supported domain types
DOMAIN_TYPES = (
'cell',
@ -733,6 +749,10 @@ class MGXS:
"""
cv.check_value(
"mgxs_type", mgxs_type,
MGXS_TYPES + ARBITRARY_VECTOR_TYPES + ARBITRARY_MATRIX_TYPES)
if mgxs_type == 'total':
mgxs = TotalXS(domain, domain_type, energy_groups)
elif mgxs_type == 'transport':
@ -786,35 +806,14 @@ class MGXS:
mgxs = DiffusionCoefficient(domain, domain_type, energy_groups)
elif mgxs_type == 'nu-diffusion-coefficient':
mgxs = DiffusionCoefficient(domain, domain_type, energy_groups, nu=True)
else:
# Now parse the REACTION_MT options, or raise an error
if mgxs_type in REACTION_MT.keys():
# Then it is a reaction not covered by the above that is
# supported by the ArbitraryXS Class
mgxs = ArbitraryXS(mgxs_type, domain, domain_type,
elif mgxs_type in ARBITRARY_VECTOR_TYPES:
# Then it is a reaction not covered by the above that is
# supported by the ArbitraryXS Class
mgxs = ArbitraryXS(mgxs_type, domain, domain_type, energy_groups)
elif mgxs_type in ARBITRARY_MATRIX_TYPES:
mgxs = ArbitraryMatrixXS(mgxs_type, domain, domain_type,
energy_groups)
elif mgxs_type.endswith("matrix"):
# Then we should see if it is a valid REACTION_MT type
# To do that, split it into words
split_mgxs_types = mgxs_type.split(" ")
rxn = split_mgxs_types[0]
# Check for correctness
if rxn not in REACTION_MT.keys():
# This is an invalid type so let the user know.
msg = 'Unable to set "{0}" to "{1}"'.format("mgxs_type",
mgxs_type) + \
" as it is not an accepted MGXS type."
raise ValueError(msg)
mgxs = ArbitraryMatrixXS(mgxs_type, domain, domain_type,
energy_groups)
else:
# This is an invalid type so let the user know.
msg = 'Unable to set "{0}" to "{1}"'.format("mgxs_type",
mgxs_type) + \
" as it is not an accepted MGXS type."
raise ValueError(msg)
mgxs.by_nuclide = by_nuclide
mgxs.name = name
mgxs.num_polar = num_polar
@ -4000,6 +3999,7 @@ class ArbitraryXS(MGXS):
def __init__(self, rxn_type, domain=None, domain_type=None, groups=None,
by_nuclide=False, name='', num_polar=1, num_azimuthal=1):
cv.check_value("rxn_type", rxn_type, ARBITRARY_VECTOR_TYPES)
super().__init__(domain, domain_type, groups, by_nuclide, name,
num_polar, num_azimuthal)
self._rxn_type = rxn_type
@ -4062,9 +4062,6 @@ class ArbitraryMatrixXS(MatrixMGXS):
num_azimuthal : Integral, optional
Number of equi-width azimuthal angle bins for angle discretization;
defaults to one bin
prompt : bool
If true, computes cross sections which only includes prompt neutrons;
defaults to False which includes prompt and delayed in total
Attributes
----------
@ -4072,8 +4069,6 @@ class ArbitraryMatrixXS(MatrixMGXS):
Name of the multi-group cross section
rxn_type : str
Reaction type (e.g., 'total', 'nu-fission', etc.)
prompt : bool
If true, computes cross sections which only includes prompt neutrons
by_nuclide : bool
If true, computes cross sections for each nuclide in domain
domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.RegularMesh
@ -4134,38 +4129,13 @@ class ArbitraryMatrixXS(MatrixMGXS):
"""
def __init__(self, domain=None, domain_type=None, groups=None,
def __init__(self, rxn_type, domain=None, domain_type=None, groups=None,
by_nuclide=False, name='', num_polar=1,
num_azimuthal=1, prompt=False):
num_azimuthal=1):
cv.check_value("rxn_type", rxn_type, ARBITRARY_MATRIX_TYPES)
super().__init__(domain, domain_type, groups, by_nuclide, name,
num_polar, num_azimuthal)
# Do that with the error variable just because PEP8 puts us in
# a hard place for multi-line if conditionals
# First we see if there are more words than there should be,
# then we make sure its a valid reaction, then we dont allow
# non (n,...) type reactions like 'heating-local' as they cant
# be matrices
split_rxn_type = rxn_type.split(" ")
error = len(split_rxn_type) > 2 or rxn not in REACTION_MT.keys() or \
not rxn.startswith("(")
if error:
# This is an invalid type so let the user know.
msg = 'Unable to set "{0}" to "{1}"'.format("rxns_type",
rxn_type) + \
" as it is not an accepted ArbitraryMatrixXS type."
raise ValueError(msg)
# See if the rxn can be a matrix type; we've already made sure its
# an (X,Y) type of reaction, get the product (Y)
_, product = rxn.strip("()").split(',', maxsplit=2)
if "n" not in product:
msg = 'Unable to set "{0}" to "{1}"'.format("rxns_type",
rxn_type) + \
" as it is not an accepted ArbitraryMatrixXS type."
raise ValueError(msg)
# If we made it here, then we are good to go
self._rxn_type = rxn_type
self._rxn_type = rxn_type.split(" ")[0]
self._estimator = 'analog'
self._valid_estimators = ['analog']

View file

@ -243,7 +243,7 @@ std::unordered_map<int, std::string> REACTION_NAME_MAP {
{N_3N3HE, "(n,3n3He)"},
{N_4N3HE, "(n,4n3He)"},
{N_3N2P, "(n,3n2p)"},
{N_3N3A, "(n,3n3a)"},
{N_3N2A, "(n,3n2a)"},
{N_3NPA, "(n,3npa)"},
{N_DT, "(n,dt)"},
{N_NPD, "(n,npd)"},

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@ import hashlib
import openmc
import openmc.mgxs
from openmc.data import REACTION_MT
from openmc.examples import pwr_pin_cell
from tests.testing_harness import PyAPITestHarness
@ -22,6 +23,8 @@ class MGXSTestHarness(PyAPITestHarness):
# Test all relevant MGXS types
relevant_MGXS_TYPES = [item for item in openmc.mgxs.MGXS_TYPES
if item != 'current']
relevant_MGXS_TYPES += openmc.mgxs.ARBITRARY_VECTOR_TYPES
relevant_MGXS_TYPES += openmc.mgxs.ARBITRARY_MATRIX_TYPES
self.mgxs_lib.mgxs_types = tuple(relevant_MGXS_TYPES) + \
openmc.mgxs.MDGXS_TYPES
self.mgxs_lib.energy_groups = energy_groups
@ -48,7 +51,7 @@ class MGXSTestHarness(PyAPITestHarness):
for mgxs_type in self.mgxs_lib.mgxs_types:
mgxs = self.mgxs_lib.get_mgxs(domain, mgxs_type)
df = mgxs.get_pandas_dataframe()
outstr += df.to_string() + '\n'
outstr += mgxs_type + '\n' + df.to_string() + '\n'
# Hash the results if necessary
if hash_output:

File diff suppressed because it is too large Load diff

View file

@ -1 +1 @@
14f7fb2e399a4ad124b25b88dda5104d43cca9192aa1c17261da40bcc0e4394e56781f42f79c90107d0ff6b3e901f034bed09b037670e60b9ac4009b3805e17d
7462fdc05825053847d93b9238b57d47ab5eb9244542279489a23b2a87423e7e58d22efa9b6db7db74ab9628b73ff37750af3de60102da5ad05f69700a1b3b8d

View file

@ -21,6 +21,8 @@ class MGXSTestHarness(PyAPITestHarness):
# Test relevant all MGXS types
relevant_MGXS_TYPES = [item for item in openmc.mgxs.MGXS_TYPES
if item != 'current']
relevant_MGXS_TYPES += openmc.mgxs.ARBITRARY_VECTOR_TYPES
relevant_MGXS_TYPES += openmc.mgxs.ARBITRARY_MATRIX_TYPES
self.mgxs_lib.mgxs_types = tuple(relevant_MGXS_TYPES)
self.mgxs_lib.energy_groups = energy_groups
self.mgxs_lib.legendre_order = 3