diff --git a/docs/source/usersguide/scripts.rst b/docs/source/usersguide/scripts.rst index 963e91cf2d..f38e1fd168 100644 --- a/docs/source/usersguide/scripts.rst +++ b/docs/source/usersguide/scripts.rst @@ -114,6 +114,17 @@ tallies. The path to the statepoint file can be provided as an optional arugment .. _scripts_track: +------------------------ +``openmc-track-combine`` +------------------------ + +This script combines multiple HDF5 :ref:`particle track files +` into a single HDF5 particle track file. The filenames of the +particle track files should be given as posititional arguments. The output +filename can also be changed with the ``-o`` flag: + +-o OUT, --out OUT Output HDF5 particle track file + ----------------------- ``openmc-track-to-vtk`` ----------------------- diff --git a/scripts/openmc-track-combine b/scripts/openmc-track-combine new file mode 100755 index 0000000000..4bd2fb0820 --- /dev/null +++ b/scripts/openmc-track-combine @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +"""Combine multiple HDF5 particle track files. + +""" + +import argparse + +import h5py + + +def main(): + # Parse command-line arguments + parser = argparse.ArgumentParser( + description='Combine particle track files into a single .h5 file.') + parser.add_argument('input', metavar='IN', nargs='+', + help='Input HDF5 particle track filename(s).') + parser.add_argument('-o', '--out', metavar='OUT', default='tracks.h5', + help='Output HDF5 particle track file.') + + args = parser.parse_args() + + with h5py.File(args.out, 'w') as h5_out: + for i, fname in enumerate(args.input): + with h5py.File(fname, 'r') as h5_in: + # Copy file attributes for first file + if i == 0: + h5_out.attrs['filetype'] = h5_in.attrs['filetype'] + h5_out.attrs['version'] = h5_in.attrs['version'] + + # Copy each 'track_*' dataset from input file + for dset in h5_in: + h5_in.copy(dset, h5_out) + + +if __name__ == '__main__': + main() diff --git a/src/track_output.cpp b/src/track_output.cpp index c75468b1f3..a5d4e6c2fc 100644 --- a/src/track_output.cpp +++ b/src/track_output.cpp @@ -2,6 +2,7 @@ #include "openmc/constants.h" #include "openmc/hdf5_interface.h" +#include "openmc/message_passing.h" #include "openmc/position.h" #include "openmc/settings.h" #include "openmc/simulation.h" @@ -40,8 +41,18 @@ void write_particle_track(Particle& p) void open_track_file() { - // Open file and write filetype/version + // Open file and write filetype/version -- when MPI is enabled and there is + // more than one rank, each rank writes its own file +#ifdef OPENMC_MPI + std::string filename; + if (mpi::n_procs > 1) { + filename = fmt::format("{}tracks_p{}.h5", settings::path_output, mpi::rank); + } else { + filename = fmt::format("{}tracks.h5", settings::path_output); + } +#else std::string filename = fmt::format("{}tracks.h5", settings::path_output); +#endif track_file = file_open(filename, 'w'); write_attribute(track_file, "filetype", "track"); write_attribute(track_file, "version", VERSION_TRACK);