Skip to content

Commit

Permalink
Rename TrackFile --> Tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed May 25, 2022
1 parent 7b0862c commit 2e54c31
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/source/pythonapi/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
32 changes: 19 additions & 13 deletions docs/source/usersguide/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
[<Track (1, 1, 50): 151 particles>,
<Track (2, 1, 30): 191 particles>,
Expand All @@ -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=<ParticleType.PHOTON: 1>, states=array([...]))

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::
>>> first_track.particle_tracks
[<ParticleTrack: neutron, 120 states>,
<ParticleTrack: photon, 6 states>,
<ParticleTrack: electron, 2 states>,
<ParticleTrack: electron, 2 states>,
<ParticleTrack: electron, 2 states>,
...
<ParticleTrack: electron, 2 states>,
<ParticleTrack: electron, 2 states>]
>>> 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::

>>> photon.states['r']
array([(-11.92987939, -12.28467295, 0.67837495),
Expand Down
4 changes: 2 additions & 2 deletions openmc/trackfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def sources(self):
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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/openmc-track-combine
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/openmc-track-to-vtk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/track_output/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_results(self):

# 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:
Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/test_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down Expand Up @@ -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


Expand All @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 2e54c31

Please sign in to comment.