def update(self, dt=None): """Updating model for a certain time step interval (default: None). Checks whether model end time is already reached. Requires that model-specific time step is a whole number of update time step. Keyword Arguments: dt {int} -- update time step interval [s] at which information is exchanged between models (default: {None}) Raises: ValueError -- Raised if model time step is not whole number of update interval Exception -- Raised if end time is already reached as no further update is possible """ # dt in seconds. if not given model timestep is used if self._t >= self._endTime: raise Exception("endTime already reached, model not updated") if (dt is not None) and (dt != self._dt.total_seconds()): _dt = timedelta(seconds=dt) if not glib.check_dts_divmod(_dt, self._dt): msg = "Invalid value for dt in comparison to model dt. Make sure a whole number of model timesteps ({}) fit in the given dt ({})" raise ValueError(msg.format(self._dt, _dt)) self._bmi.update(_dt.days) self._t += _dt else: self._bmi.update(self._dt.days) self._t += self._dt self.logger.info('updated model to datetime {}'.format( self._t.strftime("%Y-%m-%d %H:%M")))
def _check_dt(self): """Checks whether the dt specified for a model is not a whole number of GLOFRIM dt. criterion is needed to ensure updates between models remain in phase Raises: AssertionError -- Raised if model dt is not a whole number of GLOFRIM dt """ for mod in self.bmimodels: dt_mod = self.bmimodels[mod].get_time_step() if not glib.check_dts_divmod(self._dt, dt_mod): msg = "Invalid value for dt in comparison to model dt. Make sure a whole number of model timesteps fit in the set GLOFRIM dt" self.logger.error(msg) raise AssertionError(msg)
def update(self, dt=None): # dt in seconds. if not given model timestep is used if self._t >= self._endTime: raise Exception("endTime already reached, model not updated") if (dt is not None) and (dt != self._dt.total_seconds()): _dt = timedelta(seconds=dt) if not glib.check_dts_divmod(_dt, self._dt): msg = "Invalid value for dt in comparison to model dt. Make sure a whole number of model timesteps ({}) fit in the given dt ({})" raise ValueError(msg.format(self._dt, _dt)) self._bmi.update(dt) else: self._bmi.update() self._t = self.get_current_time() self.logger.info('updated model to datetime {}'.format( self._t.strftime("%Y-%m-%d %H:%M")))