The bus real power injections are related to bus voltage angles
        by::
                P = Bbus * Va + Pbusinj

        The real power flows at the from end the lines are related to the bus
        voltage angles by::

                Pf = Bf * Va + Pfinj

                | Pf |   | Bff  Bft |   | Vaf |   | Pfinj |
                |    | = |          | * |     | + |       |
                | Pt |   | Btf  Btt |   | Vat |   | Ptinj |


        Based on makeBdc.m from MATPOWER by Ray Zimmerman, developed at
        PSERC Cornell. See U{http://www.pserc.cornell.edu/matpower/} for more
        information.

        @return: B matrices and phase shift injection vectors for DC power
                 flow.
        @rtype: tuple

def makeBdc(self, buses=None, branches=None):
        """ The bus real power injections are related to bus voltage angles
        by::
                P = Bbus * Va + Pbusinj

        The real power flows at the from end the lines are related to the bus
        voltage angles by::

                Pf = Bf * Va + Pfinj

                | Pf |   | Bff  Bft |   | Vaf |   | Pfinj |
                |    | = |          | * |     | + |       |
                | Pt |   | Btf  Btt |   | Vat |   | Ptinj |


        Based on makeBdc.m from MATPOWER by Ray Zimmerman, developed at
        PSERC Cornell. See U{http://www.pserc.cornell.edu/matpower/} for more
        information.

        @return: B matrices and phase shift injection vectors for DC power
                 flow.
        @rtype: tuple
        """
        buses = self.connected_buses if buses is None else buses
        branches = self.online_branches if branches is None else branches

        nb = len(buses)
        nl = len(branches)

        # Ones at in-service branches.
        online = array([br.online for br in branches])
        # Series susceptance.
        b = online / array([br.x for br in branches])

        # Default tap ratio = 1.0.
        tap = ones(nl)
        # Transformer off nominal turns ratio (equals 0 for lines) (taps at
        # "from" bus, impedance at 'to' bus, i.e. ratio = Vsrc / Vtgt)
        for i, branch in enumerate(branches):
            if branch.ratio != 0.0:
                tap[i] = branch.ratio
        b = b / tap

        f = [br.from_bus._i for br in branches]
        t = [br.to_bus._i for br in branches]
        i = r_[array(range(nl)), array(range(nl))]
        one = ones(nl)
        Cft = csc_matrix((r_[one, -one], (i, r_[f, t])), shape=(nl, nb))
#        Cf = spmatrix(1.0, f, range(nl), (nb, nl))
#        Ct = spmatrix(1.0, t, range(nl), (nb, nl))

        # Build Bsrc such that Bsrc * Va is the vector of real branch powers
        # injected at each branch's "from" bus.
        Bf = csc_matrix((r_[b, -b], (i, r_[f, t])), (nl, nb))

        Bbus = Cft.T * Bf

        # Build phase shift injection vectors.
        shift = array([br.phase_shift * pi / 180.0 for br in branches])
        Pfinj = b * shift
        #Ptinj = -Pfinj
        # Pbusinj = Cf * Pfinj + Ct * Ptinj
        Pbusinj = Cft.T * Pfinj

        return Bbus, Bf, Pbusinj, Pfinj