mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Add volume calculation test
This commit is contained in:
parent
08c9036bb6
commit
aaefad9e2e
4 changed files with 97 additions and 0 deletions
1
tests/test_volume_calc/inputs_true.dat
Normal file
1
tests/test_volume_calc/inputs_true.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
b2de6ac20ca2ca38b00d61adae707d05519f6130eea25ab050220bac005cb6d23fa5812bf876307e92e90a8806f0b371500c5611ab23f80b7c073f118eb31649
|
||||
13
tests/test_volume_calc/results_true.dat
Normal file
13
tests/test_volume_calc/results_true.dat
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
k-combined: 4.165451e-02 3.582531e-04
|
||||
Cell 1: 31.4693 +/- 0.0721 cm^3
|
||||
Cell 2: 2.0933 +/- 0.0310 cm^3
|
||||
Cell 3: 2.0486 +/- 0.0307 cm^3
|
||||
Cell Nuclide Atoms Uncertainty
|
||||
0 1 U235.71c 3.481769e+23 7.979991e+20
|
||||
1 1 Mo99.71c 3.481769e+22 7.979991e+19
|
||||
2 2 H1.71c 1.399770e+23 2.072914e+21
|
||||
3 2 O16.71c 6.998852e+22 1.036457e+21
|
||||
4 2 B10.71c 6.998852e+18 1.036457e+17
|
||||
5 3 H1.71c 1.369920e+23 2.051689e+21
|
||||
6 3 O16.71c 6.849599e+22 1.025844e+21
|
||||
7 3 B10.71c 6.849599e+18 1.025844e+17
|
||||
82
tests/test_volume_calc/test_volume_calc.py
Normal file
82
tests/test_volume_calc/test_volume_calc.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.pardir)
|
||||
from testing_harness import PyAPITestHarness
|
||||
import openmc
|
||||
|
||||
|
||||
class VolumeTest(PyAPITestHarness):
|
||||
def _build_inputs(self):
|
||||
# Define materials
|
||||
water = openmc.Material(1)
|
||||
water.add_nuclide('H1', 2.0)
|
||||
water.add_nuclide('O16', 1.0)
|
||||
water.add_nuclide('B10', 0.0001)
|
||||
water.add_s_alpha_beta('c_H_in_H2O', '71t')
|
||||
water.set_density('g/cc', 1.0)
|
||||
|
||||
fuel = openmc.Material(2)
|
||||
fuel.add_nuclide('U235', 1.0)
|
||||
fuel.add_nuclide('Mo99', 0.1)
|
||||
fuel.set_density('g/cc', 4.5)
|
||||
|
||||
materials = openmc.Materials((water, fuel))
|
||||
materials.default_xs = '71c'
|
||||
materials.export_to_xml()
|
||||
|
||||
cyl = openmc.ZCylinder(1, R=1.0, boundary_type='vacuum')
|
||||
top_sphere = openmc.Sphere(2, z0=5., R=1., boundary_type='vacuum')
|
||||
top_plane = openmc.ZPlane(3, z0=5.)
|
||||
bottom_sphere = openmc.Sphere(4, z0=-5., R=1., boundary_type='vacuum')
|
||||
bottom_plane = openmc.ZPlane(5, z0=-5.)
|
||||
|
||||
# Define geometry
|
||||
inside_cyl = openmc.Cell(1, fill=fuel, region=-cyl & -top_plane & +bottom_plane)
|
||||
top_hemisphere = openmc.Cell(2, fill=water, region=-top_sphere & +top_plane)
|
||||
bottom_hemisphere = openmc.Cell(3, fill=water, region=-bottom_sphere & -top_plane)
|
||||
root = openmc.Universe(0, cells=(inside_cyl, top_hemisphere, bottom_hemisphere))
|
||||
|
||||
geometry = openmc.Geometry()
|
||||
geometry.root_universe = root
|
||||
geometry.export_to_xml()
|
||||
|
||||
# Set up stochastic volume calculation
|
||||
vol_calc = openmc.VolumeCalculation(
|
||||
[inside_cyl, top_hemisphere, bottom_hemisphere],
|
||||
100000)
|
||||
|
||||
# Define settings
|
||||
settings = openmc.Settings()
|
||||
settings.particles = 1000
|
||||
settings.batches = 4
|
||||
settings.inactive = 0
|
||||
settings.source = openmc.Source(space=openmc.stats.Box(
|
||||
[-1., -1., -5.], [1., 1., 5.]))
|
||||
settings.volume_calculations = vol_calc
|
||||
settings.export_to_xml()
|
||||
|
||||
def _get_results(self):
|
||||
# Read the statepoint file.
|
||||
statepoint = os.path.join(os.getcwd(), self._sp_name)
|
||||
sp = openmc.StatePoint(statepoint)
|
||||
|
||||
# Write out k-combined.
|
||||
outstr = 'k-combined: {:12.6e} {:12.6e}\n'.format(*sp.k_combined)
|
||||
|
||||
# Read volume calculation results
|
||||
vol = openmc.VolumeCalculation.from_hdf5(
|
||||
os.path.join(os.getcwd(), 'volume_1.h5'))
|
||||
|
||||
# Write cell volumes and total # of atoms for each nuclide
|
||||
for cell_id, results in sorted(vol.results.items()):
|
||||
outstr += 'Cell {0}: {1[0]:.4f} +/- {1[1]:.4f} cm^3\n'.format(
|
||||
cell_id, results['volume'])
|
||||
outstr += str(vol.atoms_dataframe) + '\n'
|
||||
|
||||
return outstr
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness = VolumeTest('statepoint.4.h5')
|
||||
harness.main()
|
||||
|
|
@ -137,6 +137,7 @@ class TestHarness(object):
|
|||
output.append(os.path.join(os.getcwd(), 'tallies.out'))
|
||||
output.append(os.path.join(os.getcwd(), 'results_test.dat'))
|
||||
output.append(os.path.join(os.getcwd(), 'summary.h5'))
|
||||
output += glob.glob(os.path.join(os.getcwd(), 'volume_*.h5'))
|
||||
for f in output:
|
||||
if os.path.exists(f):
|
||||
os.remove(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue