Pass iteration index to Integrator.__call__

For the higher order methods, like LEQI, a lower order
method may be called for the first few steps. The LEQI
method, with no restart data, will call CELI for the first
iteration. To aid this, concrete Integrator classes will be
passed an integer for the current iteration.

Some methods, like the CECM and CELI, do not need this information.
To maintain a consistent API, the iteration is an optional value
to be passed to CECM.__call__, but will not be used. The default
value in the call signature is ``_i=-1``, with documentation repeating
that the value is not used nor needed.
This commit is contained in:
Andrew Johnson 2019-07-17 16:29:55 -05:00
parent f0bb600271
commit 1d791a16c9
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
2 changed files with 10 additions and 6 deletions

View file

@ -54,7 +54,7 @@ class Integrator(ABC):
self.power = power
@abstractmethod
def __call__(self, conc, rates, dt, power):
def __call__(self, conc, rates, dt, power, i):
"""Perform the integration across one time step
Parameters
@ -67,6 +67,8 @@ class Integrator(ABC):
Time in [s] for the entire depletion interval
power : float
Power of the system [W]
i : int
Current depletion step index
Returns
-------
@ -111,11 +113,11 @@ class Integrator(ABC):
def integrate(self):
"""Perform the entire depletion process across all steps"""
with self.operator as conc:
t, i_start = self._get_start_data()
t, self._ires = self._get_start_data()
for i, (dt, p) in enumerate(self):
conc, res = self._get_bos_data(i, p, conc)
proc_time, conc_list, res_list = self(conc, res.rates, dt, p)
proc_time, conc_list, res_list = self(conc, res.rates, dt, p, i)
# Insert BOS concentration, transport results
conc_list.insert(0, conc)
@ -125,7 +127,7 @@ class Integrator(ABC):
conc = conc_list.pop()
self._save_results(
conc_list, res_list, [t, t + dt], p, i_start + i,
conc_list, res_list, [t, t + dt], p, self._ires + i,
proc_time)
t += dt
@ -133,7 +135,7 @@ class Integrator(ABC):
# Final simulation
res_list = [self.operator(conc, p)]
self._save_results(
[conc], res_list, [t, t], p, i_start + len(self))
[conc], res_list, [t, t], p, self._ires + len(self))
def _save_results(self, conc_list, results_list, time_list, power,
index, proc_time=None):

View file

@ -25,7 +25,7 @@ class CECMIntegrator(Integrator):
\end{aligned}
"""
def __call__(self, conc, rates, dt, power):
def __call__(self, conc, rates, dt, power, _i=-1):
"""Integrate using CE/CM
Parameters
@ -38,6 +38,8 @@ class CECMIntegrator(Integrator):
Time in [s] for the entire depletion interval
power : float
Power of the system [W]
_i : int, optional
Current iteration count. Not used
Returns
-------