Exemplo n.º 1
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)
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
0
    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)