Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 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))
Esempio n. 5
0
    def check_var(self):
        if not self.enable:
            return

        if not self.equal:
            self.z1[:] = np.less(self.u.v, self.bound.v)
        else:
            self.z1[:] = np.less_equal(self.u.v, self.bound.v)

        self.z0[:] = np.logical_not(self.z1)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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))
Esempio n. 8
0
    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))
Esempio n. 9
0
    def check_var(self, *args, **kwargs):
        """
        If enabled, set flags based on inputs. Use cached values if enabled.
        """
        if not self.enable:
            return
        if self.cache and self._eval:
            return

        if not self.equal:
            self.z1[:] = np.less(self.u.v, self.bound.v)
        else:
            self.z1[:] = np.less_equal(self.u.v, self.bound.v)

        self.z0[:] = np.logical_not(self.z1)

        self._eval = True
Esempio n. 10
0
 def _not_all_close(a, b):
     return np.logical_not(np.isclose(a, b))