mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Use Results.save directly during Integrator.integrate
Removed the private method for saving to avoid unnecessary redirection. Also renamed some private attributes: 1) Integrator._ires -> Integrator._i_res 2) Integrator._N_STAGES -> Integrator._num_stages
This commit is contained in:
parent
a7e1bca6da
commit
49ba67d480
9 changed files with 32 additions and 41 deletions
|
|
@ -40,13 +40,13 @@ class Integrator(ABC):
|
|||
# Check number of stages previously used
|
||||
if operator.prev_res is not None:
|
||||
res = operator.prev_res[-1]
|
||||
if res.data.shape[0] != self._N_STAGES:
|
||||
if res.data.shape[0] != self._num_stages:
|
||||
raise ValueError(
|
||||
"{} incompatible with previous restart calculation. "
|
||||
"Previous scheme used {} intermediate solutions, while "
|
||||
"this uses {}".format(
|
||||
self.__class__.__name__, res.data.shape[0],
|
||||
self._N_STAGES))
|
||||
self._num_stages))
|
||||
self.operator = operator
|
||||
self.chain = operator.chain
|
||||
if not isinstance(timesteps, Iterable):
|
||||
|
|
@ -102,7 +102,7 @@ class Integrator(ABC):
|
|||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _N_STAGES(self):
|
||||
def _num_stages(self):
|
||||
"""Number of intermediate transport solutions
|
||||
|
||||
Needed to ensure schemes are consistent with restarts
|
||||
|
|
@ -141,7 +141,7 @@ class Integrator(ABC):
|
|||
def integrate(self):
|
||||
"""Perform the entire depletion process across all steps"""
|
||||
with self.operator as conc:
|
||||
t, self._ires = self._get_start_data()
|
||||
t, self._i_res = self._get_start_data()
|
||||
|
||||
for i, (dt, p) in enumerate(self):
|
||||
if i > 0 or self.operator.prev_res is None:
|
||||
|
|
@ -157,29 +157,21 @@ class Integrator(ABC):
|
|||
# Remove actual EOS concentration for next step
|
||||
conc = conc_list.pop()
|
||||
|
||||
self._save_results(
|
||||
conc_list, res_list, [t, t + dt], p, self._ires + i,
|
||||
proc_time)
|
||||
Results.save(self.operator, conc_list, res_list, [t, t + dt],
|
||||
p, self._i_res + i, proc_time)
|
||||
|
||||
t += dt
|
||||
|
||||
# Final simulation
|
||||
res_list = [self.operator(conc, p)]
|
||||
self._save_results(
|
||||
[conc], res_list, [t, t], p, self._ires + len(self))
|
||||
Results.save(self.operator, [conc], res_list, [t, t],
|
||||
p, self._i_res + len(self), proc_time)
|
||||
self._write_statepoint(len(self))
|
||||
|
||||
def _save_results(self, conc_list, results_list, time_list, power,
|
||||
index, proc_time=None):
|
||||
"""Save the results at the end of of one step"""
|
||||
Results.save(
|
||||
self.operator, conc_list, results_list, time_list,
|
||||
power, index, proc_time)
|
||||
|
||||
def _write_statepoint(self, step_index):
|
||||
"""Use C API to write a statepoint for this index"""
|
||||
statepoint_write(
|
||||
"openmc_simulation_n{}.h5".format(step_index + self._ires),
|
||||
"openmc_simulation_n{}.h5".format(step_index + self._i_res),
|
||||
write_source=False)
|
||||
|
||||
|
||||
|
|
@ -234,7 +226,7 @@ class SI_Integrator(Integrator):
|
|||
def integrate(self):
|
||||
"""Perform the entire depletion process across all steps"""
|
||||
with self.operator as conc:
|
||||
t, self._ires = self._get_start_data()
|
||||
t, self._i_res = self._get_start_data()
|
||||
|
||||
for i, (dt, p) in enumerate(self):
|
||||
if i == 0:
|
||||
|
|
@ -256,13 +248,12 @@ class SI_Integrator(Integrator):
|
|||
# Remove actual EOS concentration for next step
|
||||
conc = conc_list.pop()
|
||||
|
||||
self._save_results(
|
||||
conc_list, res_list, [t, t + dt], p, self._ires + i,
|
||||
proc_time)
|
||||
Results.save(self.operator, conc_list, res_list, [t, t + dt],
|
||||
p, self._i_res + i, proc_time)
|
||||
|
||||
t += dt
|
||||
|
||||
# No final simulation for SIE, use last iteration results
|
||||
self._save_results(
|
||||
[conc], [res_list[-1]], [t, t], p, self._ires + len(self))
|
||||
Results.save(self.operator, [conc], [res_list[-1]], [t, t],
|
||||
p, self._i_res + len(self), proc_time)
|
||||
self._write_statepoint(len(self))
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class CECMIntegrator(Integrator):
|
|||
y_{n+1} &= \text{expm}(A_c h) y_n
|
||||
\end{aligned}
|
||||
"""
|
||||
_N_STAGES = 2
|
||||
_num_stages = 2
|
||||
|
||||
def __call__(self, conc, rates, dt, power, _i=-1):
|
||||
"""Integrate using CE/CM
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class CELIIntegrator(Integrator):
|
|||
\text{expm}(\frac{5h}{12} A_0 + \frac{h}{12} A1) y_n
|
||||
\end{aligned}
|
||||
"""
|
||||
_N_STAGES = 2
|
||||
_num_stages = 2
|
||||
|
||||
def __call__(self, bos_conc, rates, dt, power, _i=-1):
|
||||
"""Perform the integration across one time step
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class CF4Integrator(Integrator):
|
|||
\text{expm}(-1/12 F_1 + 1/6 F_2 + 1/6 F_3 + 1/4 F_4) y_0
|
||||
\end{aligned}
|
||||
"""
|
||||
_N_STAGES = 4
|
||||
_num_stages = 4
|
||||
|
||||
def __call__(self, bos_conc, bos_rates, dt, power, i):
|
||||
"""Perform the integration across one time step
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class EPC_RK4_Integrator(Integrator):
|
|||
y_4 &= \text{expm}(1/6 F_1 + 1/3 F_2 + 1/3 F_3 + 1/6 F_4) y_0
|
||||
\end{aligned}
|
||||
"""
|
||||
_N_STAGES = 4
|
||||
_num_stages = 4
|
||||
|
||||
def __call__(self, conc, rates, dt, power, _i):
|
||||
"""Perform the integration across one time step
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class LEQIIntegrator(Integrator):
|
|||
|
||||
It is initialized using the CE/LI algorithm.
|
||||
"""
|
||||
_N_STAGES = 2
|
||||
_num_stages = 2
|
||||
|
||||
def __call__(self, bos_conc, bos_rates, dt, power, i):
|
||||
"""Perform the integration across one time step
|
||||
|
|
@ -67,21 +67,21 @@ class LEQIIntegrator(Integrator):
|
|||
simulation
|
||||
"""
|
||||
if i == 0:
|
||||
if self._ires < 1: # need at least previous transport solution
|
||||
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, power, i)
|
||||
prev_res = self.operator.prev_res[-2]
|
||||
prevdt = self.timesteps[i] - prev_res.time[0]
|
||||
prev_dt = self.timesteps[i] - prev_res.time[0]
|
||||
self._prev_rates = prev_res.rates[0]
|
||||
else:
|
||||
prevdt = self.timesteps[i - 1]
|
||||
prev_dt = self.timesteps[i - 1]
|
||||
|
||||
# Remaining LE/QI
|
||||
bos_res = self.operator(bos_conc, power)
|
||||
|
||||
le_inputs = list(zip(
|
||||
self._prev_rates, bos_res.rates, repeat(prevdt), repeat(dt)))
|
||||
self._prev_rates, bos_res.rates, repeat(prev_dt), repeat(dt)))
|
||||
|
||||
time1, conc_inter = timed_deplete(
|
||||
self.chain, bos_conc, le_inputs, dt, matrix_func=_leqi_f1)
|
||||
|
|
@ -92,7 +92,7 @@ class LEQIIntegrator(Integrator):
|
|||
|
||||
qi_inputs = list(zip(
|
||||
self._prev_rates, bos_res.rates, res_inter.rates,
|
||||
repeat(prevdt), repeat(dt)))
|
||||
repeat(prev_dt), repeat(dt)))
|
||||
|
||||
time3, conc_inter = timed_deplete(
|
||||
self.chain, bos_conc, qi_inputs, dt, matrix_func=_leqi_f3)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class PredictorIntegrator(Integrator):
|
|||
initial heavy metal inventory to get total power if ``power``
|
||||
is not speficied.
|
||||
"""
|
||||
_N_STAGES = 1
|
||||
_num_stages = 1
|
||||
|
||||
def __call__(self, conc, rates, dt, power, _i=None):
|
||||
"""Perform the integration across one time step
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class SI_CELI_Integrator(SI_Integrator):
|
|||
detailed algorithm can be found in section 3.2 in `colin josey's thesis
|
||||
<http://hdl.handle.net/1721.1/113721>`_.
|
||||
"""
|
||||
_N_STAGES = 2
|
||||
_num_stages = 2
|
||||
|
||||
def __call__(self, bos_conc, bos_rates, dt, power, _i):
|
||||
"""Perform the integration across one time step
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class SI_LEQI_Integrator(SI_Integrator):
|
|||
Detailed algorithm can be found in Section 3.2 in `Colin Josey's thesis
|
||||
<http://hdl.handle.net/1721.1/113721>`_.
|
||||
"""
|
||||
_N_STAGES = 2
|
||||
_num_stages = 2
|
||||
|
||||
def __call__(self, bos_conc, bos_rates, dt, power, i):
|
||||
"""Perform the integration across one time step
|
||||
|
|
@ -52,20 +52,20 @@ class SI_LEQI_Integrator(SI_Integrator):
|
|||
simulation
|
||||
"""
|
||||
if i == 0:
|
||||
if self._ires < 1:
|
||||
if self._i_res < 1:
|
||||
self._prev_rates = bos_rates
|
||||
# Perform CELI for initial steps
|
||||
return SI_CELI_Integrator.__call__(
|
||||
self, bos_conc, bos_rates, dt, power, i)
|
||||
prev_res = self.operator.prev_res[-2]
|
||||
prevdt = self.timesteps[i] - prev_res.time[0]
|
||||
prev_dt = self.timesteps[i] - prev_res.time[0]
|
||||
self._prev_rates = prev_res.rates[0]
|
||||
else:
|
||||
prevdt = self.timesteps[i - 1]
|
||||
prev_dt = self.timesteps[i - 1]
|
||||
|
||||
# Perform remaining LE/QI
|
||||
inputs = list(zip(self._prev_rates, bos_rates,
|
||||
repeat(prevdt), repeat(dt)))
|
||||
repeat(prev_dt), repeat(dt)))
|
||||
proc_time, inter_conc = timed_deplete(
|
||||
self.chain, bos_conc, inputs, dt, matrix_func=_leqi_f1)
|
||||
time1, eos_conc = timed_deplete(
|
||||
|
|
@ -85,7 +85,7 @@ class SI_LEQI_Integrator(SI_Integrator):
|
|||
res_bar = OperatorResult(k, rates)
|
||||
|
||||
inputs = list(zip(self._prev_rates, bos_rates, res_bar.rates,
|
||||
repeat(prevdt), repeat(dt)))
|
||||
repeat(prev_dt), repeat(dt)))
|
||||
time1, inter_conc = timed_deplete(
|
||||
self.chain, bos_conc, inputs, dt, matrix_func=_leqi_f3)
|
||||
time2, inter_conc = timed_deplete(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue