def check_eq(self): """ Check the variables and equations and set the limiter flags. """ self.zu[:] = np.greater(self.u.v, self.upper.v) self.zl[:] = np.less(self.u.v, self.lower.v) self.zi[:] = np.logical_not(np.logical_or(self.zu, self.zl)) self.zu[:] = np.logical_and(self.zu, np.greater(self.state.e, 0)).astype(np.float64) self.zl[:] = np.logical_and(self.zl, np.less(self.state.e, 0)).astype(np.float64) self.zi[:] = np.logical_not( np.logical_or(self.zu.astype(np.bool), self.zl.astype(np.bool))).astype(np.float64)
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_var(self): """ Updates five flags: zi, zu, zl; zur, and zlr based on the following rules: zu: 1 if u > upper; 0 otherwise. zl: 1 if u < lower; 0 otherwise. zi: not(zu or zl); zur: - set to 1 when (previous zu + present zi == 2) - hold when (previous zi == zi) - clear otherwise zlr: - set to 1 when (previous zl + present zi == 2) - hold when (previous zi == zi) - clear otherwise """ if not self.enable: return zu = np.greater(self.u.v, self.upper.v) zl = np.less(self.u.v, self.lower.v) zi = np.logical_not(np.logical_or(zu, zl)) # square return dead band self.zur[:] = np.equal(self.zu + zi, 2) + self.zur * np.equal(zi, self.zi) self.zlr[:] = np.equal(self.zl + zi, 2) + self.zlr * np.equal(zi, self.zi) self.zu[:] = zu.astype(np.float64) self.zl[:] = zl.astype(np.float64) self.zi[:] = zi.astype(np.float64)
def check_eq(self): """ Check the variables and equations and set the limiter flags. """ self.zu[:] = np.logical_and(np.greater_equal(self.u.v, self.upper.v), np.greater_equal(self.state.e, 0)) 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))
def check(self): """ Check the bounds and equality conditions. """ if not self.enable: return def _not_all_close(a, b): return np.logical_not(np.isclose(a, b)) if self._v is None: self._v = np.zeros_like(self.u.v) checks = [(self.lower, np.less_equal, "violation of the lower limit", "limit"), (self.upper, np.greater_equal, "violation of the upper limit", "limit"), (self.equal, _not_all_close, 'should be equal', "expected"), (self.not_equal, np.equal, 'should not be equal', "not expected")] for check in checks: limit = check[0] func = check[1] text = check[2] text2 = check[3] if limit is None: continue self.v[:] = np.logical_or(self.v, func(self.u.v, limit.v)) pos = np.argwhere(func(self.u.v, limit.v)).ravel() if len(pos) == 0: continue idx = [self.owner.idx.v[i] for i in pos] lim_v = limit.v * np.ones(self.n) title = f'{self.owner.class_name} {self.info} {text}.' err_dict = OrderedDict([ ('idx', idx), ('values', self.u.v[pos]), (f'{text2}', lim_v[pos]), ]) data = list(map(list, zip(*err_dict.values()))) tab = Tab(title=title, data=data, header=list(err_dict.keys())) if self.error_out: logger.error(tab.draw()) else: logger.warning(tab.draw()) self.v[:] = np.logical_not(self.v)
def check_var(self): """ Evaluate `self.zu` and `self.zl` Returns ------- """ if not self.enable: return self.zu[:] = np.greater_equal(self.u.v, self.upper.v) self.zl[:] = np.less_equal(self.u.v, self.lower.v) self.zi[:] = np.logical_not(np.logical_or(self.zu, self.zl))
def check_var(self, *args, **kwargs): """ Evaluate the flags. """ if not self.enable: return if not self.no_upper: self.zu[:] = np.greater_equal(self.u.v, self.upper.v) if not self.no_lower: self.zl[:] = np.less_equal(self.u.v, self.lower.v) self.zi[:] = np.logical_not(np.logical_or(self.zu, self.zl))
def check_var(self, *args, **kwargs): if not self.enable: return super().check_var() if self.n_select is not None and self.n_select > 0: asc = np.argsort(self.u.v - self.lower.v) # ascending order desc = np.argsort(self.upper.v - self.u.v) lowest_n = asc[:self.n_select] highest_n = desc[:self.n_select] reset_in = np.ones(self.u.v.shape) reset_in[lowest_n] = 0 reset_in[highest_n] = 0 reset_out = 1 - reset_in self.zi[:] = np.logical_or(reset_in, self.zi) self.zl[:] = np.logical_and(reset_out, self.zl) self.zu[:] = np.logical_and(reset_out, self.zu)