Skip to content

Commit

Permalink
Merge pull request #1661 from mkreher13/transient-rewrite
Browse files Browse the repository at this point in the history
Fixed typo from last pull request
  • Loading branch information
nelsonag authored Sep 22, 2020
2 parents 3fb3711 + 23e8ed9 commit 68361b5
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 250 deletions.
2 changes: 1 addition & 1 deletion openmc/mgxs/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def get_xsdata(self, domain, xsdata_name, nuclide='total', xs_type='macro',

if 'decay-rate' in self.mgxs_types:
mymgxs = self.get_mgxs(domain, 'decay-rate')
xsdata.set_decay_rate_mgxs(mymgxs, xs_types=xs_type, nuclide=[nuclide],
xsdata.set_decay_rate_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide],
subdomain=subdomain)

# If multiplicity matrix is available, prefer that
Expand Down
146 changes: 141 additions & 5 deletions openmc/mgxs/mdgxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def get_xs(self, groups='all', subdomains='all', nuclides='all',
-------
numpy.ndarray
A NumPy array of the multi-group cross section indexed in the order
each group, subdomain and nuclide is listed in the parameters.
each group, subdomain and nuclide as listed in the parameters.
Raises
------
Expand Down Expand Up @@ -1872,14 +1872,12 @@ def filters(self):

# Create the non-domain specific Filters for the Tallies
group_edges = self.energy_groups.group_edges
energy_filter = openmc.EnergyFilter(group_edges)

if self.delayed_groups is not None:
delayed_filter = openmc.DelayedGroupFilter(self.delayed_groups)
filters = [[delayed_filter, energy_filter], [delayed_filter,
energy_filter]]
filters = [[delayed_filter], [delayed_filter]]
else:
filters = [[energy_filter], [energy_filter]]
filters = None

return self._add_angle_filters(filters)

Expand Down Expand Up @@ -1922,6 +1920,144 @@ def get_homogenized_mgxs(self, other_mgxs):

return self._get_homogenized_mgxs(other_mgxs, 'delayed-nu-fission')

def get_xs(self, subdomains='all', nuclides='all',
xs_type='macro', order_groups='increasing',
value='mean', delayed_groups='all', squeeze=True, **kwargs):
"""Returns an array of multi-delayed-group cross sections.
This method constructs a 4D NumPy array for the requested
multi-delayed-group cross section data for one or more
subdomains (1st dimension), delayed groups (2nd demension),
energy groups (3rd dimension), and nuclides (4th dimension).
Parameters
----------
subdomains : Iterable of Integral or 'all'
Subdomain IDs of interest. Defaults to 'all'.
nuclides : Iterable of str or 'all' or 'sum'
A list of nuclide name strings (e.g., ['U-235', 'U-238']). The
special string 'all' will return the cross sections for all nuclides
in the spatial domain. The special string 'sum' will return the
cross section summed over all nuclides. Defaults to 'all'.
xs_type: {'macro', 'micro'}
Return the macro or micro cross section in units of cm^-1 or barns.
Defaults to 'macro'.
order_groups: {'increasing', 'decreasing'}
Return the cross section indexed according to increasing or
decreasing energy groups (decreasing or increasing energies).
Defaults to 'increasing'.
value : {'mean', 'std_dev', 'rel_err'}
A string for the type of value to return. Defaults to 'mean'.
delayed_groups : list of int or 'all'
Delayed groups of interest. Defaults to 'all'.
squeeze : bool
A boolean representing whether to eliminate the extra dimensions
of the multi-dimensional array to be returned. Defaults to True.
Returns
-------
numpy.ndarray
A NumPy array of the multi-group cross section indexed in the order
each group, subdomain and nuclide as listed in the parameters.
Raises
------
ValueError
When this method is called before the multi-delayed-group cross
section is computed from tally data.
"""

cv.check_value('value', value, ['mean', 'std_dev', 'rel_err'])
cv.check_value('xs_type', xs_type, ['macro', 'micro'])

# FIXME: Unable to get microscopic xs for mesh domain because the mesh
# cells do not know the nuclide densities in each mesh cell.
if self.domain_type == 'mesh' and xs_type == 'micro':
msg = 'Unable to get micro xs for mesh domain since the mesh ' \
'cells do not know the nuclide densities in each mesh cell.'
raise ValueError(msg)

filters = []
filter_bins = []

# Construct a collection of the domain filter bins
if not isinstance(subdomains, str):
cv.check_iterable_type('subdomains', subdomains, Integral,
max_depth=3)
for subdomain in subdomains:
filters.append(_DOMAIN_TO_FILTER[self.domain_type])
filter_bins.append((subdomain,))

# Construct list of delayed group tuples for all requested groups
if not isinstance(delayed_groups, str):
cv.check_type('delayed groups', delayed_groups, list, int)
for delayed_group in delayed_groups:
filters.append(openmc.DelayedGroupFilter)
filter_bins.append((delayed_group,))

# Construct a collection of the nuclides to retrieve from the xs tally
if self.by_nuclide:
if nuclides == 'all' or nuclides == 'sum' or nuclides == ['sum']:
query_nuclides = self.get_nuclides()
else:
query_nuclides = nuclides
else:
query_nuclides = ['total']

# If user requested the sum for all nuclides, use tally summation
if nuclides == 'sum' or nuclides == ['sum']:
xs_tally = self.xs_tally.summation(nuclides=query_nuclides)
xs = xs_tally.get_values(filters=filters,
filter_bins=filter_bins, value=value)
else:
xs = self.xs_tally.get_values(filters=filters,
filter_bins=filter_bins,
nuclides=query_nuclides, value=value)

# Divide by atom number densities for microscopic cross sections
if xs_type == 'micro' and self._divide_by_density:
if self.by_nuclide:
densities = self.get_nuclide_densities(nuclides)
else:
densities = self.get_nuclide_densities('sum')
if value == 'mean' or value == 'std_dev':
xs /= densities[np.newaxis, :, np.newaxis]

# Eliminate the trivial score dimension
xs = np.squeeze(xs, axis=len(xs.shape) - 1)
xs = np.nan_to_num(xs)

if delayed_groups == 'all':
num_delayed_groups = self.num_delayed_groups
else:
num_delayed_groups = len(delayed_groups)

# Reshape tally data array with separate axes for domain,
# energy groups, delayed groups, and nuclides
# Accommodate the polar and azimuthal bins if needed
num_subdomains = \
int(xs.shape[0] / (num_delayed_groups *
self.num_polar * self.num_azimuthal))
if self.num_polar > 1 or self.num_azimuthal > 1:
new_shape = (self.num_polar, self.num_azimuthal, num_subdomains,
num_delayed_groups)
else:
new_shape = (num_subdomains, num_delayed_groups)
xs = np.reshape(xs, new_shape)

# Reverse data if user requested increasing energy groups since
# tally data is stored in order of increasing energies
if order_groups == 'increasing':
xs = xs[..., ::-1, :]

if squeeze:
# We want to squeeze out everything but the polar, azimuthal,
# delayed group, and energy group data.
xs = self._squeeze_xs(xs)

return xs


class MatrixMDGXS(MDGXS):
"""An abstract multi-delayed-group cross section for some energy group and
Expand Down
4 changes: 2 additions & 2 deletions tests/regression_tests/mgxs_library_condense/inputs_true.dat
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@
<estimator>tracklength</estimator>
</tally>
<tally id="59">
<filters>1 69 2</filters>
<filters>1 69</filters>
<nuclides>total</nuclides>
<scores>delayed-nu-fission</scores>
<estimator>tracklength</estimator>
</tally>
<tally id="60">
<filters>1 69 2</filters>
<filters>1 69</filters>
<nuclides>total</nuclides>
<scores>decay-rate</scores>
<estimator>tracklength</estimator>
Expand Down
52 changes: 26 additions & 26 deletions tests/regression_tests/mgxs_library_condense/results_true.dat
Original file line number Diff line number Diff line change
Expand Up @@ -290,32 +290,32 @@
21 2 2 1 4 1 total 0.002732 0.000330
22 2 2 1 5 1 total 0.001214 0.000143
23 2 2 1 6 1 total 0.000505 0.000059
mesh 1 delayedgroup group in nuclide mean std. dev.
x y z
0 1 1 1 1 1 total 0.013357 0.000929
1 1 1 1 2 1 total 0.032589 0.002199
2 1 1 1 3 1 total 0.121106 0.008007
3 1 1 1 4 1 total 0.306140 0.019650
4 1 1 1 5 1 total 0.862764 0.052685
5 1 1 1 6 1 total 2.897892 0.177498
12 1 2 1 1 1 total 0.013356 0.001330
13 1 2 1 2 1 total 0.032598 0.003165
14 1 2 1 3 1 total 0.121086 0.011554
15 1 2 1 4 1 total 0.305948 0.028460
16 1 2 1 5 1 total 0.862070 0.076649
17 1 2 1 6 1 total 2.895530 0.258195
6 2 1 1 1 1 total 0.013355 0.001389
7 2 1 1 2 1 total 0.032601 0.003293
8 2 1 1 3 1 total 0.121079 0.011980
9 2 1 1 4 1 total 0.305874 0.029310
10 2 1 1 5 1 total 0.861802 0.077464
11 2 1 1 6 1 total 2.894617 0.261360
18 2 2 1 1 1 total 0.013354 0.001670
19 2 2 1 2 1 total 0.032610 0.003972
20 2 2 1 3 1 total 0.121059 0.014468
21 2 2 1 4 1 total 0.305680 0.035462
22 2 2 1 5 1 total 0.861087 0.093863
23 2 2 1 6 1 total 2.892185 0.316700
mesh 1 delayedgroup nuclide mean std. dev.
x y z
0 1 1 1 1 total 0.013357 0.000957
1 1 1 1 2 total 0.032589 0.002282
2 1 1 1 3 total 0.121106 0.008354
3 1 1 1 4 total 0.306140 0.020673
4 1 1 1 5 total 0.862764 0.056302
5 1 1 1 6 total 2.897892 0.189487
12 1 2 1 1 total 0.013356 0.001529
13 1 2 1 2 total 0.032598 0.003723
14 1 2 1 3 total 0.121086 0.013808
15 1 2 1 4 total 0.305948 0.034825
16 1 2 1 5 total 0.862070 0.097922
17 1 2 1 6 total 2.895530 0.328926
6 2 1 1 1 total 0.013355 0.001381
7 2 1 1 2 total 0.032601 0.003301
8 2 1 1 3 total 0.121079 0.012082
9 2 1 1 4 total 0.305874 0.029845
10 2 1 1 5 total 0.861802 0.080523
11 2 1 1 6 total 2.894617 0.271269
18 2 2 1 1 total 0.013354 0.001732
19 2 2 1 2 total 0.032610 0.004117
20 2 2 1 3 total 0.121059 0.014991
21 2 2 1 4 total 0.305680 0.036716
22 2 2 1 5 total 0.861087 0.097002
23 2 2 1 6 total 2.892185 0.327342
mesh 1 delayedgroup group in group out nuclide mean std. dev.
x y z
0 1 1 1 1 1 1 total 0.000000 0.000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@
<estimator>tracklength</estimator>
</tally>
<tally id="58">
<filters>1 65 2</filters>
<filters>1 65</filters>
<nuclides>total</nuclides>
<scores>delayed-nu-fission</scores>
<estimator>tracklength</estimator>
</tally>
<tally id="59">
<filters>1 65 2</filters>
<filters>1 65</filters>
<nuclides>total</nuclides>
<scores>decay-rate</scores>
<estimator>tracklength</estimator>
Expand Down
Loading

0 comments on commit 68361b5

Please sign in to comment.