mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Add test for source file generation
This commit is contained in:
parent
441d081dd5
commit
667fb50a3b
1 changed files with 38 additions and 0 deletions
38
tests/unit_tests/test_source_file.py
Normal file
38
tests/unit_tests/test_source_file.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from random import random
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
import openmc
|
||||
|
||||
|
||||
def test_source_file(run_in_tmpdir):
|
||||
# Create source particles
|
||||
source = []
|
||||
n = 1000
|
||||
for i in range(n):
|
||||
source.append(openmc.SourceParticle(
|
||||
r=(random(), i, 0),
|
||||
u=(0., 0., 1.),
|
||||
E=float(n - i),
|
||||
))
|
||||
|
||||
# Create source file
|
||||
openmc.write_source_file(source, 'test_source.h5')
|
||||
|
||||
# Get array of source particles from file
|
||||
with h5py.File('test_source.h5', 'r') as fh:
|
||||
arr = fh['source_bank'][...]
|
||||
|
||||
# Ensure data is consistent
|
||||
r = arr['r']
|
||||
assert np.all((r['x'] > 0.0) & (r['x'] < 1.0))
|
||||
assert np.all(r['y'] == np.arange(1000))
|
||||
assert np.all(r['z'] == 0.0)
|
||||
u = arr['u']
|
||||
assert np.all(u['x'] == 0.0)
|
||||
assert np.all(u['y'] == 0.0)
|
||||
assert np.all(u['z'] == 1.0)
|
||||
assert np.all(arr['E'] == n - np.arange(n))
|
||||
assert np.all(arr['wgt'] == 1.0)
|
||||
assert np.all(arr['delayed_group'] == 0)
|
||||
assert np.all(arr['particle'] == 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue