2015-09-14 21:42:25 -04:00
|
|
|
import glob
|
|
|
|
|
import os
|
2022-05-19 13:08:29 -04:00
|
|
|
from pathlib import Path
|
2018-01-29 10:53:46 -06:00
|
|
|
|
2022-05-19 13:27:02 -04:00
|
|
|
import numpy as np
|
|
|
|
|
import openmc
|
2018-01-29 10:53:46 -06:00
|
|
|
import pytest
|
|
|
|
|
|
2022-05-19 13:08:29 -04:00
|
|
|
from tests.testing_harness import TestHarness, config
|
2013-11-07 10:17:51 +01:00
|
|
|
|
|
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
class TrackTestHarness(TestHarness):
|
|
|
|
|
def _test_output_created(self):
|
|
|
|
|
"""Make sure statepoint.* and track* have been created."""
|
|
|
|
|
TestHarness._test_output_created(self)
|
2013-11-07 10:17:51 +01:00
|
|
|
|
2022-05-19 13:08:29 -04:00
|
|
|
if config['mpi'] and int(config['mpi_np']) > 1:
|
|
|
|
|
outputs = Path.cwd().glob('tracks_p*.h5')
|
|
|
|
|
assert len(list(outputs)) == int(config['mpi_np'])
|
|
|
|
|
else:
|
|
|
|
|
assert Path('tracks.h5').is_file()
|
2013-11-07 10:17:51 +01:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
def _get_results(self):
|
2022-05-19 13:27:02 -04:00
|
|
|
"""Get data from track file and return as a string."""
|
|
|
|
|
|
|
|
|
|
# For MPI mode, combine track files
|
|
|
|
|
if config['mpi']:
|
2025-02-15 05:58:30 +01:00
|
|
|
track_files = list(glob.glob('tracks_p*.h5'))
|
|
|
|
|
openmc.Tracks.combine(track_files, 'tracks.h5')
|
2022-05-19 13:27:02 -04:00
|
|
|
|
|
|
|
|
# Get string of track file information
|
|
|
|
|
outstr = ''
|
2022-05-25 16:58:20 -05:00
|
|
|
tracks = openmc.Tracks('tracks.h5')
|
2022-05-19 13:27:02 -04:00
|
|
|
for track in tracks:
|
|
|
|
|
with np.printoptions(formatter={'float_kind': '{:.6e}'.format}):
|
2022-05-25 14:52:44 -05:00
|
|
|
for ptrack in track:
|
|
|
|
|
outstr += f"{ptrack.particle} {ptrack.states}\n"
|
2015-06-28 00:06:33 -06:00
|
|
|
|
|
|
|
|
return outstr
|
2014-02-25 13:41:24 -05:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
def _cleanup(self):
|
|
|
|
|
TestHarness._cleanup(self)
|
2022-05-19 13:08:29 -04:00
|
|
|
output = glob.glob('tracks*') + glob.glob('poly*')
|
2015-06-25 00:10:07 -06:00
|
|
|
for f in output:
|
|
|
|
|
if os.path.exists(f):
|
|
|
|
|
os.remove(f)
|
2014-02-25 13:41:24 -05:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2018-01-29 12:10:24 -06:00
|
|
|
def test_track_output():
|
2015-06-25 00:10:07 -06:00
|
|
|
# If vtk python module is not available, we can't run track.py so skip this
|
|
|
|
|
# test.
|
2018-01-29 11:39:37 -06:00
|
|
|
vtk = pytest.importorskip('vtk')
|
2017-04-07 10:25:24 -05:00
|
|
|
harness = TrackTestHarness('statepoint.2.h5')
|
2015-06-29 18:50:53 -06:00
|
|
|
harness.main()
|