From 2e54c31915ceb05ade36575f87f9a51f4a982343 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 25 May 2022 16:58:20 -0500 Subject: [PATCH] Rename TrackFile --> Tracks --- docs/source/pythonapi/base.rst | 2 +- docs/source/usersguide/settings.rst | 30 ++++++++++++--------- openmc/trackfile.py | 4 +-- scripts/openmc-track-combine | 2 +- scripts/openmc-track-to-vtk | 2 +- tests/regression_tests/track_output/test.py | 2 +- tests/unit_tests/test_tracks.py | 10 +++---- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/docs/source/pythonapi/base.rst b/docs/source/pythonapi/base.rst index bc4325ae5..076b02722 100644 --- a/docs/source/pythonapi/base.rst +++ b/docs/source/pythonapi/base.rst @@ -189,7 +189,7 @@ Post-processing openmc.StatePoint openmc.Summary openmc.Track - openmc.TrackFile + openmc.Tracks The following classes and functions are used for functional expansion reconstruction. diff --git a/docs/source/usersguide/settings.rst b/docs/source/usersguide/settings.rst index db06d8a0e..d1242f70c 100644 --- a/docs/source/usersguide/settings.rst +++ b/docs/source/usersguide/settings.rst @@ -545,9 +545,9 @@ tracks will be written as follows:: settings.max_tracks = 1000 Particle track information is written to the ``tracks.h5`` file, which can be -analyzed using the :class:`~openmc.TrackFile` class:: +analyzed using the :class:`~openmc.Tracks` class:: - >>> tracks = openmc.TrackFile('tracks.h5') + >>> tracks = openmc.Tracks('tracks.h5') >>> tracks [, , @@ -557,19 +557,25 @@ Each :class:`~openmc.Track` object stores a list of track information for every primary/secondary particle. In the above example, the first source particle produced 150 secondary particles for a total of 151 particles. Information for each primary/secondary particle can be accessed using the -:attr:`~openmc.Track.particles` attribute:: +:attr:`~openmc.Track.particle_tracks` attribute:: >>> first_track = tracks[0] - >>> len(first_track.particles) - 151 - >>> photon = first_track.particles[10] - ParticleTrack(particle=, states=array([...])) + >>> first_track.particle_tracks + [, + , + , + , + , + ... + , + ] + >>> photon = first_track.particle_tracks[1] -The :class:`~openmc.ParticleTrack` class is a named tuple indicating the particle -type and then a NumPy array of the "states". The states array is a compound type -with a field for each physical quantity (position, direction, energy, time, -weight, cell ID, and material ID). For example, to get the position for the -above particle track:: +The :class:`~openmc.ParticleTrack` class is a named tuple indicating the +particle type and then a NumPy array of the "states". The states array is a +compound type with a field for each physical quantity (position, direction, +energy, time, weight, cell ID, and material ID). For example, to get the +position for the above particle track:: >>> photon.states['r'] array([(-11.92987939, -12.28467295, 0.67837495), diff --git a/openmc/trackfile.py b/openmc/trackfile.py index 179371260..b3bf2e904 100644 --- a/openmc/trackfile.py +++ b/openmc/trackfile.py @@ -189,7 +189,7 @@ class Track(Sequence): return sources -class TrackFile(list): +class Tracks(list): """Collection of particle tracks This class behaves like a list and can be indexed using the normal subscript @@ -202,7 +202,7 @@ class TrackFile(list): """ - def __init__(self, filepath): + def __init__(self, filepath='tracks.h5'): # Read data from track file with h5py.File(filepath, 'r') as fh: # Check filetype and version diff --git a/scripts/openmc-track-combine b/scripts/openmc-track-combine index 155fe9b54..f69f2151c 100755 --- a/scripts/openmc-track-combine +++ b/scripts/openmc-track-combine @@ -17,7 +17,7 @@ def main(): help='Output HDF5 particle track file.') args = parser.parse_args() - openmc.TrackFile.combine(args.input, args.out) + openmc.Tracks.combine(args.input, args.out) if __name__ == '__main__': diff --git a/scripts/openmc-track-to-vtk b/scripts/openmc-track-to-vtk index 7959ad35d..2624ad239 100755 --- a/scripts/openmc-track-to-vtk +++ b/scripts/openmc-track-to-vtk @@ -39,7 +39,7 @@ def main(): point_offset = 0 for fname in args.input: # Write coordinate values to points array. - track_file = openmc.TrackFile(fname) + track_file = openmc.Tracks(fname) for track in track_file: for particle in track.particles: for state in particle.states: diff --git a/tests/regression_tests/track_output/test.py b/tests/regression_tests/track_output/test.py index 49dfcefe3..62526117d 100644 --- a/tests/regression_tests/track_output/test.py +++ b/tests/regression_tests/track_output/test.py @@ -31,7 +31,7 @@ class TrackTestHarness(TestHarness): # Get string of track file information outstr = '' - tracks = openmc.TrackFile('tracks.h5') + tracks = openmc.Tracks('tracks.h5') for track in tracks: with np.printoptions(formatter={'float_kind': '{:.6e}'.format}): for ptrack in track: diff --git a/tests/unit_tests/test_tracks.py b/tests/unit_tests/test_tracks.py index 4c820724d..bf54e700f 100644 --- a/tests/unit_tests/test_tracks.py +++ b/tests/unit_tests/test_tracks.py @@ -36,7 +36,7 @@ def generate_track_file(model, **kwargs): if config['mpi'] and int(config['mpi_np']) > 1: # With MPI, we need to combine track files track_files = Path.cwd().glob('tracks_p*.h5') - openmc.TrackFile.combine(track_files, 'tracks.h5') + openmc.Tracks.combine(track_files, 'tracks.h5') else: track_file = Path('tracks.h5') assert track_file.is_file() @@ -54,7 +54,7 @@ def test_tracks(sphere_model, particle, run_in_tmpdir): generate_track_file(sphere_model) # Open track file and make sure we have correct number of tracks - tracks = openmc.TrackFile('tracks.h5') + tracks = openmc.Tracks('tracks.h5') assert len(tracks) == len(sphere_model.settings.track) for track, identifier in zip(tracks, sphere_model.settings.track): @@ -105,7 +105,7 @@ def test_max_tracks(sphere_model, run_in_tmpdir): generate_track_file(sphere_model, tracks=True) # Open track file and make sure we have correct number of tracks - tracks = openmc.TrackFile('tracks.h5') + tracks = openmc.Tracks('tracks.h5') assert len(tracks) == expected_num_tracks @@ -117,7 +117,7 @@ def test_filter(sphere_model, run_in_tmpdir): # Run OpenMC to generate tracks.h5 file generate_track_file(sphere_model, tracks=True) - tracks = openmc.TrackFile('tracks.h5') + tracks = openmc.Tracks('tracks.h5') for track in tracks: # Test filtering by particle matches = track.filter(particle='photon') @@ -132,7 +132,7 @@ def test_filter(sphere_model, run_in_tmpdir): matches = track.filter(state_filter=lambda s: s['E'] < 0.0) assert matches == [] - # Test filter method on TrackFile + # Test filter method on Tracks matches = tracks.filter(particle='neutron') assert matches == tracks matches = tracks.filter(state_filter=lambda s: s['E'] > 0.0)