2015-10-02 23:19:00 -04:00
|
|
|
import numpy as np
|
2018-01-29 10:53:46 -06:00
|
|
|
|
2017-12-11 14:53:56 +07:00
|
|
|
import openmc
|
|
|
|
|
import openmc.stats
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2018-01-29 10:53:46 -06:00
|
|
|
from tests.testing_harness import PyAPITestHarness
|
|
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2017-12-11 14:53:56 +07:00
|
|
|
class FixedSourceTestHarness(PyAPITestHarness):
|
2015-06-25 00:10:07 -06:00
|
|
|
def _get_results(self):
|
2015-06-28 00:06:33 -06:00
|
|
|
"""Digest info in the statepoint and return as a string."""
|
2015-06-25 00:10:07 -06:00
|
|
|
# Read the statepoint file.
|
|
|
|
|
outstr = ''
|
2018-01-29 10:53:46 -06:00
|
|
|
with openmc.StatePoint(self._sp_name) as sp:
|
2017-04-07 10:25:24 -05:00
|
|
|
# Write out tally data.
|
|
|
|
|
for i, tally_ind in enumerate(sp.tallies):
|
2015-09-16 16:19:12 +07:00
|
|
|
tally = sp.tallies[tally_ind]
|
|
|
|
|
results = np.zeros((tally.sum.size*2, ))
|
|
|
|
|
results[0::2] = tally.sum.ravel()
|
|
|
|
|
results[1::2] = tally.sum_sq.ravel()
|
2015-06-25 00:10:07 -06:00
|
|
|
results = ['{0:12.6E}'.format(x) for x in results]
|
|
|
|
|
|
2017-04-07 10:25:24 -05:00
|
|
|
outstr += 'tally ' + str(i + 1) + ':\n'
|
2015-06-25 00:10:07 -06:00
|
|
|
outstr += '\n'.join(results) + '\n'
|
|
|
|
|
|
2017-04-07 10:25:24 -05:00
|
|
|
gt = sp.global_tallies
|
|
|
|
|
outstr += 'leakage:\n'
|
|
|
|
|
outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum']) + '\n'
|
|
|
|
|
outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum_sq']) + '\n'
|
2015-08-13 23:01:02 -07:00
|
|
|
|
2015-06-28 00:06:33 -06:00
|
|
|
return outstr
|
2013-02-01 15:22:32 -05:00
|
|
|
|
2014-02-25 11:18:51 -05:00
|
|
|
|
2018-01-29 12:10:24 -06:00
|
|
|
def test_fixed_source():
|
2017-12-11 14:53:56 +07:00
|
|
|
mat = openmc.Material()
|
|
|
|
|
mat.add_nuclide('O16', 1.0)
|
|
|
|
|
mat.add_nuclide('U238', 0.0001)
|
|
|
|
|
mat.set_density('g/cc', 7.5)
|
|
|
|
|
|
2019-03-08 11:25:26 -06:00
|
|
|
surf = openmc.Sphere(r=10.0, boundary_type='vacuum')
|
2017-12-11 14:53:56 +07:00
|
|
|
cell = openmc.Cell(fill=mat, region=-surf)
|
|
|
|
|
|
|
|
|
|
model = openmc.model.Model()
|
|
|
|
|
model.geometry.root_universe = openmc.Universe(cells=[cell])
|
|
|
|
|
model.materials.append(mat)
|
|
|
|
|
|
|
|
|
|
model.settings.run_mode = 'fixed source'
|
|
|
|
|
model.settings.batches = 10
|
|
|
|
|
model.settings.particles = 100
|
|
|
|
|
model.settings.temperature = {'default': 294}
|
2023-06-20 21:27:55 -05:00
|
|
|
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point(),
|
|
|
|
|
strength=10.0)
|
2017-12-11 14:53:56 +07:00
|
|
|
|
|
|
|
|
tally = openmc.Tally()
|
|
|
|
|
tally.scores = ['flux']
|
|
|
|
|
model.tallies.append(tally)
|
|
|
|
|
|
|
|
|
|
harness = FixedSourceTestHarness('statepoint.10.h5', model)
|
2015-06-29 18:50:53 -06:00
|
|
|
harness.main()
|