added test for tally arithmetic

This commit is contained in:
Sam Shaner 2015-12-08 13:19:02 -05:00
parent 42f438dcab
commit b17a8e07e3
5 changed files with 177 additions and 0 deletions

View file

@ -0,0 +1,8 @@
<?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

@ -0,0 +1,11 @@
<?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>

View file

@ -0,0 +1,49 @@
Tally
ID = 10000
Name = (tally 1 + tally 2)
Filters =
energy [ 0. 20.]
(cell + material) (array([1]), array([1]))
Nuclides = (U-235 + U-235) (U-235 + Pu-239) (U-238 + U-235) (U-238 + Pu-239)
Scores = [(fission + fission), (fission + absorption), (nu-fission + fission), (nu-fission + absorption)]
Estimator = tracklength
[[[ 0.07510122 0.07839105 0.13713377 0.1404236 ]
[ 0.0916553 0.09321683 0.15368785 0.15524938]
[ 0.04596277 0.0492526 0.06126275 0.06455259]
[ 0.06251685 0.06407838 0.07781683 0.07937836]]]Tally
ID = 10001
Name = (tally 1 - tally 2)
Filters =
energy [ 0. 20.]
(cell - material) (array([1]), array([1]))
Nuclides = (U-235 - U-235) (U-235 - Pu-239) (U-238 - U-235) (U-238 - Pu-239)
Scores = [(fission - fission), (fission - absorption), (nu-fission - fission), (nu-fission - absorption)]
Estimator = tracklength
[[[ 0. -0.00328983 0.06203255 0.05874271]
[-0.01655408 -0.01811561 0.04547847 0.04391694]
[-0.02913845 -0.03242829 -0.01383847 -0.0171283 ]
[-0.04569253 -0.04725406 -0.03039255 -0.03195408]]]Tally
ID = 10002
Name = (tally 1 * tally 2)
Filters =
energy [ 0. 20.]
(cell * material) (array([1]), array([1]))
Nuclides = (U-235 * U-235) (U-235 * Pu-239) (U-238 * U-235) (U-238 * Pu-239)
Scores = [(fission * fission), (fission * absorption), (nu-fission * fission), (nu-fission * absorption)]
Estimator = tracklength
[[[ 0.00141005 0.00153358 0.00373941 0.00406702]
[ 0.00203166 0.0020903 0.00538792 0.00554342]
[ 0.00031588 0.00034356 0.00089041 0.00096841]
[ 0.00045514 0.00046827 0.00128294 0.00131997]]]Tally
ID = 10003
Name = (tally 1 / tally 2)
Filters =
energy [ 0. 20.]
(cell / material) (array([1]), array([1]))
Nuclides = (U-235 / U-235) (U-235 / Pu-239) (U-238 / U-235) (U-238 / Pu-239)
Scores = [(fission / fission), (fission / absorption), (nu-fission / fission), (nu-fission / absorption)]
Estimator = tracklength
[[[ 1. 0.91944666 2.65197177 2.4383466 ]
[ 0.69403611 0.67456727 1.84056418 1.78893335]
[ 0.22402189 0.20597618 0.63147153 0.58060439]
[ 0.15547928 0.15111784 0.43826405 0.42597002]]]

View file

@ -0,0 +1,18 @@
<?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

@ -0,0 +1,91 @@
#!/usr/bin/env python
import os
import sys
import glob
import hashlib
sys.path.insert(0, os.pardir)
from testing_harness import TestHarness
import openmc
class TallyArithmeticTestHarness(TestHarness):
def _build_inputs(self):
u235 = openmc.Nuclide('U-235')
u238 = openmc.Nuclide('U-238')
pu239 = openmc.Nuclide('Pu-239')
# Instantiate energy filter
energy_filter = openmc.Filter(type='energy', bins=[0., 20.])
# Create tallies
tally_1 = openmc.Tally(name='tally 1')
tally_1.add_filter(openmc.Filter(type='cell', bins=[1]))
tally_1.add_filter(energy_filter)
tally_1.add_score('fission')
tally_1.add_score('nu-fission')
tally_1.add_nuclide(u235)
tally_1.add_nuclide(u238)
tally_2 = openmc.Tally(name='tally 2')
tally_2.add_filter(openmc.Filter(type='material', bins=[1]))
tally_2.add_filter(energy_filter)
tally_2.add_score('fission')
tally_2.add_score('absorption')
tally_2.add_nuclide(u235)
tally_2.add_nuclide(pu239)
# Export tallies to file
tallies_file = openmc.TalliesFile()
tallies_file.add_tally(tally_1)
tallies_file.add_tally(tally_2)
tallies_file.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 tallies
tally_1 = sp.get_tally(name='tally 1')
tally_2 = sp.get_tally(name='tally 2')
# Perform all the tally arithmetic operations and output results
outstr = ''
tally_3 = tally_1 + tally_2
outstr += tally_3.__repr__()
outstr += str(tally_3.mean)
tally_3 = tally_1 - tally_2
outstr += tally_3.__repr__()
outstr += str(tally_3.mean)
tally_3 = tally_1 * tally_2
outstr += tally_3.__repr__()
outstr += str(tally_3.mean)
tally_3 = tally_1 / tally_2
outstr += tally_3.__repr__()
outstr += str(tally_3.mean)
print(outstr)
# Hash the results if necessary
if hash_output:
sha512 = hashlib.sha512()
sha512.update(outstr.encode('utf-8'))
outstr = sha512.hexdigest()
return outstr
if __name__ == '__main__':
harness = TallyArithmeticTestHarness('statepoint.10.*', True)
harness.main()