Ejemplo n.º 1
0
    def update(self):
        """
        Update values based on the requested content
        """
        system = self.system
        self.basic.update({
            'Buses': system.Bus.n,
            'Generators': system.PV.n + system.Slack.n,
            'Committed Gens': int(sum(system.PV.u.v) + sum(system.Slack.u.v)),
            'Loads': system.PQ.n,
            'Shunts': system.Shunt.n,
            'Lines': system.Line.n,
            'Transformers': np.count_nonzero(system.Line.trans.v == 1),
            'Areas': system.Area.n,
        })

        if self.system.PFlow.converged is False:
            logger.warning('Cannot update extended summary. Power flow not solved.')
            return

        self.extended.update({
            'Pg': sum(system.PV.u.v * system.PV.p.v) + sum(system.Slack.u.v * system.Slack.p.v),
            'Qg': sum(system.PV.u.v * system.PV.q.v) + sum(system.Slack.u.v * system.Slack.q.v),
            'Pl': round(float(sum(system.PQ.p0.v)), 6),
            'Ql': round(float(sum(system.PQ.q0.v)), 6),
            'Ptot': sum(system.PV.pmax.v) + sum(system.Slack.pmax.v),
            'Pon': sum(system.PV.u.v * system.PV.pmax.v),
            'Qtot_min': sum(system.PV.qmin.v) + sum(system.Slack.qmin.v),
            'Qtot_max': sum(system.PV.qmax.v) + sum(system.Slack.qmax.v),
            'Qon_min': sum(system.PV.u.v * system.PV.qmin.v),
            'Qon_max': sum(system.PV.u.v * system.PV.qmax.v),
        })
Ejemplo n.º 2
0
    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