mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Added test for MGXS library subdomain-averaging across distribcells
This commit is contained in:
parent
7a73c2ba47
commit
7bb00368f2
6 changed files with 94 additions and 5 deletions
|
|
@ -405,5 +405,5 @@ class AggregateFilter(object):
|
|||
aggregate_bin_array = np.repeat(aggregate_bin_array, datasize)
|
||||
|
||||
# Construct Pandas DataFrame for the AggregateFilter
|
||||
df = pd.DataFrame({self.aggregate_filter.type: aggregate_bin_array})
|
||||
return df
|
||||
df = pd.DataFrame({self.type: aggregate_bin_array})
|
||||
return df
|
||||
|
|
|
|||
|
|
@ -1219,7 +1219,7 @@ class MGXS(object):
|
|||
df = self.xs_tally.get_pandas_dataframe(summary=summary)
|
||||
|
||||
# Remove the score column since it is homogeneous and redundant
|
||||
if summary and self.domain_type == 'distribcell':
|
||||
if summary and 'distribcell' in self.domain_type:
|
||||
df = df.drop('score', level=0, axis=1)
|
||||
else:
|
||||
df = df.drop('score', axis=1)
|
||||
|
|
|
|||
|
|
@ -63,8 +63,6 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
df = mgxs.get_pandas_dataframe()
|
||||
outstr += df.to_string()
|
||||
|
||||
print(outstr)
|
||||
|
||||
# Hash the results if necessary
|
||||
if hash_output:
|
||||
sha512 = hashlib.sha512()
|
||||
|
|
|
|||
1
tests/test_mgxs_library_distribcell/inputs_true.dat
Normal file
1
tests/test_mgxs_library_distribcell/inputs_true.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
224a9e84e87c8a21385326d34ef27c046107d4a2ace6ee85d7a36142a3726e12532e2fc1a318ab707437e0b306a81c6d2b80c531d4c3210d4162242e6265ba70
|
||||
5
tests/test_mgxs_library_distribcell/results_true.dat
Normal file
5
tests/test_mgxs_library_distribcell/results_true.dat
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
sum(distribcell) group in nuclide mean std. dev.
|
||||
0 sum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... 1 total 0.720213 1.424323 sum(distribcell) group in nuclide mean std. dev.
|
||||
0 sum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... 1 total 0 0 sum(distribcell) group in group out nuclide mean std. dev.
|
||||
0 sum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... 1 1 total 0.70466 1.403916 sum(distribcell) group out nuclide mean std. dev.
|
||||
0 sum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... 1 total 0 0
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
import hashlib
|
||||
sys.path.insert(0, os.pardir)
|
||||
from testing_harness import PyAPITestHarness
|
||||
import openmc
|
||||
import openmc.mgxs
|
||||
|
||||
|
||||
class MGXSTestHarness(PyAPITestHarness):
|
||||
def _build_inputs(self):
|
||||
|
||||
# The openmc.mgxs module needs a summary.h5 file
|
||||
self._input_set.settings.output = {'summary': True}
|
||||
|
||||
# Generate inputs using parent class routine
|
||||
super(MGXSTestHarness, self)._build_inputs()
|
||||
|
||||
# Initialize a one-group structure
|
||||
energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.])
|
||||
|
||||
# Initialize MGXS Library for a few cross section types
|
||||
# for one material-filled cell in the geometry
|
||||
self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry.geometry)
|
||||
self.mgxs_lib.by_nuclide = False
|
||||
self.mgxs_lib.mgxs_types = ['transport', 'nu-fission',
|
||||
'nu-scatter matrix', 'chi']
|
||||
self.mgxs_lib.energy_groups = energy_groups
|
||||
self.mgxs_lib.domain_type = 'distribcell'
|
||||
material_cells = self.mgxs_lib.openmc_geometry.get_all_material_cells()
|
||||
self.mgxs_lib.domains = [material_cells[-1]]
|
||||
self.mgxs_lib.build_library()
|
||||
|
||||
# Initialize a tallies file
|
||||
self._input_set.tallies = openmc.TalliesFile()
|
||||
self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False)
|
||||
self._input_set.tallies.export_to_xml()
|
||||
|
||||
def _get_results(self, hash_output=False):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
|
||||
# Read the statepoint file.
|
||||
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
|
||||
sp = openmc.StatePoint(statepoint)
|
||||
|
||||
# Read the summary file.
|
||||
summary = glob.glob(os.path.join(os.getcwd(), 'summary.h5'))[0]
|
||||
su = openmc.Summary(summary)
|
||||
sp.link_with_summary(su)
|
||||
|
||||
# Load the MGXS library from the statepoint
|
||||
self.mgxs_lib.load_from_statepoint(sp)
|
||||
|
||||
# Average the MGXS across distribcell subdomains
|
||||
avg_lib = self.mgxs_lib.get_subdomain_avg_library()
|
||||
|
||||
# Build a string from Pandas Dataframe for each 1-group MGXS
|
||||
outstr = ''
|
||||
for domain in avg_lib.domains:
|
||||
for mgxs_type in avg_lib.mgxs_types:
|
||||
mgxs = avg_lib.get_mgxs(domain, mgxs_type)
|
||||
df = mgxs.get_pandas_dataframe()
|
||||
outstr += df.to_string()
|
||||
|
||||
# Hash the results if necessary
|
||||
if hash_output:
|
||||
sha512 = hashlib.sha512()
|
||||
sha512.update(outstr.encode('utf-8'))
|
||||
outstr = sha512.hexdigest()
|
||||
|
||||
return outstr
|
||||
|
||||
|
||||
def _cleanup(self):
|
||||
super(MGXSTestHarness, self)._cleanup()
|
||||
f = os.path.join(os.getcwd(), 'tallies.xml')
|
||||
if os.path.exists(f): os.remove(f)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness = MGXSTestHarness('statepoint.10.*', True)
|
||||
harness.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue