From 9d4363d9311f295ab54c17f3021f82ec4b3bd73e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 3 Apr 2017 10:06:49 -0500 Subject: [PATCH] Update scripts section, fix bugs in openmc-plot-mesh-tally --- docs/source/usersguide/install.rst | 56 ++++-------- docs/source/usersguide/scripts.rst | 136 +++++++++++++++++++++++++++++ scripts/openmc-get-nndc-data | 2 +- scripts/openmc-plot-mesh-tally | 46 +++++----- scripts/openmc-track-to-vtk | 17 +--- scripts/openmc-update-inputs | 27 ++---- scripts/openmc-update-mgxs | 17 ---- 7 files changed, 187 insertions(+), 114 deletions(-) diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index 01cfd9879c..978b7a1cc7 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -445,10 +445,9 @@ or multi-group mode. In continuous-energy mode, OpenMC uses a native HDF5 format to store all nuclear data. If you have ACE format data that was produced with NJOY_, such as that distributed with MCNP_ or Serpent_, it can be converted to the HDF5 format using -the :ref:`openmc-ace-to-hdf5 ` script distributed with -OpenMC. Several sources provide openly available ACE data as described -below. The TALYS-based evaluated nuclear data library, TENDL_, is also available -in ACE format. +the :ref:`scripts_ace` script. Several sources provide openly available ACE +data as described below. The TALYS-based evaluated nuclear data library, TENDL_, +is also available in ACE format. In multi-group mode, OpenMC utilizes an XML-based library format which can be used to describe nuclide- or material-specific quantities. @@ -457,8 +456,8 @@ Using ENDF/B-VII.1 Cross Sections from NNDC ------------------------------------------- The NNDC_ provides ACE data from the ENDF/B-VII.1 neutron and thermal scattering -sublibraries at four temperatures processed using NJOY_. To use this data with -OpenMC, a script is provided with OpenMC that will automatically download and +sublibraries at room temperature processed using NJOY_. To use this data with +OpenMC, the :ref:`scripts_nndc` script can be used to automatically download and extract the ACE data, fix any deficiencies, and create an HDF5 library: .. code-block:: sh @@ -473,8 +472,9 @@ Using JEFF Cross Sections from OECD/NEA --------------------------------------- The NEA_ provides processed ACE data from the JEFF_ library. To use this data -with OpenMC, a script is provided with OpenMC that will automatically download -and extract the ACE data, fix any deficiencies, and create an HDF5 library. +with OpenMC, the :ref:`scripts_jeff` script can be used to automatically +download and extract the ACE data, fix any deficiencies, and create an HDF5 +library. .. code-block:: sh @@ -486,10 +486,11 @@ variable to the absolute path of the file ``jeff-3.2-hdf5/cross_sections.xml``. Using Cross Sections from MCNP ------------------------------ -OpenMC is provided with a script that will automatically convert ENDF/B-VII.0 -and ENDF/B-VII.1 ACE data that is provided with MCNP5 or MCNP6. To convert the -ENDF/B-VII.0 ACE files (``endf70[a-k]`` and ``endf70sab``) into the native HDF5 -format, run the following: +OpenMC provides two scripts (:ref:`scripts_mcnp70` and :ref:`scripts_mcnp71`) +that will automatically convert ENDF/B-VII.0 and ENDF/B-VII.1 ACE data that is +provided with MCNP5 or MCNP6. To convert the ENDF/B-VII.0 ACE files +(``endf70[a-k]`` and ``endf70sab``) into the native HDF5 format, run the +following: .. code-block:: sh @@ -514,9 +515,9 @@ Using Other Cross Sections -------------------------- If you have a library of ACE format cross sections other than those listed above -that you need to convert to OpenMC's HDF5 format, the ``openmc-ace-to-hdf5`` -script can be used. There are four different ways you can specify ACE libraries -that are to be converted: +that you need to convert to OpenMC's HDF5 format, the :ref:`scripts_ace` script +can be used. There are four different ways you can specify ACE libraries that +are to be converted: 1. List each ACE library as a positional argument. This is very useful in conjunction with the usual shell utilities (ls, find, etc.). @@ -531,31 +532,6 @@ convention follows the NNDC data convention (1000*Z + A + 300 + 100*m), or the MCNP data convention (essentially the same as NNDC, except that the first metastable state of Am242 is 95242 and the ground state is 95642). -The ``openmc-ace-to-hdf5`` script has the following command-line flags: - --h, --help show this help message and exit - --d DESTINATION, --destination DESTINATION - Directory to create new library in (default: .) - --m META, --metastable META - How to interpret ZAIDs for metastable nuclides. META - can be either 'nndc' or 'mcnp'. (default: nndc) - ---xml XML Old-style cross_sections.xml that lists ACE libraries - (default: None) - ---xsdir XSDIR MCNP xsdir file that lists ACE libraries (default: - None) - ---xsdata XSDATA Serpent xsdata file that lists ACE libraries (default: - None) - ---fission_energy_release FISSION_ENERGY_RELEASE - HDF5 file containing fission energy release data - (default: None) - - Using Multi-Group Cross Sections -------------------------------- diff --git a/docs/source/usersguide/scripts.rst b/docs/source/usersguide/scripts.rst index d1c37fa167..b7cc1e9fc7 100644 --- a/docs/source/usersguide/scripts.rst +++ b/docs/source/usersguide/scripts.rst @@ -45,46 +45,182 @@ flags: -v, --version Show version information -h, --help Show help message +.. _scripts_ace: + ---------------------- ``openmc-ace-to-hdf5`` ---------------------- +This script can be used to create HDF5 nuclear data libraries used by OpenMC if +you have existing ACE files. There are four different ways you can specify ACE +libraries that are to be converted: + +1. List each ACE library as a positional argument. This is very useful in + conjunction with the usual shell utilities (ls, find, etc.). +2. Use the ``--xml`` option to specify a pre-v0.9 cross_sections.xml file. +3. Use the ``--xsdir`` option to specify a MCNP xsdir file. +4. Use the ``--xsdata`` option to specify a Serpent xsdata file. + +The script does not use any extra information from cross_sections.xml/ xsdir/ +xsdata files to determine whether the nuclide is metastable. Instead, the +``--metastable`` argument can be used to specify whether the ZAID naming convention +follows the NNDC data convention (1000*Z + A + 300 + 100*m), or the MCNP data +convention (essentially the same as NNDC, except that the first metastable state +of Am242 is 95242 and the ground state is 95642). + +The optional ``--fission_energy_release`` argument will accept an HDF5 file +containing a library of fission energy release (ENDF MF=1 MT=458) data. A +library built from ENDF/B-VII.1 data is released with OpenMC and can be found at +openmc/data/fission_Q_data_endb71.h5. This data is necessary for +'fission-q-prompt' and 'fission-q-recoverable' tallies, but is not needed +otherwise. + +-h, --help show help message and exit + +-d DESTINATION, --destination DESTINATION + Directory to create new library in (default: .) + +-m META, --metastable META + How to interpret ZAIDs for metastable nuclides. META + can be either 'nndc' or 'mcnp'. (default: nndc) + +--xml XML Old-style cross_sections.xml that lists ACE libraries + +--xsdir XSDIR MCNP xsdir file that lists ACE libraries + +--xsdata XSDATA Serpent xsdata file that lists ACE libraries + +--fission_energy_release FISSION_ENERGY_RELEASE + HDF5 file containing fission energy release data + +.. _scripts_mcnp70: + ------------------------------ ``openmc-convert-mcnp70-data`` ------------------------------ +This script converts ENDF/B-VII.0 ACE data from the MCNP5/6 distribution into an +HDF5 library that can be used by OpenMC. This assumes that you have a directory +containing files named endf70a, endf70b, ..., endf70k, and endf70sab. The path +to the directory containing these files should be given as a positional +argument. The following optional arguments are available: + +-d DESTINATION, --destination DESTINATION + Directory to create new library in (Default: mcnp_endfb70) + +.. _scripts_mcnp71: + ------------------------------ ``openmc-convert-mcnp71-data`` ------------------------------ +This script converts ENDF/B-VII.1 ACE data from the MCNP6 distribution into an +HDF5 library that can be used by OpenMC. This assumes that you have a directory +containing subdirectories 'endf71x' and 'ENDF71SaB'. The path to the directory +containing these subdirectories should be given as a positional argument. The +following optional arguments are available: + +-d DESTINATION, --destination DESTINATION + Directory to create new library in (Default: mcnp_endfb71) + +-f FER, --fission_energy_release FER + HDF5 file containing fission energy release data + +.. _scripts_jeff: + ------------------------ ``openmc-get-jeff-data`` ------------------------ +This script downloads `JEFF 3.2 ACE data +`_ from OECD/NEA +and converts it to a multi-temperature HDF5 library for use with OpenMC. It has +the following optional arguments: + +-b, --batch + Suppress standard in + +-d DESTINATION, --destination DESTINATION + Directory to create new library in (default: jeff-3.2-hdf5) + +.. warning:: This script will download approximately 9 GB of data. Extracting + and processing the data may require as much as 40 GB of additional + free disk space. + ----------------------------- ``openmc-get-multipole-data`` ----------------------------- +This script downloads and extracts windowed multipole data based on +ENDF/B-VII.1. It has the following optional arguments: + +-b, --batch Suppress standard in + +.. _scripts_nndc: + ------------------------ ``openmc-get-nndc-data`` ------------------------ +This script downloads `ENDF/B-VII.1 ACE data +`_ from NNDC and converts it to +an HDF5 library for use with OpenMC. This data is used for OpenMC's regression +test suite. This script has the following optional arguments: + +-b, --batch Suppress standard in + -------------------------- ``openmc-plot-mesh-tally`` -------------------------- +``openmc-plot-mesh-tally`` provides a graphical user interface for plotting mesh +tallies. The path to the statepoint file can be provided as an optional arugment +(if omitted, a file dialog will be presented). + ----------------------- ``openmc-track-to-vtk`` ----------------------- +This script converts HDF5 particle track files to VTK poly data that can be +viewed with ParaView or VisIt. 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 VTK poly filename + ------------------------ ``openmc-update-inputs`` ------------------------ +If you have existing XML files that worked in a previous version of OpenMC that +no longer work with the current version, you can try to update these files using +``openmc-update-inputs``. If any of the given files do not match the most +up-to-date formatting, then they will be automatically rewritten. The old +out-of-date files will not be deleted; they will be moved to a new file with +'.original' appended to their name. + +Formatting changes that will be made: + +geometry.xml + Lattices containing 'outside' attributes/tags will be replaced with lattices + containing 'outer' attributes, and the appropriate cells/universes will be + added. Any 'surfaces' attributes/elements on a cell will be renamed 'region'. + +materials.xml + Nuclide names will be changed from ACE aliases (e.g., Am-242m) to HDF5/GND + names (e.g., Am242_m1). Thermal scattering table names will be changed from + ACE aliases (e.g., HH2O) to HDF5/GND names (e.g., c_H_in_H2O). + ---------------------- ``openmc-update-mgxs`` ---------------------- +This script updates OpenMC's deprecated multi-group cross section XML files to +the latest HDF5-based format. + +-i IN, --input IN Input XML file +-o OUT, --output OUT Output file in HDF5 format + .. _scripts_validate: ----------------------- diff --git a/scripts/openmc-get-nndc-data b/scripts/openmc-get-nndc-data index 92beaf9888..f1da2241ab 100755 --- a/scripts/openmc-get-nndc-data +++ b/scripts/openmc-get-nndc-data @@ -18,7 +18,7 @@ import openmc.data description = """ Download ENDF/B-VII.1 ACE data from NNDC and convert it to an HDF5 library for -use with OpenMC. +use with OpenMC. This data is used for OpenMC's regression test suite. """ diff --git a/scripts/openmc-plot-mesh-tally b/scripts/openmc-plot-mesh-tally index cf17fabe9a..c273a6d592 100755 --- a/scripts/openmc-plot-mesh-tally +++ b/scripts/openmc-plot-mesh-tally @@ -4,6 +4,7 @@ import os import sys +import argparse import six.moves.tkinter as tk import six.moves.tkinter_filedialog as filedialog @@ -16,17 +17,17 @@ from matplotlib.figure import Figure import matplotlib.pyplot as plt import numpy as np -from openmc.statepoint import StatePoint +from openmc import StatePoint, MeshFilter class MeshPlotter(tk.Frame): def __init__(self, parent, filename): tk.Frame.__init__(self, parent) - self.labels = {'cell': 'Cell:', 'cellborn': 'Cell born:', - 'surface': 'Surface:', 'material': 'Material:', - 'universe': 'Universe:', 'energy': 'Energy in:', - 'energyout': 'Energy out:'} + self.labels = {'Cell': 'Cell:', 'Cellborn': 'Cell born:', + 'Surface': 'Surface:', 'Material': 'Material:', + 'Universe': 'Universe:', 'Energy': 'Energy in:', + 'Energyout': 'Energy out:'} self.filterBoxes = {} @@ -122,7 +123,7 @@ class MeshPlotter(tk.Frame): selectedTally = self.datafile.tallies[tally_id] # Get mesh for selected tally - self.mesh = selectedTally.filters_by_name['mesh'].mesh + self.mesh = selectedTally.find_filter(MeshFilter).mesh # Get mesh dimensions if len(self.mesh.dimension) == 2: @@ -160,8 +161,8 @@ class MeshPlotter(tk.Frame): # create a label/combobox for each filter in selected tally count = 0 for f in selectedTally.filters: - filterType = f.type - if filterType == 'mesh': + filterType = f.short_name + if filterType == 'Mesh': continue count += 1 @@ -172,7 +173,7 @@ class MeshPlotter(tk.Frame): self.filterBoxes[filterType] = combobox # Set combobox items - if filterType in ['energy', 'energyout']: + if filterType in ['Energy', 'Energyout']: combobox['values'] = ['{0} to {1}'.format(*f.bins[i:i+2]) for i in range(len(f.bins) - 1)] else: @@ -202,16 +203,16 @@ class MeshPlotter(tk.Frame): # Create spec_list spec_list = [] for f in selectedTally.filters: - if f.type == 'mesh': + if f.short_name == 'Mesh': mesh_filter = f continue - elif f.type in ['energy', 'energyout']: - index = self.filterBoxes[f.type].current() + elif f.short_name in ['Energy', 'Energyout']: + index = self.filterBoxes[f.short_name].current() ebin = (f.bins[index], f.bins[index + 1]) - spec_list.append((f.type, (ebin,))) + spec_list.append((type(f), (ebin,))) else: - index = self.filterBoxes[f.type].current() - spec_list.append((f.type, (index,))) + index = self.filterBoxes[f.short_name].current() + spec_list.append((type(f), (index,))) text = self.basisBox.get() if text == 'xy': @@ -230,7 +231,7 @@ class MeshPlotter(tk.Frame): else: meshtuple = (i + 1, axial_level, j + 1) filters, filter_bins = zip(*spec_list + [ - (mesh_filter.type, (meshtuple,))]) + (type(mesh_filter), (meshtuple,))]) mean = selectedTally.get_values( [self.scoreBox.get()], filters, filter_bins) stdev = selectedTally.get_values( @@ -268,10 +269,9 @@ class MeshPlotter(tk.Frame): # Find which tallies are mesh tallies self.meshTallies = [] - for itally, tally in self.datafile.tallies.iteritems(): - if any([f.type == 'mesh' for f in tally.filters]): + for itally, tally in self.datafile.tallies.items(): + if any([isinstance(f, MeshFilter) for f in tally.filters]): self.meshTallies.append(itally) - tally.filters_by_name = {f.type: f for f in tally.filters} if not self.meshTallies: messagebox.showerror("Invalid StatePoint File", @@ -280,16 +280,20 @@ class MeshPlotter(tk.Frame): if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('statepoint', nargs='?', help='Statepoint file') + args = parser.parse_args() + # Hide root window root = tk.Tk() root.withdraw() # If no filename given as command-line argument, open file dialog - if len(sys.argv) < 2: + if args.statepoint is None: filename = filedialog.askopenfilename(title='Select statepoint file', initialdir='.') else: - filename = sys.argv[1] + filename = args.statepoint if filename: # Check to make sure file exists diff --git a/scripts/openmc-track-to-vtk b/scripts/openmc-track-to-vtk index e22a22dea3..d190ac662f 100755 --- a/scripts/openmc-track-to-vtk +++ b/scripts/openmc-track-to-vtk @@ -1,25 +1,14 @@ #!/usr/bin/env python -"""Convert binary particle track to VTK poly data. -Usage information can be obtained by running 'track.py --help': - - usage: track.py [-h] [-o OUT] IN [IN ...] - - Convert particle track file to a .pvtp file. - - positional arguments: - IN Input particle track data filename(s). - - optional arguments: - -h, --help show this help message and exit - -o OUT, --out OUT Output VTK poly data filename. +"""Convert HDF5 particle track to VTK poly data. """ import os import argparse -import h5py import struct + +import h5py import vtk diff --git a/scripts/openmc-update-inputs b/scripts/openmc-update-inputs index 586e7b6dc7..72aee9c0fa 100755 --- a/scripts/openmc-update-inputs +++ b/scripts/openmc-update-inputs @@ -1,22 +1,6 @@ #!/usr/bin/env python """Update OpenMC's input XML files to the latest format. -Usage information can be obtained by running 'openmc-update-inputs --help': - -usage: openmc-update-inputs [-h] IN [IN ...] - -Update geometry.xml files to the latest format. This will remove 'outside' -attributes/elements from lattices and replace them with 'outer' attributes. For -'cell' elements, any 'surfaces' attributes/elements will be renamed -'region'. Note that this script will not delete the given files; it will append -'.original' to the given files and write new ones. - -positional arguments: - IN Input geometry.xml file(s). - -optional arguments: - -h, --help show this help message and exit - """ from __future__ import print_function @@ -59,7 +43,7 @@ def parse_args(): epilog=epilog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('input', metavar='IN', type=str, nargs='+', - help='Input geometry.xml file(s).') + help='Input XML file(s).') # Parse and return commandline arguments. return parser.parse_args() @@ -68,20 +52,21 @@ def parse_args(): def get_universe_ids(geometry_root): """Return a set of universe id numbers.""" root = geometry_root - out = {0} + out = set() # Get the ids of universes defined by cells. for cell in root.iter('cell'): - # Get universe attributes. + # Get universe attributes/elements if 'universe' in cell.attrib: uid = cell.attrib['universe'] out.add(int(uid)) - - # Get universe elements. elif cell.find('universe') is not None: elem = cell.find('universe') uid = elem.text out.add(int(uid)) + else: + # Default to universe 0 + out.add(0) # Get the ids of universes defined by lattices. for lat in root.iter('lattice'): diff --git a/scripts/openmc-update-mgxs b/scripts/openmc-update-mgxs index 54a553f77a..f33adfc005 100755 --- a/scripts/openmc-update-mgxs +++ b/scripts/openmc-update-mgxs @@ -2,23 +2,6 @@ """Update OpenMC's deprecated multi-group cross section XML files to the latest HDF5-based format. -Usage information can be obtained by running 'openmc-update-mgxs --help': - -usage: openmc-update-mgxs [-h] in out - -Update mgxs.xml files to the latest format. This will remove 'outside' -attributes/elements from lattices and replace them with 'outer' attributes. For -'cell' elements, any 'surfaces' attributes/elements will be renamed -'region'. Note that this script will not delete the given files; it will append -'.original' to the given files and write new ones. - -positional arguments: - in Input mgxs xml file - out Output mgxs hdf5 file - -optional arguments: - -h, --help show this help message and exit - """ from __future__ import print_function