From cc98d13793a7dd1fac4d42a260bd49403889becc Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 30 May 2019 17:55:09 -0400 Subject: [PATCH] Read chain file for deplete.Operator from OPENMC_CROSS_SECTIONS If a chain_file is not passed when initializing an openmc.deplete.Operator object, then the chain_file will be read from the depletion_chain node from $OPENMC_CROSS_SECTIONS. A deprecation warning is raised if the environment variable OPENMC_DEPLETE_CHAIN is still set, informing the users that this information can instead be placed in their cross section file. Documentation is updated describing the logic in the chain_file search to reflect this in - TransportOperator - Operator - Chain . Closes #1239 --- openmc/deplete/abc.py | 26 ++++++++++++++++++++++---- openmc/deplete/chain.py | 3 ++- openmc/deplete/operator.py | 5 +++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index 8502909a21..14dd3638ce 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -8,6 +8,8 @@ from collections import namedtuple import os from pathlib import Path from abc import ABCMeta, abstractmethod +from xml.etree import ElementTree as ET +from warnings import warn from .chain import Chain @@ -43,8 +45,9 @@ class TransportOperator(metaclass=ABCMeta): Parameters ---------- chain_file : str, optional - Path to the depletion chain XML file. Defaults to the - :envvar:`OPENMC_DEPLETE_CHAIN` environment variable if it exists. + Path to the depletion chain XML file. Defaults to the file + listed under ``depletion_chain`` in + :envvar:`OPENMC_CROSS_SECTIONS` environment variable. Attributes ---------- @@ -62,8 +65,23 @@ class TransportOperator(metaclass=ABCMeta): if chain_file is None: chain_file = os.environ.get("OPENMC_DEPLETE_CHAIN", None) if chain_file is None: - raise IOError("No chain specified, either manually or in " - "environment variable OPENMC_DEPLETE_CHAIN.") + xs_file = os.environ.get("OPENMC_CROSS_SECTIONS", None) + if xs_file is None: + raise IOError( + "OPENMC_CROSS_SECTIONS environment variable " + "not set.") + root = ET.parse(xs_file).getroot() + node = root.find("depletion_chain") + if node is None: + raise IOError( + "No chain specified, either manually or " + "under depletion_chain in environment variable " + "OPENMC_CROSS_SECTIONS.") + chain_file = node.get("path") + else: + warn("Use of OPENMC_DEPLETE_CHAIN is deprecated in favor " + "of adding depletion_chain to OPENMC_CROSS_SECTIONS", + DeprecationWarning) self.chain = Chain.from_xml(chain_file) @abstractmethod diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 4635d99d15..b8b6a3644a 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -107,7 +107,8 @@ class Chain(object): yield sublibrary files. The depletion chain used during a depletion simulation is indicated by either an argument to :class:`openmc.deplete.Operator` or through the - :envvar:`OPENMC_DEPLETE_CHAIN` environment variable. + ``depletion_chain`` item in the :envvar:`OPENMC_CROSS_SECTIONS` + environment variable. Attributes ---------- diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index 66cac392d9..d284d98567 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -64,8 +64,9 @@ class Operator(TransportOperator): settings : openmc.Settings OpenMC Settings object chain_file : str, optional - Path to the depletion chain XML file. Defaults to the - :envvar:`OPENMC_DEPLETE_CHAIN` environment variable if it exists. + Path to the depletion chain XML file. Defaults to the file + listed under ``depletion_chain`` in + :envvar:`OPENMC_CROSS_SECTIONS` environment variable. prev_results : ResultsList, optional Results from a previous depletion calculation. If this argument is specified, the depletion calculation will start from the latest state