diff --git a/openmc/config.py b/openmc/config.py index a883c74cc..65b7e0863 100644 --- a/openmc/config.py +++ b/openmc/config.py @@ -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 diff --git a/openmc/material.py b/openmc/material.py index 96a660b8b..1b2b46a73 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -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. """ diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index 8d6e4bec9..98a99196e 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -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')