From eac4092362545db994f0653eaea134afcf864dbf Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 1 Aug 2022 09:35:30 -0500 Subject: [PATCH] address @paulromano's fourth round of comments - syntax fixes - remove `units` argument from MicroXS.from_csv and MicroXS.from_array - make Operator warning display only when users call Operator --- openmc/deplete/abc.py | 4 ++-- openmc/deplete/coupled_operator.py | 18 ++++++++++-------- openmc/deplete/microxs.py | 29 ++++++++++++----------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index e874479c0..8439fab34 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -529,8 +529,8 @@ class Integrator(ABC): initial heavy metal inventory to get total power if ``power`` is not specified. source_rates : float or iterable of float, optional - Source rate in [neutron/sec] or neutron flux in [neut/cm^2-s] for each - interval in :attr:`timesteps` + Source rate in [neutron/sec] or neutron flux in [neutron/s-cm^2] for + each interval in :attr:`timesteps` .. versionadded:: 0.12.1 timestep_units : {'s', 'min', 'h', 'd', 'MWd/kg'} diff --git a/openmc/deplete/coupled_operator.py b/openmc/deplete/coupled_operator.py index 39e46c882..2e457f4d7 100644 --- a/openmc/deplete/coupled_operator.py +++ b/openmc/deplete/coupled_operator.py @@ -192,13 +192,7 @@ class CoupledOperator(OpenMCOperator): fission_yield_mode="constant", fission_yield_opts=None, reaction_rate_mode="direct", reaction_rate_opts=None, reduce_chain=False, reduce_chain_level=None): - # warn of name change - warn( - "The Operator(...) class has been renamed and will " - "be removed in a future version of OpenMC. Use " - "CoupledOperator(...) instead.", - FutureWarning - ) + # check for old call to constructor if isinstance(model, openmc.Geometry): msg = "As of version 0.13.0 openmc.deplete.CoupledOperator " \ @@ -526,4 +520,12 @@ class CoupledOperator(OpenMCOperator): openmc.lib.finalize() # Retain deprecated name for the time being -Operator = CoupledOperator +def Operator(**args, **kwargs): + # warn of name change + warn( + "The Operator(...) class has been renamed and will " + "be removed in a future version of OpenMC. Use " + "CoupledOperator(...) instead.", + FutureWarning + ) + return CoupledOperator(*args, **kwargs) diff --git a/openmc/deplete/microxs.py b/openmc/deplete/microxs.py index 6abf8836f..68255d18a 100644 --- a/openmc/deplete/microxs.py +++ b/openmc/deplete/microxs.py @@ -6,7 +6,6 @@ nuclides names as row indices and reaction names as column indices. import tempfile from pathlib import Path -from os import chdir from pandas import DataFrame, read_csv, concat from numpy import ndarray @@ -54,7 +53,8 @@ class MicroXS(DataFrame): Returns ------- - MicroXS, cross section data in [b] + MicroXS + Cross section data in [b] """ groups = EnergyGroups(energy_bounds) @@ -73,15 +73,12 @@ class MicroXS(DataFrame): model.tallies = tallies # create temporary run - original_dir = Path.cwd() - temp_dir = tempfile.TemporaryDirectory() - chdir(tempfile.gettempdir()) - statepoint_path = model.run() - chdir(original_dir) + with tempfile.TemporaryDirectory() as temp_dir: + statepoint_path = model.run(cwd=temp_dir) - with StatePoint(statepoint_path) as sp: - for rxn in xs: - xs[rxn].load_from_statepoint(sp) + with StatePoint(statepoint_path) as sp: + for rxn in xs: + xs[rxn].load_from_statepoint(sp) # Build the DataFrame micro_xs = cls() @@ -89,7 +86,7 @@ class MicroXS(DataFrame): df = xs[rxn].get_pandas_dataframe(xs_type='micro') df.index = df['nuclide'] df.drop(['nuclide', xs[rxn].domain_type, 'group in', 'std. dev.'], axis=1, inplace=True) - df.rename({'mean':rxn}, axis=1, inplace=True) + df.rename({'mean': rxn}, axis=1, inplace=True) micro_xs = concat([micro_xs, df], axis=1) micro_xs._units = 'b' @@ -100,7 +97,7 @@ class MicroXS(DataFrame): return micro_xs @classmethod - def from_array(cls, nuclides, reactions, data, units='b'): + def from_array(cls, nuclides, reactions, data): """ Creates a ``MicroXS`` object from arrays. @@ -115,8 +112,6 @@ class MicroXS(DataFrame): data : ndarray of floats Array containing one-group microscopic cross section values for each nuclide and reaction - units : {'b', 'cm^2'} - Units of the cross section values in ``data`` Returns ------- @@ -133,12 +128,12 @@ class MicroXS(DataFrame): cls._validate_micro_xs_inputs( nuclides, reactions, data) micro_xs = cls(index=nuclides, columns=reactions, data=data) - micro_xs._units = units + micro_xs._units = 'b' return micro_xs @classmethod - def from_csv(cls, csv_file, units='b', **kwargs): + def from_csv(cls, csv_file, **kwargs): """ Load a ``MicroXS`` object from a ``.csv`` file. @@ -165,7 +160,7 @@ class MicroXS(DataFrame): cls._validate_micro_xs_inputs(list(micro_xs.index), list(micro_xs.columns), micro_xs.to_numpy()) - micro_xs._units = units + micro_xs._units = 'b' return micro_xs