def _run_power_flow(self, Ybus, Sbus, V, pv, pq, pvpq):
        """ Solves the power flow using a full Newton's method.
        """
        i = 0
        Va = angle(V)
        Vm = abs(V)

        # FIXME: Do not repeat build for each Q limit loop.
        Bp, Bpp = self.case.makeB(method=self.method)

        # Evaluate initial mismatch.
        P, Q = self._evaluate_mismatch(Ybus, V, Sbus, pq, pvpq)

        if self.verbose:
            logger.info("iteration     max mismatch (p.u.)  \n")
            logger.info("type   #        P            Q     \n")
            logger.info("---- ----  -----------  -----------\n")

        # Check tolerance.
        converged = self._check_convergence(P, Q, i, "P")

        if converged and self.verbose:
            logger.info("Converged!")

        # Reduce B matrices.
        pq_col = [[k] for k in pq]
        pvpq_col = [[k] for k in pvpq]
        Bp = Bp[pvpq_col, pvpq].tocsc() # splu requires a CSC matrix
        Bpp = Bpp[pq_col, pq].tocsc()

        # Factor B matrices.
        Bp_solver = splu(Bp)
        Bpp_solver = splu(Bpp)
#        L = decomp.lu(Bp.todense())
#        LU, P = decomp.lu_factor(Bp.todense())

        # Perform Newton iterations.
        while (not converged) and (i < self.iter_max):
            i += 1
            # Perform P iteration, update Va.
            V, Vm, Va = self._p_iteration(P, Bp_solver, Vm, Va, pvpq)

            # Evalute mismatch.
            P, Q = self._evaluate_mismatch(Ybus, V, Sbus, pq, pvpq)
            # Check tolerance.
            converged = self._check_convergence(P, Q, i, "P")

            if self.verbose and converged:
                logger.info("Fast-decoupled power flow converged in %d "
                    "P-iterations and %d Q-iterations." % (i, i - 1))
                break

            # Perform Q iteration, update Vm.
            V, Vm, Va = self._q_iteration(Q, Bpp_solver, Vm, Va, pq)

            # Evalute mismatch.
            P, Q = self._evaluate_mismatch(Ybus, V, Sbus, pq, pvpq)
            # Check tolerance.
            converged = self._check_convergence(P, Q, i, "Q")

            if self.verbose and converged:
                logger.info("Fast-decoupled power flow converged in %d "
                    "P-iterations and %d Q-iterations." % (i, i))
                break

        if self.verbose and not converged:
            logger.error("FDPF did not converge in %d iterations." % i)

        return V, converged, i
def _run_power_flow ( self , Ybus , Sbus , V , pv , pq , pvpq ) : i = 0 Va = angle ( V ) Vm = abs ( V ) Bp , Bpp = self . case . makeB ( method = self . method ) P , Q = self . _evaluate_mismatch ( Ybus , V , Sbus , pq , pvpq ) if self . verbose : logger . info ( "iteration     max mismatch (p.u.)  \n" ) logger . info ( "type   #        P            Q     \n" ) logger . info ( "---- ----  -----------  -----------\n" ) converged = self . _check_convergence ( P , Q , i , "P" ) if converged and self . verbose : logger . info ( "Converged!" ) pq_col = [ [ k ] for k in pq ] pvpq_col = [ [ k ] for k in pvpq ] Bp = Bp [ pvpq_col , pvpq ] . tocsc ( ) Bpp = Bpp [ pq_col , pq ] . tocsc ( ) Bp_solver = splu ( Bp ) Bpp_solver = splu ( Bpp ) while ( not converged ) and ( i < self . iter_max ) : i += 1 V , Vm , Va = self . _p_iteration ( P , Bp_solver , Vm , Va , pvpq ) P , Q = self . _evaluate_mismatch ( Ybus , V , Sbus , pq , pvpq ) converged = self . _check_convergence ( P , Q , i , "P" ) if self . verbose and converged : logger . info ( "Fast-decoupled power flow converged in %d " "P-iterations and %d Q-iterations." % ( i , i - 1 ) ) break V , Vm , Va = self . _q_iteration ( Q , Bpp_solver , Vm , Va , pq ) P , Q = self . _evaluate_mismatch ( Ybus , V , Sbus , pq , pvpq ) converged = self . _check_convergence ( P , Q , i , "Q" ) if self . verbose and converged : logger . info ( "Fast-decoupled power flow converged in %d " "P-iterations and %d Q-iterations." % ( i , i ) ) break if self . verbose and not converged : logger . error ( "FDPF did not converge in %d iterations." % i ) return V , converged , i
Solves the power flow using a full Newton's method.