def check_eq(self): """ Check the variables and equations and set the limiter flags. Reset differential equation values based on limiter flags. Notes ----- The current implementation reallocates memory for `self.x_set` in each call. Consider improving for speed. (TODO) """ if not self.no_upper: self.zu[:] = np.logical_and( np.greater_equal(self.u.v, self.upper.v), np.greater_equal(self.state.e, 0)) if not self.no_lower: self.zl[:] = np.logical_and(np.less_equal(self.u.v, self.lower.v), np.less_equal(self.state.e, 0)) self.zi[:] = np.logical_not(np.logical_or(self.zu, self.zl)) # must flush the `x_set` list at the beginning self.x_set = list() if not np.all(self.zi): idx = np.where(self.zi == 0) self.state.e[:] = self.state.e * self.zi self.state.v[:] = self.state.v * self.zi + self.upper.v * self.zu + self.lower.v * self.zl self.x_set.append((self.state.a[idx], self.state.v[idx], 0)) # (address, var. values, eqn. values)
def check(self, **kwargs): if not np.all(self.v == self.u.v): self.owner.system.TDS.custom_event = True logger.debug( f"Event flag set at t={self.owner.system.dae.t:.6f} sec.") return self.u.v
def set_eq(self): """ Reset differential equation values based on limiter flags. """ self.x_set = list() if not np.all(self.zi): self.state.e = self.state.e * self.zi self.state.v = self.state.v * self.zi + self.upper.v * self.zu + self.lower.v * self.zl self.x_set.append((self.state.a, self.state.v))
def check(self, **kwargs): if not np.all(self.hold.v == 0.0): hold_idx = np.where(self.hold.v == 1) ret = self.u.v.copy() ret[hold_idx] = self.v[hold_idx] return ret else: return self.u.v
def check(self, **kwargs): dae_t = self.owner.system.dae.t if dae_t == 0.0: self.u_last[:] = self.u.v self.v_event[:] = self.u.v # when any input signal changes if not np.all(self.u.v == self.u_last): diff = self.u.v - self.u_last # detect the actual ending of an event if self.trig == 'rise': starting = np.where(diff == 1)[0] ending = np.where(diff == -1)[0] else: starting = np.where(diff == -1)[0] ending = np.where(diff == 1)[0] if len(starting): self.z[starting] = 1 if not self.extend_only: self.v_event[starting] = self.u.v[starting] if len(ending): if self.extend_only: self.v_event[ending] = self.u_last[ending] final_times = dae_t + self.t_ext.v[ending] self.t_final[ending] = final_times self.n_ext += len(ending) # TODO: insert extended event end times to a model-level list logger.debug( f"Extended Event ending time set at t={final_times} sec.") # final time of the extended event if self.n_ext and np.any(self.t_final <= dae_t): self.z[np.where(self.t_final <= dae_t)] = 0 self.n_ext = np.count_nonzero(self.z) self.u_last[:] = self.u.v return self.enable.v * (self.u.v * (1 - self.z) + self.v_event * self.z) + \ (1-self.enable.v) * self.v_disabled
def set_eq(self): """ Reset differential equation values based on limiter flags. Notes ----- The current implementation reallocates memory for `self.x_set` in each call. Consider improving for speed. (TODO) """ # must flush the `x_set` list at the beginning self.x_set = list() if not np.all(self.zi): idx = np.where(self.zi == 0) self.state.e[:] = self.state.e * self.zi self.state.v[:] = self.state.v * self.zi + self.upper.v * self.zu + self.lower.v * self.zl self.x_set.append((self.state.a[idx], self.state.v[idx]))