Add mg_cross_sections to openmc.config

This commit is contained in:
Paul Romano 2022-08-31 22:23:29 -05:00
parent a074e0a5cf
commit 225e40db0c
3 changed files with 19 additions and 14 deletions

View file

@ -21,6 +21,9 @@ class _Config(MutableMapping):
# Force environment variable to match
self._mapping[key] = Path(value)
os.environ['OPENMC_CROSS_SECTIONS'] = str(value)
elif key == 'mg_cross_sections':
self._mapping[key] = Path(value)
os.environ['OPENMC_MG_CROSS_SECTIONS'] = str(value)
elif key == 'chain_file':
self._mapping[key] = Path(value)
else:
@ -40,7 +43,10 @@ class _Config(MutableMapping):
config = _Config()
# Set cross sections using environment variable
config['cross_sections'] = os.environ.get("OPENMC_CROSS_SECTIONS")
if "OPENMC_CROSS_SECTIONS" in os.environ:
config['cross_sections'] = os.environ["OPENMC_CROSS_SECTIONS"]
if "OPENMC_MG_CROSS_SECTIONS" in os.environ:
config['mg_cross_sections'] = os.environ["OPENMC_MG_CROSS_SECTIONS"]
# Check for depletion chain in cross_sections.xml
# Set depletion chain
@ -51,4 +57,5 @@ if chain_file is None and config['cross_sections'] is not None:
if lib['type'] == 'depletion_chain':
chain_file = lib['path']
break
config['chain_file'] = chain_file
if chain_file is not None:
config['chain_file'] = chain_file

View file

@ -1329,10 +1329,11 @@ class Materials(cv.CheckedList):
----------
cross_sections : str or path-like
Indicates the path to an XML cross section listing file (usually named
cross_sections.xml). If it is not set, openmc.config['cross_sections']
will be used for continuous-energy calculations and
:envvar:`OPENMC_MG_CROSS_SECTIONS` will be used for multi-group
calculations to find the path to the HDF5 cross section file.
cross_sections.xml). If it is not set, the
:envvar:`OPENMC_CROSS_SECTIONS` environment variable will be used for
continuous-energy calculations and :envvar:`OPENMC_MG_CROSS_SECTIONS`
will be used for multi-group calculations to find the path to the HDF5
cross section file.
"""

View file

@ -1,6 +1,5 @@
import copy
from numbers import Real, Integral
import os
import h5py
import numpy as np
@ -2536,8 +2535,7 @@ class MGXSLibrary:
----------
filename : str, optional
Name of HDF5 file containing MGXS data. Default is None.
If not provided, the value of the OPENMC_MG_CROSS_SECTIONS
environmental variable will be used
If not provided, openmc.config['mg_cross_sections'] will be used.
Returns
-------
@ -2545,15 +2543,14 @@ class MGXSLibrary:
Multi-group cross section data object.
"""
# If filename is None, get the cross sections from the
# OPENMC_MG_CROSS_SECTIONS environment variable
# If filename is None, get the cross sections from openmc.config
if filename is None:
filename = os.environ.get('OPENMC_MG_CROSS_SECTIONS')
filename = openmc.config.get('mg_cross_sections')
# Check to make sure there was an environmental variable.
if filename is None:
raise ValueError("Either path or OPENMC_MG_CROSS_SECTIONS "
"environmental variable must be set")
raise ValueError("Either path or openmc.config['mg_cross_sections']"
"must be set")
check_type('filename', filename, str)
file = h5py.File(filename, 'r')