Пример #1
0
    def _runpf_with_diverging_exception(self, is_dc):
        """
        .. warning:: /!\\\\ Internal, do not use unless you know what you are doing /!\\\\


        Computes a power flow on the _grid and raises an exception in case of diverging power flow, or any other
        exception that can be thrown by the backend.

        :param is_dc: mode of the power flow. If *is_dc* is True, then the powerlow is run using the DC
                      approximation otherwise it uses the AC powerflow.
        :type is_dc: bool

        Raises
        ------
        exc_: :class:`grid2op.Exceptions.DivergingPowerFlow`
            In case of divergence of the powerflow

        """
        conv = False
        try:
            conv = self.runpf(is_dc=is_dc)  # run powerflow
        except:
            pass

        res = None
        if not conv:
            res = DivergingPowerFlow(
                "GAME OVER: Powerflow has diverged during computation "
                "or a load has been disconnected or a generator has been disconnected."
            )
        return res
Пример #2
0
    def runpf(self, is_dc=False):
        try:
            if is_dc:
                msg_ = "LightSimBackend: the support of the DC approximation is fully supported at the moment"
                warnings.warn(msg_)
                raise RuntimeError(msg_)
                if self.V is None:
                    self.V = np.ones(self.nb_bus_total, dtype=np.complex_)
                V = self._grid.dc_pf(self.V, self.max_it, self.tol)
                if V.shape[0] == 0:
                    raise DivergingPowerFlow(
                        "divergence of powerflow (non connected grid)")
            else:
                if self.V is None:
                    # init from dc approx in this case
                    self.V = np.ones(self.nb_bus_total,
                                     dtype=np.complex_) * 1.04

                if self.initdc:
                    self._grid.deactivate_result_computation()
                    V = self._grid.dc_pf(copy.deepcopy(self.V), self.max_it,
                                         self.tol)
                    self._grid.reactivate_result_computation()

                    if V.shape[0] == 0:
                        raise DivergingPowerFlow(
                            "divergence of powerflow (non connected grid)")
                    self.V[:] = V
                V = self._grid.ac_pf(self.V, self.max_it, self.tol)
                if V.shape[0] == 0:
                    # V = self._grid.ac_pf(self.V, self.max_it, self.tol)
                    raise DivergingPowerFlow("divergence of powerflow")

            self.comp_time += self._grid.get_computation_time()
            self.V[:] = V
            lpor, lqor, lvor, laor = self._grid.get_lineor_res()
            lpex, lqex, lvex, laex = self._grid.get_lineex_res()
            tpor, tqor, tvor, taor = self._grid.get_trafohv_res()
            tpex, tqex, tvex, taex = self._grid.get_trafolv_res()

            self.p_or[:] = np.concatenate((lpor, tpor))
            self.q_or[:] = np.concatenate((lqor, tqor))
            self.v_or[:] = np.concatenate((lvor, tvor))
            self.a_or[:] = 1000. * np.concatenate((laor, taor))

            self.p_ex[:] = np.concatenate((lpex, tpex))
            self.q_ex[:] = np.concatenate((lqex, tqex))
            self.v_ex[:] = np.concatenate((lvex, tvex))
            self.a_ex[:] = 1000. * np.concatenate((laex, taex))

            self.a_or[~np.isfinite(self.a_or)] = 0.
            self.v_or[~np.isfinite(self.v_or)] = 0.
            self.a_ex[~np.isfinite(self.a_ex)] = 0.
            self.v_ex[~np.isfinite(self.v_ex)] = 0.

            self.load_p[:], self.load_q[:], self.load_v[:] = self._grid.get_loads_res(
            )
            self.prod_p[:], self.prod_q[:], self.prod_v[:] = self._grid.get_gen_res(
            )
            self.next_prod_p[:] = self.prod_p

            if np.any(~np.isfinite(self.load_v)) or np.any(self.load_v <= 0.):
                raise DivergingPowerFlow("One load is disconnected")
            if np.any(~np.isfinite(self.prod_v)) or np.any(self.prod_v <= 0.):
                raise DivergingPowerFlow("One generator is disconnected")

            res = True
        except Exception as exc_:
            # of the powerflow has not converged, results are Nan
            self._fill_nans()
            res = False

        return res
Пример #3
0
    def runpf(self, is_dc=False):
        try:
            if is_dc:
                raise NotImplementedError(
                    "Not fully implemented at the moment.")
                if self.V is None:
                    self.V = np.ones(self.nb_bus_total, dtype=np.complex_)
                self.V = self._grid.dc_pf(self.V, self.max_it, self.tol)
            else:
                if self.V is None:
                    # init from dc approx in this case
                    self.V = np.ones(self.nb_bus_total,
                                     dtype=np.complex_) * 1.04

                if self.initdc:
                    V = self._grid.dc_pf(self.V, self.max_it, self.tol)
                    if V.shape[0] == 0:
                        # V = self._grid.ac_pf(self.V, self.max_it, self.tol)
                        raise DivergingPowerFlow(
                            "divergence of powerflow (non connected grid)")
                    self.V[:] = V
                V = self._grid.ac_pf(self.V, self.max_it, self.tol)
                if V.shape[0] == 0:
                    # V = self._grid.ac_pf(self.V, self.max_it, self.tol)
                    raise DivergingPowerFlow("divergence of powerflow")
                self.V[:] = V
                # self.V[self.V == 0.] = 1.
                lpor, lqor, lvor, laor = self._grid.get_lineor_res()
                lpex, lqex, lvex, laex = self._grid.get_lineex_res()
                tpor, tqor, tvor, taor = self._grid.get_trafohv_res()
                tpex, tqex, tvex, taex = self._grid.get_trafolv_res()

                self.p_or[:] = np.concatenate((lpor, tpor))
                self.q_or[:] = np.concatenate((lqor, tqor))
                self.v_or[:] = np.concatenate((lvor, tvor))
                self.a_or[:] = 1000. * np.concatenate((laor, taor))

                self.a_or[~np.isfinite(self.a_or)] = 0.
                self.v_or[~np.isfinite(self.v_or)] = 0.
                self.a_ex[~np.isfinite(self.a_ex)] = 0.
                self.v_ex[~np.isfinite(self.v_ex)] = 0.

                self.p_ex[:] = np.concatenate((lpex, tpex))
                self.q_ex[:] = np.concatenate((lqex, tqex))
                self.v_ex[:] = np.concatenate((lvex, tvex))
                self.a_ex[:] = 1000. * np.concatenate((laex, taex))

                self.load_p[:], self.load_q[:], self.load_v[:] = self._grid.get_loads_res(
                )
                self.prod_p[:], self.prod_q[:], self.prod_v[:] = self._grid.get_gen_res(
                )
                self.next_prod_p[:] = self.prod_p

                if np.any(~np.isfinite(self.load_v)) or np.any(
                        self.load_v <= 0.):
                    raise DivergingPowerFlow("One load is disconnected")
                if np.any(~np.isfinite(self.prod_v)) or np.any(
                        self.prod_v <= 0.):
                    raise DivergingPowerFlow("One generator is disconnected")

                res = True
        except Exception as e:
            # of the powerflow has not converged, results are Nan
            self._fill_nans()
            res = False

        return res