From 97414699fdb67628fe0ef6e7af8a4dbf4f938fa5 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Jul 2023 14:48:36 -0500 Subject: [PATCH] Update variable names for depletion 'n' vectors (#2583) --- openmc/deplete/abc.py | 51 ++++---- openmc/deplete/integrators.py | 219 +++++++++++++++++----------------- openmc/deplete/pool.py | 55 +++++---- 3 files changed, 166 insertions(+), 159 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index ae0d86027..1acfe6b1a 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -683,21 +683,22 @@ class Integrator(ABC): self._solver = func - def _timed_deplete(self, concs, rates, dt, matrix_func=None): + def _timed_deplete(self, n, rates, dt, matrix_func=None): start = time.time() results = deplete( - self._solver, self.chain, concs, rates, dt, matrix_func, + self._solver, self.chain, n, rates, dt, matrix_func, self.transfer_rates) return time.time() - start, results @abstractmethod - def __call__(self, conc, rates, dt, source_rate, i): + def __call__(self, n, rates, dt, source_rate, i): """Perform the integration across one time step Parameters ---------- - conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -711,7 +712,7 @@ class Integrator(ABC): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -777,7 +778,7 @@ class Integrator(ABC): .. versionadded:: 0.13.1 """ with change_directory(self.operator.output_dir): - conc = self.operator.initial_condition() + n = self.operator.initial_condition() t, self._i_res = self._get_start_data() for i, (dt, source_rate) in enumerate(self): @@ -786,21 +787,21 @@ class Integrator(ABC): # Solve transport equation (or obtain result from restart) if i > 0 or self.operator.prev_res is None: - conc, res = self._get_bos_data_from_operator(i, source_rate, conc) + n, res = self._get_bos_data_from_operator(i, source_rate, n) else: - conc, res = self._get_bos_data_from_restart(i, source_rate, conc) + n, res = self._get_bos_data_from_restart(i, source_rate, n) # Solve Bateman equations over time interval - proc_time, conc_list, res_list = self(conc, res.rates, dt, source_rate, i) + proc_time, n_list, res_list = self(n, res.rates, dt, source_rate, i) # Insert BOS concentration, transport results - conc_list.insert(0, conc) + n_list.insert(0, n) res_list.insert(0, res) # Remove actual EOS concentration for next step - conc = conc_list.pop() + n = n_list.pop() - StepResult.save(self.operator, conc_list, res_list, [t, t + dt], + StepResult.save(self.operator, n_list, res_list, [t, t + dt], source_rate, self._i_res + i, proc_time) t += dt @@ -811,8 +812,8 @@ class Integrator(ABC): # solve) if output and final_step and comm.rank == 0: print(f"[openmc.deplete] t={t} (final operator evaluation)") - res_list = [self.operator(conc, source_rate if final_step else 0.0)] - StepResult.save(self.operator, [conc], res_list, [t, t], + res_list = [self.operator(n, source_rate if final_step else 0.0)] + StepResult.save(self.operator, [n], res_list, [t, t], source_rate, self._i_res + len(self), proc_time) self.operator.write_bos_data(len(self) + self._i_res) @@ -942,13 +943,13 @@ class SIIntegrator(Integrator): timestep_units=timestep_units, solver=solver) self.n_steps = n_steps - def _get_bos_data_from_operator(self, step_index, step_power, bos_conc): + def _get_bos_data_from_operator(self, step_index, step_power, n_bos): reset_particles = False if step_index == 0 and hasattr(self.operator, "settings"): reset_particles = True self.operator.settings.particles *= self.n_steps inherited = super()._get_bos_data_from_operator( - step_index, step_power, bos_conc) + step_index, step_power, n_bos) if reset_particles: self.operator.settings.particles //= self.n_steps return inherited @@ -964,7 +965,7 @@ class SIIntegrator(Integrator): .. versionadded:: 0.13.1 """ with change_directory(self.operator.output_dir): - conc = self.operator.initial_condition() + n = self.operator.initial_condition() t, self._i_res = self._get_start_data() for i, (dt, p) in enumerate(self): @@ -973,30 +974,30 @@ class SIIntegrator(Integrator): if i == 0: if self.operator.prev_res is None: - conc, res = self._get_bos_data_from_operator(i, p, conc) + n, res = self._get_bos_data_from_operator(i, p, n) else: - conc, res = self._get_bos_data_from_restart(i, p, conc) + n, res = self._get_bos_data_from_restart(i, p, n) else: # Pull rates, k from previous iteration w/o # re-running transport res = res_list[-1] # defined in previous i iteration - proc_time, conc_list, res_list = self(conc, res.rates, dt, p, i) + proc_time, n_list, res_list = self(n, res.rates, dt, p, i) # Insert BOS concentration, transport results - conc_list.insert(0, conc) + n_list.insert(0, n) res_list.insert(0, res) # Remove actual EOS concentration for next step - conc = conc_list.pop() + n = n_list.pop() - StepResult.save(self.operator, conc_list, res_list, [t, t + dt], + StepResult.save(self.operator, n_list, res_list, [t, t + dt], p, self._i_res + i, proc_time) t += dt # No final simulation for SIE, use last iteration results - StepResult.save(self.operator, [conc], [res_list[-1]], [t, t], + StepResult.save(self.operator, [n], [res_list[-1]], [t, t], p, self._i_res + len(self), proc_time) self.operator.write_bos_data(self._i_res + len(self)) diff --git a/openmc/deplete/integrators.py b/openmc/deplete/integrators.py index 74a3cebdb..e73088621 100644 --- a/openmc/deplete/integrators.py +++ b/openmc/deplete/integrators.py @@ -26,13 +26,14 @@ class PredictorIntegrator(Integrator): """ _num_stages = 1 - def __call__(self, conc, rates, dt, source_rate, _i=None): + def __call__(self, n, rates, dt, source_rate, _i=None): """Perform the integration across one time step Parameters ---------- - conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -46,15 +47,15 @@ class PredictorIntegrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at end of interval op_results : empty list - Kept for consistency with API. No intermediate calls to - operator with predictor + Kept for consistency with API. No intermediate calls to operator + with predictor """ - proc_time, conc_end = self._timed_deplete(conc, rates, dt) - return proc_time, [conc_end], [] + proc_time, n_end = self._timed_deplete(n, rates, dt) + return proc_time, [n_end], [] @add_params @@ -77,13 +78,14 @@ class CECMIntegrator(Integrator): """ _num_stages = 2 - def __call__(self, conc, rates, dt, source_rate, _i=None): + def __call__(self, n, rates, dt, source_rate, _i=None): """Integrate using CE/CM Parameters ---------- - conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -97,21 +99,21 @@ class CECMIntegrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult Eigenvalue and reaction rates from transport simulations """ # deplete across first half of interval - time0, x_middle = self._timed_deplete(conc, rates, dt / 2) - res_middle = self.operator(x_middle, source_rate) + time0, n_middle = self._timed_deplete(n, rates, dt / 2) + res_middle = self.operator(n_middle, source_rate) # deplete across entire interval with BOS concentrations, # MOS reaction rates - time1, x_end = self._timed_deplete(conc, res_middle.rates, dt) + time1, n_end = self._timed_deplete(n, res_middle.rates, dt) - return time0 + time1, [x_middle, x_end], [res_middle] + return time0 + time1, [n_middle, n_end], [res_middle] @add_params @@ -140,13 +142,14 @@ class CF4Integrator(Integrator): """ _num_stages = 4 - def __call__(self, bos_conc, bos_rates, dt, source_rate, _i=None): + def __call__(self, n_bos, bos_rates, dt, source_rate, _i=None): """Perform the integration across one time step Parameters ---------- - bos_conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n_bos : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. bos_rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -160,7 +163,7 @@ class CF4Integrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -168,30 +171,30 @@ class CF4Integrator(Integrator): simulations """ # Step 1: deplete with matrix 1/2*A(y0) - time1, conc_eos1 = self._timed_deplete( - bos_conc, bos_rates, dt, matrix_func=cf4_f1) - res1 = self.operator(conc_eos1, source_rate) + time1, n_eos1 = self._timed_deplete( + n_bos, bos_rates, dt, matrix_func=cf4_f1) + res1 = self.operator(n_eos1, source_rate) # Step 2: deplete with matrix 1/2*A(y1) - time2, conc_eos2 = self._timed_deplete( - bos_conc, res1.rates, dt, matrix_func=cf4_f1) - res2 = self.operator(conc_eos2, source_rate) + time2, n_eos2 = self._timed_deplete( + n_bos, res1.rates, dt, matrix_func=cf4_f1) + res2 = self.operator(n_eos2, source_rate) # Step 3: deplete with matrix -1/2*A(y0)+A(y2) list_rates = list(zip(bos_rates, res2.rates)) - time3, conc_eos3 = self._timed_deplete( - conc_eos1, list_rates, dt, matrix_func=cf4_f2) - res3 = self.operator(conc_eos3, source_rate) + time3, n_eos3 = self._timed_deplete( + n_eos1, list_rates, dt, matrix_func=cf4_f2) + res3 = self.operator(n_eos3, source_rate) # Step 4: deplete with two matrix exponentials list_rates = list(zip(bos_rates, res1.rates, res2.rates, res3.rates)) - time4, conc_inter = self._timed_deplete( - bos_conc, list_rates, dt, matrix_func=cf4_f3) - time5, conc_eos5 = self._timed_deplete( - conc_inter, list_rates, dt, matrix_func=cf4_f4) + time4, n_inter = self._timed_deplete( + n_bos, list_rates, dt, matrix_func=cf4_f3) + time5, n_eos5 = self._timed_deplete( + n_inter, list_rates, dt, matrix_func=cf4_f4) return (time1 + time2 + time3 + time4 + time5, - [conc_eos1, conc_eos2, conc_eos3, conc_eos5], + [n_eos1, n_eos2, n_eos3, n_eos5], [res1, res2, res3]) @@ -217,13 +220,14 @@ class CELIIntegrator(Integrator): """ _num_stages = 2 - def __call__(self, bos_conc, rates, dt, source_rate, _i=None): + def __call__(self, n_bos, rates, dt, source_rate, _i=None): """Perform the integration across one time step Parameters ---------- - bos_conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n_bos : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -237,7 +241,7 @@ class CELIIntegrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -245,19 +249,19 @@ class CELIIntegrator(Integrator): simulation """ # deplete to end using BOS rates - proc_time, conc_ce = self._timed_deplete(bos_conc, rates, dt) - res_ce = self.operator(conc_ce, source_rate) + proc_time, n_ce = self._timed_deplete(n_bos, rates, dt) + res_ce = self.operator(n_ce, source_rate) # deplete using two matrix exponentials list_rates = list(zip(rates, res_ce.rates)) - time_le1, conc_inter = self._timed_deplete( - bos_conc, list_rates, dt, matrix_func=celi_f1) + time_le1, n_inter = self._timed_deplete( + n_bos, list_rates, dt, matrix_func=celi_f1) - time_le2, conc_end = self._timed_deplete( - conc_inter, list_rates, dt, matrix_func=celi_f2) + time_le2, n_end = self._timed_deplete( + n_inter, list_rates, dt, matrix_func=celi_f2) - return proc_time + time_le1 + time_le1, [conc_ce, conc_end], [res_ce] + return proc_time + time_le1 + time_le1, [n_ce, n_end], [res_ce] @add_params @@ -282,13 +286,14 @@ class EPCRK4Integrator(Integrator): """ _num_stages = 4 - def __call__(self, conc, rates, dt, source_rate, _i=None): + def __call__(self, n, rates, dt, source_rate, _i=None): """Perform the integration across one time step Parameters ---------- - conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] + n : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -302,7 +307,7 @@ class EPCRK4Integrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -311,26 +316,22 @@ class EPCRK4Integrator(Integrator): """ # Step 1: deplete with matrix A(y0) / 2 - time1, conc1 = self._timed_deplete( - conc, rates, dt, matrix_func=rk4_f1) - res1 = self.operator(conc1, source_rate) + time1, n1 = self._timed_deplete(n, rates, dt, matrix_func=rk4_f1) + res1 = self.operator(n1, source_rate) # Step 2: deplete with matrix A(y1) / 2 - time2, conc2 = self._timed_deplete( - conc, res1.rates, dt, matrix_func=rk4_f1) - res2 = self.operator(conc2, source_rate) + time2, n2 = self._timed_deplete(n, res1.rates, dt, matrix_func=rk4_f1) + res2 = self.operator(n2, source_rate) # Step 3: deplete with matrix A(y2) - time3, conc3 = self._timed_deplete(conc, res2.rates, dt) - res3 = self.operator(conc3, source_rate) + time3, n3 = self._timed_deplete(n, res2.rates, dt) + res3 = self.operator(n3, source_rate) # Step 4: deplete with matrix built from weighted rates list_rates = list(zip(rates, res1.rates, res2.rates, res3.rates)) - time4, conc4 = self._timed_deplete( - conc, list_rates, dt, matrix_func=rk4_f4) + time4, n4 = self._timed_deplete(n, list_rates, dt, matrix_func=rk4_f4) - return (time1 + time2 + time3 + time4, [conc1, conc2, conc3, conc4], - [res1, res2, res3]) + return (time1 + time2 + time3 + time4, [n1, n2, n3, n4], [res1, res2, res3]) @add_params @@ -368,14 +369,15 @@ class LEQIIntegrator(Integrator): """ _num_stages = 2 - def __call__(self, bos_conc, bos_rates, dt, source_rate, i): + def __call__(self, n_bos, bos_rates, dt, source_rate, i): """Perform the integration across one time step Parameters ---------- - conc : numpy.ndarray - Initial concentrations for all nuclides in [atom] - rates : openmc.deplete.ReactionRates + n_bos : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. + bos_rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float Time in [s] for the entire depletion interval @@ -388,7 +390,7 @@ class LEQIIntegrator(Integrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -399,7 +401,7 @@ class LEQIIntegrator(Integrator): if self._i_res < 1: # need at least previous transport solution self._prev_rates = bos_rates return CELIIntegrator.__call__( - self, bos_conc, bos_rates, dt, source_rate, i) + self, n_bos, bos_rates, dt, source_rate, i) prev_res = self.operator.prev_res[-2] prev_dt = self.timesteps[i] - prev_res.time[0] self._prev_rates = prev_res.rates[0] @@ -407,32 +409,32 @@ class LEQIIntegrator(Integrator): prev_dt = self.timesteps[i - 1] # Remaining LE/QI - bos_res = self.operator(bos_conc, source_rate) + bos_res = self.operator(n_bos, source_rate) le_inputs = list(zip( self._prev_rates, bos_res.rates, repeat(prev_dt), repeat(dt))) - time1, conc_inter = self._timed_deplete( - bos_conc, le_inputs, dt, matrix_func=leqi_f1) - time2, conc_eos0 = self._timed_deplete( - conc_inter, le_inputs, dt, matrix_func=leqi_f2) + time1, n_inter = self._timed_deplete( + n_bos, le_inputs, dt, matrix_func=leqi_f1) + time2, n_eos0 = self._timed_deplete( + n_inter, le_inputs, dt, matrix_func=leqi_f2) - res_inter = self.operator(conc_eos0, source_rate) + res_inter = self.operator(n_eos0, source_rate) qi_inputs = list(zip( self._prev_rates, bos_res.rates, res_inter.rates, repeat(prev_dt), repeat(dt))) - time3, conc_inter = self._timed_deplete( - bos_conc, qi_inputs, dt, matrix_func=leqi_f3) - time4, conc_eos1 = self._timed_deplete( - conc_inter, qi_inputs, dt, matrix_func=leqi_f4) + time3, n_inter = self._timed_deplete( + n_bos, qi_inputs, dt, matrix_func=leqi_f3) + time4, n_eos1 = self._timed_deplete( + n_inter, qi_inputs, dt, matrix_func=leqi_f4) # store updated rates self._prev_rates = copy.deepcopy(bos_res.rates) return ( - time1 + time2 + time3 + time4, [conc_eos0, conc_eos1], + time1 + time2 + time3 + time4, [n_eos0, n_eos1], [bos_res, res_inter]) @@ -449,13 +451,14 @@ class SICELIIntegrator(SIIntegrator): """ _num_stages = 2 - def __call__(self, bos_conc, bos_rates, dt, source_rate, _i=None): + def __call__(self, n_bos, bos_rates, dt, source_rate, _i=None): """Perform the integration across one time step Parameters ---------- - bos_conc : numpy.ndarray - Initial bos_concentrations for all nuclides in [atom] + n_bos : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. bos_rates : openmc.deplete.ReactionRates Reaction rates from operator dt : float @@ -469,19 +472,19 @@ class SICELIIntegrator(SIIntegrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - bos_conc_list : list of numpy.ndarray + n_bos_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with - the final bos_concentration as the last element + the final concentration as the last element op_results : list of openmc.deplete.OperatorResult Eigenvalue and reaction rates from intermediate transport simulations """ - proc_time, eos_conc = self._timed_deplete(bos_conc, bos_rates, dt) - inter_conc = copy.deepcopy(eos_conc) + proc_time, n_eos = self._timed_deplete(n_bos, bos_rates, dt) + n_inter = copy.deepcopy(n_eos) # Begin iteration for j in range(self.n_steps + 1): - inter_res = self.operator(inter_conc, source_rate) + inter_res = self.operator(n_inter, source_rate) if j <= 1: res_bar = copy.deepcopy(inter_res) @@ -491,14 +494,14 @@ class SICELIIntegrator(SIIntegrator): res_bar = OperatorResult(k, rates) list_rates = list(zip(bos_rates, res_bar.rates)) - time1, inter_conc = self._timed_deplete( - bos_conc, list_rates, dt, matrix_func=celi_f1) - time2, inter_conc = self._timed_deplete( - inter_conc, list_rates, dt, matrix_func=celi_f2) + time1, n_inter = self._timed_deplete( + n_bos, list_rates, dt, matrix_func=celi_f1) + time2, n_inter = self._timed_deplete( + n_inter, list_rates, dt, matrix_func=celi_f2) proc_time += time1 + time2 # end iteration - return proc_time, [eos_conc, inter_conc], [res_bar] + return proc_time, [n_eos, n_inter], [res_bar] @add_params @@ -514,14 +517,14 @@ class SILEQIIntegrator(SIIntegrator): """ _num_stages = 2 - def __call__(self, bos_conc, bos_rates, dt, source_rate, i): + def __call__(self, n_bos, bos_rates, dt, source_rate, i): """Perform the integration across one time step Parameters ---------- - bos_conc : list of numpy.ndarray - Initial concentrations for all nuclides in [atom] for - all depletable materials + n_bos : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. bos_rates : list of openmc.deplete.ReactionRates Reaction rates from operator for all depletable materials dt : float @@ -535,7 +538,7 @@ class SILEQIIntegrator(SIIntegrator): ------- proc_time : float Time spent in CRAM routines for all materials in [s] - conc_list : list of numpy.ndarray + n_list : list of list of numpy.ndarray Concentrations at each of the intermediate points with the final concentration as the last element op_results : list of openmc.deplete.OperatorResult @@ -547,7 +550,7 @@ class SILEQIIntegrator(SIIntegrator): self._prev_rates = bos_rates # Perform CELI for initial steps return SICELIIntegrator.__call__( - self, bos_conc, bos_rates, dt, source_rate, i) + self, n_bos, bos_rates, dt, source_rate, i) prev_res = self.operator.prev_res[-2] prev_dt = self.timesteps[i] - prev_res.time[0] self._prev_rates = prev_res.rates[0] @@ -557,16 +560,16 @@ class SILEQIIntegrator(SIIntegrator): # Perform remaining LE/QI inputs = list(zip(self._prev_rates, bos_rates, repeat(prev_dt), repeat(dt))) - proc_time, inter_conc = self._timed_deplete( - bos_conc, inputs, dt, matrix_func=leqi_f1) - time1, eos_conc = self._timed_deplete( - inter_conc, inputs, dt, matrix_func=leqi_f2) + proc_time, n_inter = self._timed_deplete( + n_bos, inputs, dt, matrix_func=leqi_f1) + time1, n_eos = self._timed_deplete( + n_inter, inputs, dt, matrix_func=leqi_f2) proc_time += time1 - inter_conc = copy.deepcopy(eos_conc) + n_inter = copy.deepcopy(n_eos) for j in range(self.n_steps + 1): - inter_res = self.operator(inter_conc, source_rate) + inter_res = self.operator(n_inter, source_rate) if j <= 1: res_bar = copy.deepcopy(inter_res) @@ -577,13 +580,13 @@ class SILEQIIntegrator(SIIntegrator): inputs = list(zip(self._prev_rates, bos_rates, res_bar.rates, repeat(prev_dt), repeat(dt))) - time1, inter_conc = self._timed_deplete( - bos_conc, inputs, dt, matrix_func=leqi_f3) - time2, inter_conc = self._timed_deplete( - inter_conc, inputs, dt, matrix_func=leqi_f4) + time1, n_inter = self._timed_deplete( + n_bos, inputs, dt, matrix_func=leqi_f3) + time2, n_inter = self._timed_deplete( + n_inter, inputs, dt, matrix_func=leqi_f4) proc_time += time1 + time2 - return proc_time, [eos_conc, inter_conc], [res_bar] + return proc_time, [n_eos, n_inter], [res_bar] integrator_by_name = { diff --git a/openmc/deplete/pool.py b/openmc/deplete/pool.py index 1fa5e26ac..9dc9ea468 100644 --- a/openmc/deplete/pool.py +++ b/openmc/deplete/pool.py @@ -4,8 +4,10 @@ Provided to avoid some circular imports """ from itertools import repeat, starmap from multiprocessing import Pool + from scipy.sparse import bmat import numpy as np + from openmc.mpi import comm # Configurable switch that enables / disables the use of @@ -38,28 +40,28 @@ def _distribute(items): return items[j:j + chunk_size] j += chunk_size -def deplete(func, chain, x, rates, dt, matrix_func=None, transfer_rates=None, +def deplete(func, chain, n, rates, dt, matrix_func=None, transfer_rates=None, *matrix_args): """Deplete materials using given reaction rates for a specified time Parameters ---------- func : callable - Function to use to get new compositions. Expected to have the - signature ``func(A, n0, t) -> n1`` + Function to use to get new compositions. Expected to have the signature + ``func(A, n0, t) -> n1`` chain : openmc.deplete.Chain Depletion chain - x : list of numpy.ndarray - Atom number vectors for each material + n : list of numpy.ndarray + List of atom number arrays for each material. Each array in the list + contains the number of [atom] of each nuclide. rates : openmc.deplete.ReactionRates Reaction rates (from transport operator) dt : float Time in [s] to deplete for maxtrix_func : callable, optional - Function to form the depletion matrix after calling - ``matrix_func(chain, rates, fission_yields)``, where - ``fission_yields = {parent: {product: yield_frac}}`` - Expected to return the depletion matrix required by + Function to form the depletion matrix after calling ``matrix_func(chain, + rates, fission_yields)``, where ``fission_yields = {parent: {product: + yield_frac}}`` Expected to return the depletion matrix required by ``func`` transfer_rates : openmc.deplete.TransferRates, Optional Object to perform continuous reprocessing. @@ -70,19 +72,20 @@ def deplete(func, chain, x, rates, dt, matrix_func=None, transfer_rates=None, Returns ------- - x_result : list of numpy.ndarray - Updated atom number vectors for each material + n_result : list of numpy.ndarray + Updated list of atom number arrays for each material. Each array in the + list contains the number of [atom] of each nuclide. """ fission_yields = chain.fission_yields if len(fission_yields) == 1: fission_yields = repeat(fission_yields[0]) - elif len(fission_yields) != len(x): + elif len(fission_yields) != len(n): raise ValueError( "Number of material fission yield distributions {} is not " "equal to the number of compositions {}".format( - len(fission_yields), len(x))) + len(fission_yields), len(n))) if matrix_func is None: matrices = map(chain.form_matrix, rates, fission_yields) @@ -101,12 +104,12 @@ def deplete(func, chain, x, rates, dt, matrix_func=None, transfer_rates=None, if len(transfer_rates.index_transfer) > 0: # Gather all on comm.rank 0 matrices = comm.gather(matrices) - x = comm.gather(x) + n = comm.gather(n) if comm.rank == 0: # Expand lists matrices = [elm for matrix in matrices for elm in matrix] - x = [x_elm for x_mat in x for x_elm in x_mat] + n = [n_elm for n_mat in n for n_elm in n_mat] # Calculate transfer rate terms as diagonal matrices transfer_pair = { @@ -136,28 +139,28 @@ def deplete(func, chain, x, rates, dt, matrix_func=None, transfer_rates=None, matrix = bmat(rows) # Concatenate vectors of nuclides in one - x_multi = np.concatenate([xx for xx in x]) - x_result = func(matrix, x_multi, dt) + n_multi = np.concatenate(n) + n_result = func(matrix, n_multi, dt) # Split back the nuclide vector result into the original form - x_result = np.split(x_result, np.cumsum([len(i) for i in x])[:-1]) + n_result = np.split(n_result, np.cumsum([len(i) for i in n])[:-1]) else: - x_result = None + n_result = None # Braodcast result to other ranks - x_result = comm.bcast(x_result) + n_result = comm.bcast(n_result) # Distribute results across MPI - x_result = _distribute(x_result) + n_result = _distribute(n_result) - return x_result + return n_result - inputs = zip(matrices, x, repeat(dt)) + inputs = zip(matrices, n, repeat(dt)) if USE_MULTIPROCESSING: with Pool(NUM_PROCESSES) as pool: - x_result = list(pool.starmap(func, inputs)) + n_result = list(pool.starmap(func, inputs)) else: - x_result = list(starmap(func, inputs)) + n_result = list(starmap(func, inputs)) - return x_result + return n_result