|
17 | 17 | import lxml.etree as ET |
18 | 18 | import scipy.sparse as sp |
19 | 19 |
|
20 | | -from openmc.checkvalue import check_type, check_greater_than |
| 20 | +from openmc.checkvalue import check_type, check_greater_than, PathLike |
21 | 21 | from openmc.data import gnds_name, zam |
| 22 | +from openmc.exceptions import DataError |
22 | 23 | from .nuclide import FissionYieldDistribution, Nuclide |
23 | 24 | import openmc.data |
24 | 25 |
|
@@ -1246,3 +1247,38 @@ def _follow(self, isotopes, level): |
1246 | 1247 | found.update(isotopes) |
1247 | 1248 |
|
1248 | 1249 | return found |
| 1250 | + |
| 1251 | + |
| 1252 | +def _get_chain( |
| 1253 | + chain_file: PathLike | Chain | None = None, |
| 1254 | + fission_q: dict | None = None |
| 1255 | +) -> Chain: |
| 1256 | + """Get a depletion chain from a file or the runtime configuration. |
| 1257 | +
|
| 1258 | + Parameters |
| 1259 | + ---------- |
| 1260 | + chain_file : PathLike or Chain, optional |
| 1261 | + Path to depletion chain XML file, a Chain instance, or None to use |
| 1262 | + the file specified in ``openmc.config['chain_file']``. |
| 1263 | + fission_q : dict, optional |
| 1264 | + Dictionary of nuclides and their fission Q values [eV]. If not given, |
| 1265 | + values will be pulled from the ``chain_file``. |
| 1266 | +
|
| 1267 | + Returns |
| 1268 | + ------- |
| 1269 | + Chain |
| 1270 | + Depletion chain instance. |
| 1271 | + """ |
| 1272 | + if isinstance(chain_file, Chain): |
| 1273 | + return chain_file |
| 1274 | + elif isinstance(chain_file, PathLike | None): |
| 1275 | + if chain_file is None: |
| 1276 | + chain_file = openmc.config.get('chain_file') |
| 1277 | + if 'chain_file' not in openmc.config: |
| 1278 | + raise DataError( |
| 1279 | + "No depletion chain specified and could not find depletion " |
| 1280 | + "chain in openmc.config['chain_file']" |
| 1281 | + ) |
| 1282 | + return Chain.from_xml(chain_file, fission_q) |
| 1283 | + else: |
| 1284 | + raise TypeError("chain_file must be path-like, a Chain, or None") |
0 commit comments