extended tally arithmetic test to cover different hybrid tallies and fixed bug in tallies.py

This commit is contained in:
Sam Shaner 2015-12-18 13:59:16 -08:00
parent 4a21ac8bf6
commit 587f0e8f0e
7 changed files with 1691 additions and 114 deletions

View file

@ -1846,7 +1846,7 @@ class Tally(object):
else:
filter1_bins = [(filter1.get_bin(i)) for i in range(filter1.num_bins)]
if filter1.type == 'distribcell':
if filter2.type == 'distribcell':
filter2_bins = np.arange(filter2.num_bins)
else:
filter2_bins = [filter2.get_bin(i) for i in range(filter2.num_bins)]

View file

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<geometry>
<!-- Sphere with radius 10 -->
<surface id="1" type="sphere" coeffs="0 0 0 10" boundary="vacuum"/>
<cell id="1" material="1" region="-1" />
</geometry>

View file

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<materials>
<material id="1">
<density value="4.5" units="g/cc" />
<nuclide name="U-238" xs="71c" ao="1.0" />
<nuclide name="U-235" xs="71c" ao="1.0" />
<nuclide name="Pu-239" xs="71c" ao="1.0" />
</material>
</materials>

File diff suppressed because it is too large Load diff

View file

@ -1,18 +0,0 @@
<?xml version="1.0"?>
<settings>
<eigenvalue>
<batches>10</batches>
<inactive>5</inactive>
<particles>1000</particles>
</eigenvalue>
<source>
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>
</source>
<output summary="true"/>
</settings>

View file

@ -1,15 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<tallies>
<tally id="10000" name="tally 1">
<filter bins="1" type="cell" />
<filter bins="0.0 20.0" type="energy" />
<nuclides>U-235 U-238</nuclides>
<scores>fission nu-fission</scores>
</tally>
<tally id="10001" name="tally 2">
<filter bins="1" type="material" />
<filter bins="0.0 20.0" type="energy" />
<nuclides>U-235 Pu-239</nuclides>
<scores>fission absorption</scores>
</tally>
</tallies>

View file

@ -5,11 +5,87 @@ import sys
import glob
import hashlib
sys.path.insert(0, os.pardir)
from testing_harness import TestHarness
from testing_harness import PyAPITestHarness
import openmc
class TallyArithmeticTestHarness(TestHarness):
class TallyArithmeticTestHarness(PyAPITestHarness):
def _build_inputs(self):
# The summary.h5 file needs to be created to read in the tallies
self._input_set.settings.output = {'summary': True}
# Initialize the tallies file
tallies_file = openmc.TalliesFile()
# Initialize the nuclides
u235 = openmc.Nuclide('U-235')
u238 = openmc.Nuclide('U-238')
pu239 = openmc.Nuclide('Pu-239')
zr90 = openmc.Nuclide('Zr-90')
o16 = openmc.Nuclide('O-16')
# Initialize Mesh
mesh = openmc.Mesh(mesh_id=1)
mesh.type = 'regular'
mesh.dimension = [2, 2, 2]
mesh.lower_left = [-160.0, -160.0, -183.0]
mesh.upper_right = [160.0, 160.0, 183.0]
# Initialize the filters
energy_filter = openmc.Filter(type='energy', bins=(0.0, 0.253e-6,
1.0e-3, 1.0, 20.0))
material_filter = openmc.Filter(type='material', bins=(1, 3))
universe_filter = openmc.Filter(type='universe', bins=(1, 3))
distrib_filter = openmc.Filter(type='distribcell', bins=(60))
mesh_filter = openmc.Filter(type='mesh')
mesh_filter.mesh = mesh
# Initialized the tallies
tally = openmc.Tally(name='tally 1')
tally.add_filter(material_filter)
tally.add_filter(energy_filter)
tally.add_score('nu-fission')
tally.add_score('total')
tally.add_nuclide(u235)
tally.add_nuclide(pu239)
tallies_file.add_tally(tally)
# Instantiate reaction rate Tally in fuel
tally = openmc.Tally(name='tally 2')
tally.add_filter(universe_filter)
tally.add_filter(energy_filter)
tally.add_score('total')
tally.add_score('fission')
tally.add_nuclide(u238)
tally.add_nuclide(u235)
tallies_file.add_tally(tally)
# Instantiate reaction rate Tally in moderator
tally = openmc.Tally(name='tally 3')
tally.add_filter(distrib_filter)
tally.add_filter(energy_filter)
tally.add_score('absorption')
tally.add_score('total')
tally.add_nuclide(u235)
tally.add_nuclide(o16)
tallies_file.add_tally(tally)
# Instantiate reaction rate Tally in moderator
tally = openmc.Tally(name='tally 4')
tally.add_filter(mesh_filter)
tally.add_filter(energy_filter)
tally.add_score('scatter')
tally.add_score('total')
tally.add_nuclide(u235)
tally.add_nuclide(zr90)
tallies_file.add_tally(tally)
tallies_file.add_mesh(mesh)
# Export tallies to file
self._input_set.tallies = tallies_file
super(TallyArithmeticTestHarness, self)._build_inputs()
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""
@ -22,27 +98,87 @@ class TallyArithmeticTestHarness(TestHarness):
su = openmc.Summary(summary)
sp.link_with_summary(su)
print 'reading in tallies'
# Load the tallies
tally_1 = sp.get_tally(name='tally 1')
tally_2 = sp.get_tally(name='tally 2')
tally_3 = sp.get_tally(name='tally 3')
tally_4 = sp.get_tally(name='tally 4')
# Perform all the tally arithmetic operations and output results
outstr = ''
tally_3 = tally_1 + tally_2
outstr += repr(tally_3)
outstr += str(tally_3.mean)
tally_5 = tally_1 * tally_2
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_3 = tally_1 - tally_2
outstr += repr(tally_3)
outstr += str(tally_3.mean)
tally_5 = tally_1.hybrid_product(tally_2, '*', 'entrywise', 'tensor',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_3 = tally_1 * tally_2
outstr += repr(tally_3)
outstr += str(tally_3.mean)
tally_5 = tally_1.hybrid_product(tally_2, '*', 'entrywise', 'entrywise',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_3 = tally_1 / tally_2
outstr += repr(tally_3)
outstr += str(tally_3.mean)
tally_5 = tally_1.hybrid_product(tally_2, '*', 'entrywise', 'tensor',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_2, '*', 'entrywise', 'entrywise',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1 * tally_3
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_3, '*', 'entrywise', 'tensor',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_3, '*', 'entrywise', 'entrywise',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_3, '*', 'entrywise', 'tensor',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_3, '*', 'entrywise', 'entrywise',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1 * tally_4
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_4, '*', 'entrywise', 'tensor',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_4, '*', 'entrywise', 'entrywise',
'tensor')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_4, '*', 'entrywise', 'tensor',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
tally_5 = tally_1.hybrid_product(tally_4, '*', 'entrywise', 'entrywise',
'entrywise')
outstr += repr(tally_5)
outstr += str(tally_5.mean)
print(outstr)
@ -54,6 +190,11 @@ class TallyArithmeticTestHarness(TestHarness):
return outstr
def _cleanup(self):
super(TallyArithmeticTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = TallyArithmeticTestHarness('statepoint.10.h5', True)
harness.main()