def __init__(self,from_bus,to_bus, bandwidth=2.0, N_PT=20.0, CTp=700., CTs=5, Rd=3.0, Xd=9.0, Vset=120, type='B'):
     Branch.__init__(self,from_bus,to_bus)    
     self.from_bus=from_bus # self is attached from bus
     self.to_bus = to_bus # self is attached to bus
     self.bandwidth=bandwidth # my bandwidth in Volt
     self.Vset=Vset # the desired voltage on a 120 V base voltage to be held at the regulating point
     self.Vset_min= self.Vset-self.bandwidth/2.
     self.Vset_max= self.Vset+self.bandwidth/2.
     self.N_PT=N_PT # my potential transformer ratio
     self.CTp=CTp # my primary current rating of the current transformer  in Ampere
     self.CTs=CTs # my secondary current rating of the current transformer  in Ampere
     self.CT=self.CTp/self.CTs
     self.Rd=Rd # Rd --> R' the compensator equvalent setting in Volt
     self.Xd=Xd # Xd --> R' the compensator equvalent setting in Volt
     self.Zd=self.Rd + 1j*self.Xd
     self.Zd_ohm =self.Zd/self.CTs
     self.Tap=0
     self.a_R=1
     self.I_comp=0
     self.I_line=0
     self.I_from=0
     self.Vs=1.0+1j*0
     self.Is=0
     self.VL=1+1j*0
     self.IL=0
     self.V_reg=1+1j*0
     self.V_drop=1+1j*0
     self.type=type
Exemplo n.º 2
0
    def test_bus_indexes(self):
        """ Test the from/to bus index property.
        """
        c = Case(name="c")
        bus1 = Bus(name="Bus 1")
        bus2 = Bus(name="Bus 2")
        bus3 = Bus(name="Bus 3")
        c.buses = [bus1, bus2, bus3]

        # Append to list.
        branch1 = Branch(bus3, bus1)
        c.branches.append(branch1)

        self.assertEqual(c.buses.index(branch1.from_bus), 2)
        self.assertEqual(c.buses.index(branch1.to_bus), 0)

        # Set list.
        branch2 = Branch(bus2, bus3)
        branch3 = Branch(bus2, bus1)
        c.branches = [branch2, branch3]

        self.assertEqual(c.buses.index(branch2.from_bus), 1)
        self.assertEqual(c.buses.index(branch2.to_bus), 2)

        # Move branch.
        branch2.from_bus = bus1
        self.assertEqual(c.buses.index(branch2.from_bus), 0)
Exemplo n.º 3
0
    def test_bus_indexes(self):
        """ Test the from/to bus index property.
        """
        c = Case(name="c")
        bus1 = Bus(name="Bus 1")
        bus2 = Bus(name="Bus 2")
        bus3 = Bus(name="Bus 3")
        c.buses = [bus1, bus2, bus3]

        # Append to list.
        branch1 = Branch(bus3, bus1)
        c.branches.append(branch1)

        self.assertEqual(c.buses.index(branch1.from_bus), 2)
        self.assertEqual(c.buses.index(branch1.to_bus), 0)

        # Set list.
        branch2 = Branch(bus2, bus3)
        branch3 = Branch(bus2, bus1)
        c.branches = [branch2, branch3]

        self.assertEqual(c.buses.index(branch2.from_bus), 1)
        self.assertEqual(c.buses.index(branch2.to_bus), 2)

        # Move branch.
        branch2.from_bus = bus1
        self.assertEqual(c.buses.index(branch2.from_bus), 0)
Exemplo n.º 4
0
    def push_line(self, tokens):
        """ Adds a Branch object to the case.
        """
        logger.debug("Pushing line data: %s" % tokens)

        from_bus = self.case.buses[tokens["fbus"]-1]
        to_bus = self.case.buses[tokens["tbus"]-1]

        e = Branch(from_bus=from_bus, to_bus=to_bus)
        e.r = tokens["r"]
        e.x = tokens["x"]
        e.b = tokens["b"]
        e.rate_a = tokens["s_limit"]
        e.rate_b = tokens["p_limit"]
        e.rate_c = tokens["i_limit"]
        # Optional parameter
        if tokens["tap"] == 0: #Transmission line
            e.ratio = 1.0
        else: # Transformer
            e.ratio = tokens["tap"]
        e.phase_shift = tokens["shift"]
        # Optional parameter
#        if "status" in tokens.keys:
#        e.online = tokens["status"]

        self.case.branches.append(e)
    def __init__(self, from_bus, to_bus, Z=ones([3, 3]),Y=zeros([3,3]),base_kv=1.0):
        Branch.__init__(self,from_bus,to_bus)
        self.Z=Z # This is the series element of the line impedance
        self.Y=Y # This is the shunt element of the line impedance
	self.Z012 = dot(dot(inv(Pinv),Z),Pinv)
        self.base_kv=base_kv
        self.E_from = from_bus.E#zeros(3)
        self.E_to=to_bus.E#zeros(3)
        self.I_from = zeros(3)
        self.I_to=zeros(3)
        #self.Iline=zeros(3)
        self.I_line=self.I_to+dot(self.Y,self.E_to)
        self.line_drop=zeros(3,dtype=complex)
	self.line_loss=zeros(3,dtype=complex)
Exemplo n.º 6
0
    def test_reset(self):
        """ Test initialisation of bus result attributes.
        """
        branch = Branch(Bus(), Bus())

        branch.p_from = 25.0
        branch.p_to = -25.0
        branch.q_from = -9.0
        branch.q_to = 9.0
        branch.mu_s_from = 90.0
        branch.mu_s_to = 0.0
        branch.mu_angmin = 60.0
        branch.mu_angmax = 0.0

        branch.reset()

        self.assertEqual(branch.p_from, 0.0)
        self.assertEqual(branch.p_to, 0.0)
        self.assertEqual(branch.q_from, 0.0)
        self.assertEqual(branch.q_to, 0.0)
        self.assertEqual(branch.mu_s_from, 0.0)
        self.assertEqual(branch.mu_s_to, 0.0)
        self.assertEqual(branch.mu_angmin, 0.0)
        self.assertEqual(branch.mu_angmax, 0.0)
Exemplo n.º 7
0
# Author: Richard Lincoln, [email protected]
#------------------------------------------------------------------------------
""" Import "sys" so the report can be written to stdout. """
import sys
""" Import the logging module """
import logging
""" and set up a basic configuration. """
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
""" The "pylon" package contains classes for defining a power system model and
power flow solvers. """
from pylon import \
    Case, Bus, Branch, Generator, NewtonPF, FastDecoupledPF, REFERENCE
""" Start by building up a one branch case with two generators """
bus1 = Bus(type=REFERENCE)
g1 = Generator(bus1, p=80.0, q=10.0)
""" and fixed load at the other. """
bus2 = Bus(p_demand=60.0, q_demand=4.0)
g2 = Generator(bus2, p=20.0, q=0.0)
""" Connect the two buses """
line = Branch(bus1, bus2, r=0.05, x=0.01)
""" and add it all to a new case. """
case = Case(buses=[bus1, bus2], branches=[line], generators=[g1, g2])
""" Choose to solve using either Fast Decoupled method """
solver = FastDecoupledPF(case)
""" or Newton's method """
solver = NewtonPF(case)
""" and then call the solver. """
solver.solve()
""" Write the case out to view the results. """
case.save_rst(sys.stdout)
Exemplo n.º 8
0
import sys

""" Import the logging module """
import logging

""" and set up a basic configuration. """
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

""" Create two generators, specifying their marginal cost. """
bus1 = Bus(p_demand=100.0, type=REFERENCE)
g1 = Generator(bus1, p_min=0.0, p_max=80.0, p_cost=[(0., 0.), (80., 4800.)])
bus2 = Bus()
g2 = Generator(bus2, p_min=0.0, p_max=60.0, p_cost=[(0., 0.), (60., 4500.)])

""" Connect the two generator buses """
line = Branch(bus1, bus2, r=0.05, x=0.25, b=0.06)

""" and add it all to a case. """
case = Case(buses=[bus1, bus2], branches=[line], generators=[g1, g2])

""" Non-linear AC optimal power flow """
dc = False

""" or linearised DC optimal power flow may be selected. """
dc = True

""" Pass the case to the OPF routine and solve. """
OPF(case, dc).solve()

""" View the results as ReStructuredText. """
case.save_rst(sys.stdout)
Exemplo n.º 9
0
    def _parse_file(self, file):
        """ Parses the given file.
        """
        case = Case()
        file.seek(0)
        case.base_mva = float(file.next().split(",")[1].split("/")[0])
        case.name = "%s %s" % (file.next().strip(), file.next().strip())

        bustype_map = {1: "PQ", 2: "PV", 3: "ref", 4: "isolated"}

        # I, 'NAME', BASKV, IDE, GL, BL, AREA, ZONE, VM, VA, OWNER
        bus_data = file.next().split(",")
        while bus_data[0].strip()[0] != "0":
            bus = Bus()
            i = int(bus_data[0].strip())
            self.bus_map[i] = bus
            bus._i = i
            bus.name = bus_data[1].strip("'").strip()
            bus.v_base = float(bus_data[2])
            bus.type = bustype_map[int(bus_data[3])]
            bus.g_shunt = float(bus_data[4])
            bus.b_shunt = float(bus_data[5])
            bus.v_magnitude = float(bus_data[8])
            bus.v_angle = float(bus_data[9])
            case.buses.append(bus)
            bus_data = file.next().split(",")

        # I, ID, STATUS, AREA, ZONE, PL, QL, IP, IQ, YP, YQ, OWNER
        load_data = file.next().split(",")
        while load_data[0].strip()[0] != "0":
            bus = self.bus_map[int(load_data[0].strip())]
            bus.p_demand += float(load_data[5])
            bus.q_demand += float(load_data[6])
            load_data = file.next().split(",")

        #I,ID,PG,QG,QT,QB,VS,IREG,MBASE,ZR,ZX,RT,XT,GTAP,STAT,RMPCT,PT,PB,O1,F1
        gen_data = file.next().split(",")
        while gen_data[0].strip()[0] != "0":
            bus = self.bus_map[int(gen_data[0].strip())]
            g = Generator(bus)
            g.p = float(gen_data[2])
            g.q = float(gen_data[3])
            g.q_max = float(gen_data[4])
            g.q_min = float(gen_data[5])
            g.v_magnitude = float(gen_data[6])
            g.base_mva = float(gen_data[8])
            g.online = bool(int(gen_data[14]))
            g.p_max = float(gen_data[16])
            g.p_min = float(gen_data[17])
            case.generators.append(g)
            gen_data = file.next().split(",")

        # I,J,CKT,R,X,B,RATEA,RATEB,RATEC,GI,BI,GJ,BJ,ST,LEN,O1,F1,...,O4,F4
        branch_data = file.next().split(",")
        while branch_data[0].strip()[0] != "0":
            from_bus = self.bus_map[abs(int(branch_data[0]))]
            to_bus = self.bus_map[abs(int(branch_data[1]))]
            l = Branch(from_bus, to_bus)
            l.r = float(branch_data[3])
            l.x = float(branch_data[4])
            l.b = float(branch_data[5])
            l.rate_a = float(branch_data[6])
            l.rate_b = float(branch_data[7])
            l.rate_c = float(branch_data[8])
            #            l.online = bool(int(branch_data[13]))
            case.branches.append(l)
            branch_data = file.next().split(",")

        # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
        # R1-2,X1-2,SBASE1-2
        # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
        # WINDV2,NOMV2
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            trx_data2 = file.next().split(",")
            trx_data3 = file.next().split(",")
            trx_data4 = file.next().split(",")  # second winding
            if len(trx_data2) < 5:
                from_bus = self.bus_map[abs(int(trx_data[0]))]
                to_bus = self.bus_map[abs(int(trx_data[1]))]
                l = Branch(from_bus, to_bus)
                l.name = trx_data[10].strip("'").strip()
                l.online = bool(int(trx_data[11]))
                l.b = float(trx_data[8])
                l.r = float(trx_data2[0])
                l.x = float(trx_data2[1])
                l.ratio = float(trx_data3[0])
                l.phase_shift = float(trx_data3[2])
                rate_a = float(trx_data3[3])
                if rate_a != 0.0:
                    l.rate_a = rate_a
                rate_b = float(trx_data3[4])
                if rate_b != 0.0:
                    l.rate_b = rate_b
                rate_c = float(trx_data3[5])
                if rate_c != 0.0:
                    l.rate_c = rate_c
                case.branches.append(l)
                trx_data = file.next().split(",")
            else:
                # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
                # R1-2,X1-2,SBASE1-2,R2-3,X2-3,SBASE2-3,R3-1,X3-1,SBASE3-1,VMSTAR,ANSTAR
                # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
                # WINDV2,NOMV2,ANG2,RATA2,RATB2,RATC2,COD2,CONT2,RMA2,RMI2,VMA2,VMI2,NTP2,TAB2,CR2,CX2
                # WINDV3,NOMV3,ANG3,RATA3,RATB3,RATC3,COD3,CONT3,RMA3,RMI3,VMA3,VMI3,NTP3,TAB3,CR3,CX3

                trx_data5 = file.next().split(",")  # third winding
                # Three-winding transformers are modelled as a group of three
                # two-winding transformers with a fictitious neutral bus.
                tmp_bus = Bus()
                tmp_bus.name = "n" + tmp_bus.name
                tmp_bus._i = len(case.buses) + 1

                bus1 = self.bus_map[abs(int(trx_data[0]))]
                bus2 = self.bus_map[abs(int(trx_data[1]))]
                bus3 = self.bus_map[abs(int(trx_data[2]))]
                l1 = Branch(tmp_bus, bus1)
                l2 = Branch(tmp_bus, bus2)
                l3 = Branch(tmp_bus, bus3)

                b = float(trx_data[8])  # MAG2
                l1.b = b  # / 3.0
                #                l2.b = b / 3.0
                #                l3.b = b / 3.0

                on = bool(int(trx_data[11]))
                l1.online = on
                l2.online = on
                l3.online = on

                r12 = float(trx_data2[0])
                x12 = float(trx_data2[1])
                r23 = float(trx_data2[3])
                x23 = float(trx_data2[4])
                r31 = float(trx_data2[6])
                x31 = float(trx_data2[7])

                l1.r = 0.5 * (r12 + r31 - r23)
                l1.x = 0.5 * (x12 + x31 - x23)
                l2.r = 0.5 * (r12 + r23 - r31)
                l2.x = 0.5 * (x12 + x23 - x31)
                l3.r = 0.5 * (r23 + r31 - r12)
                l3.x = 0.5 * (x23 + x31 - x12)

                for l in [l1, l2, l3]:
                    if abs(l.x) < 1e-5:
                        logger.warning("Zero branch reactance [%s]." % l.name)
                        l.x = self.xtol
                    if abs(complex(l.r, l.x)) < 0.00001:
                        logger.warning("Zero branch impedance [%s]." % l.name)

                l1.ratio = float(trx_data3[0])
                l1.phase_shift = float(trx_data3[2])
                l2.ratio = float(trx_data4[0])
                l2.phase_shift = float(trx_data4[2])
                l3.ratio = float(trx_data5[0])
                l3.phase_shift = float(trx_data5[2])

                rate_a1 = float(trx_data3[3])
                rate_b1 = float(trx_data3[4])
                rate_c1 = float(trx_data3[5])
                if rate_a1 > 0.0:
                    l1.rate_a = rate_a1
                if rate_b1 > 0.0:
                    l1.rate_b = rate_b1
                if rate_c1 > 0.0:
                    l1.rate_c = rate_c1

                rate_a2 = float(trx_data4[3])
                rate_b2 = float(trx_data4[4])
                rate_c2 = float(trx_data4[5])
                if rate_a2 > 0.0:
                    l2.rate_a = rate_a2
                if rate_b2 > 0.0:
                    l2.rate_b = rate_b2
                if rate_c2 > 0.0:
                    l2.rate_c = rate_c2

                rate_a3 = float(trx_data5[3])
                rate_b3 = float(trx_data5[4])
                rate_c3 = float(trx_data5[5])
                if rate_a3 > 0.0:
                    l3.rate_a = rate_a3
                if rate_b2 > 0.0:
                    l3.rate_b = rate_b3
                if rate_c2 > 0.0:
                    l3.rate_c = rate_c3

                case.buses.append(tmp_bus)
                case.branches.append(l1)
                case.branches.append(l2)
                case.branches.append(l3)

                trx_data = file.next().split(",")

        # Area interchange data.
        # I, ISW, PDES, PTOL, 'ARNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring area interchange data.")
            trx_data = file.next().split(",")

        # Two-terminal DC line data.
        # I,MDC,RDC,SETVL,VSCHD,VCMOD,RCOMP,DELTI,METER,DCVMIN,CCCITMX,CCCACC
        # IPR,NBR,ALFMX,ALFMN,RCR,XCR,EBASR,TRR,TAPR,TMXR,TMNR,STPR,ICR,IFR,ITR,IDR,XCAPR
        # IPI,NBI,GAMMX,GAMMN,RCI,XCI,EBASI,TRI,TAPI,TMXI,TMNI,STPI,ICI,IFI,ITI,IDI,XCAPI
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring two-terminal DC line data.")
            trx_data = file.next().split(",")

        # VSC DC line data.
        # 'NAME', MDC, RDC, O1, F1, ... O4, F4
        # IBUS,TYPE,MODE,DOCET,ACSET,ALOSS,BLOSS,MINOSS,SMAX,IMAX,PWF,MAXQ,MINQ,
        # REMOT,RMPCT
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring VSC DC line data.")
            trx_data = file.next().split(",")

        # Switched shunt data.
        # I,MODSW,VSWHI,VSWLO,SWREM,RMPCT,'RMIDNT',BINIT,N1,B1,N2,B2,...N8,B8
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            bus = self.bus_map[abs(int(trx_data[0]))]
            bus.b_shunt += float(trx_data[7])
            trx_data = file.next().split(",")

        # Transformer impedance correction table.
        # I, T1, F1, T2, F2, T3, F3, ... T11, F11
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring transformer X correction table data.")
            trx_data = file.next().split(",")

        # Multi-terminal dc line data.
        # I, NCONV, NDCBS, NDCLN, MDC, VCONV, VCMOD, VCONVN
        # IB,N,ANGMX,ANGMN,RC,XC,EBAS,TR,TAP,TPMX,TPMN,TSTP,SETVL,DCPF,MARG,CNVCOD
        # IDC, IB, IA, ZONE, 'NAME', IDC2, RGRND, OWNER
        # IDC, JDC, DCCKT, RDC, LDC
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multi-terminal dc line data.")
            trx_data = file.next().split(",")

        # Multisection line data.
        # I,J,ID,DUM1,DUM2,...DUM9
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multisection line data.")
            trx_data = file.next().split(",")

        # Zone data.
        # I,'ZONAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring zone data.")
            trx_data = file.next().split(",")

        # Interarea transfer data.
        # ARFROM, ARTO, TRID, PTRAN
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring interarea transfer data.")
            trx_data = file.next().split(",")

        # Owner data.
        # I,'OWNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring owner data.")
            trx_data = file.next().split(",")

        # FACTS device data.
        # N,I,J,MODE,PDES,QDES,VSET,SHMX,TRMX,VTMN,VTMX,VSMX,IMX,LINX,RMPCT,OWNER,SET1,SET2,VSREF
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring FACTS device data.")
            trx_data = file.next().split(",")

        return case
Exemplo n.º 10
0
    def push_line(self, tokens):
        """ Adds a Branch object to the case.
        """
        logger.debug("Pushing line data: %s" % tokens)

        from_bus = self.case.buses[tokens["fbus"] - 1]
        to_bus = self.case.buses[tokens["tbus"] - 1]

        e = Branch(from_bus=from_bus, to_bus=to_bus)
        e.r = tokens["r"]
        e.x = tokens["x"]
        e.b = tokens["b"]
        e.rate_a = tokens["s_limit"]
        e.rate_b = tokens["p_limit"]
        e.rate_c = tokens["i_limit"]
        # Optional parameter
        if tokens["tap"] == 0:  #Transmission line
            e.ratio = 1.0
        else:  # Transformer
            e.ratio = tokens["tap"]
        e.phase_shift = tokens["shift"]
        # Optional parameter
        #        if "status" in tokens.keys:
        #        e.online = tokens["status"]

        self.case.branches.append(e)
Exemplo n.º 11
0
    def test_reset(self):
        """ Test initialisation of bus result attributes.
        """
        branch = Branch(Bus(), Bus())

        branch.p_from = 25.0
        branch.p_to = -25.0
        branch.q_from = -9.0
        branch.q_to = 9.0
        branch.mu_s_from = 90.0
        branch.mu_s_to = 0.0
        branch.mu_angmin = 60.0
        branch.mu_angmax = 0.0

        branch.reset()

        self.assertEqual(branch.p_from, 0.0)
        self.assertEqual(branch.p_to, 0.0)
        self.assertEqual(branch.q_from, 0.0)
        self.assertEqual(branch.q_to, 0.0)
        self.assertEqual(branch.mu_s_from, 0.0)
        self.assertEqual(branch.mu_s_to, 0.0)
        self.assertEqual(branch.mu_angmin, 0.0)
        self.assertEqual(branch.mu_angmax, 0.0)
Exemplo n.º 12
0
Arquivo: psse.py Projeto: ZiiCee/pylon
    def _parse_file(self, file):
        """ Parses the given file.
        """
        case = Case()
        file.seek(0)
        case.base_mva = float(file.next().split(",")[1].split("/")[0])
        case.name = "%s %s" % (file.next().strip(), file.next().strip())

        bustype_map = {1: "PQ", 2: "PV", 3: "ref", 4: "isolated"}

        # I, 'NAME', BASKV, IDE, GL, BL, AREA, ZONE, VM, VA, OWNER
        bus_data = file.next().split(",")
        while bus_data[0].strip()[0] != "0":
            bus = Bus()
            i = int(bus_data[0].strip())
            self.bus_map[i] = bus
            bus._i = i
            bus.name = bus_data[1].strip("'").strip()
            bus.v_base = float(bus_data[2])
            bus.type = bustype_map[int(bus_data[3])]
            bus.g_shunt = float(bus_data[4])
            bus.b_shunt = float(bus_data[5])
            bus.v_magnitude = float(bus_data[8])
            bus.v_angle = float(bus_data[9])
            # bus.area = 1;  # hcui7 added
            case.buses.append(bus)
            bus_data = file.next().split(",")

        # I, ID, STATUS, AREA, ZONE, PL, QL, IP, IQ, YP, YQ, OWNER
        load_data = file.next().split(",")
        while load_data[0].strip()[0] != "0":
            bus = self.bus_map[int(load_data[0].strip())]
            bus.p_demand += float(load_data[5])
            bus.q_demand += float(load_data[6])
            load_data = file.next().split(",")

        # I,ID,PG,QG,QT,QB,VS,IREG,MBASE,ZR,ZX,RT,XT,GTAP,STAT,RMPCT,PT,PB,O1,F1
        gen_data = file.next().split(",")
        while gen_data[0].strip()[0] != "0":
            bus = self.bus_map[int(gen_data[0].strip())]
            g = Generator(bus)
            g.p = float(gen_data[2])
            g.q = float(gen_data[3])
            g.q_max = float(gen_data[4])
            g.q_min = float(gen_data[5])
            g.v_magnitude = float(gen_data[6])
            g.base_mva = float(gen_data[8])
            g.online = bool(int(gen_data[14]))
            g.p_max = float(gen_data[16])
            g.p_min = float(gen_data[17])
            case.generators.append(g)
            gen_data = file.next().split(",")

        # I,J,CKT,R,X,B,RATEA,RATEB,RATEC,GI,BI,GJ,BJ,ST,LEN,O1,F1,...,O4,F4
        branch_data = file.next().split(",")
        while branch_data[0].strip()[0] != "0":
            from_bus = self.bus_map[abs(int(branch_data[0]))]
            to_bus = self.bus_map[abs(int(branch_data[1]))]
            l = Branch(from_bus, to_bus)
            l.r = float(branch_data[3])
            l.x = float(branch_data[4])
            l.b = float(branch_data[5])
            l.rate_a = float(branch_data[6])
            l.rate_b = float(branch_data[7])
            l.rate_c = float(branch_data[8])
            #            l.online = bool(int(branch_data[13]))
            case.branches.append(l)
            branch_data = file.next().split(",")

        # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
        # R1-2,X1-2,SBASE1-2
        # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
        # WINDV2,NOMV2
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            trx_data2 = file.next().split(",")
            trx_data3 = file.next().split(",")
            trx_data4 = file.next().split(",")  # second winding
            if len(trx_data2) < 5:
                from_bus = self.bus_map[abs(int(trx_data[0]))]
                to_bus = self.bus_map[abs(int(trx_data[1]))]
                l = Branch(from_bus, to_bus)
                l.name = trx_data[10].strip("'").strip()
                l.online = bool(int(trx_data[11]))
                l.b = float(trx_data[8])
                l.r = float(trx_data2[0])
                l.x = float(trx_data2[1])
                l.ratio = float(trx_data3[0])
                l.phase_shift = float(trx_data3[2])
                rate_a = float(trx_data3[3])
                if rate_a != 0.0:
                    l.rate_a = rate_a
                rate_b = float(trx_data3[4])
                if rate_b != 0.0:
                    l.rate_b = rate_b
                rate_c = float(trx_data3[5])
                if rate_c != 0.0:
                    l.rate_c = rate_c
                case.branches.append(l)
                trx_data = file.next().split(",")
            else:
                # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
                # R1-2,X1-2,SBASE1-2,R2-3,X2-3,SBASE2-3,R3-1,X3-1,SBASE3-1,VMSTAR,ANSTAR
                # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
                # WINDV2,NOMV2,ANG2,RATA2,RATB2,RATC2,COD2,CONT2,RMA2,RMI2,VMA2,VMI2,NTP2,TAB2,CR2,CX2
                # WINDV3,NOMV3,ANG3,RATA3,RATB3,RATC3,COD3,CONT3,RMA3,RMI3,VMA3,VMI3,NTP3,TAB3,CR3,CX3

                trx_data5 = file.next().split(",")  # third winding
                # Three-winding transformers are modelled as a group of three
                # two-winding transformers with a fictitious neutral bus.
                tmp_bus = Bus()
                tmp_bus.name = "n" + tmp_bus.name
                tmp_bus._i = len(case.buses) + 1

                bus1 = self.bus_map[abs(int(trx_data[0]))]
                bus2 = self.bus_map[abs(int(trx_data[1]))]
                bus3 = self.bus_map[abs(int(trx_data[2]))]
                l1 = Branch(tmp_bus, bus1)
                l2 = Branch(tmp_bus, bus2)
                l3 = Branch(tmp_bus, bus3)

                b = float(trx_data[8])  # MAG2
                l1.b = b  # / 3.0
                #                l2.b = b / 3.0
                #                l3.b = b / 3.0

                on = bool(int(trx_data[11]))
                l1.online = on
                l2.online = on
                l3.online = on

                r12 = float(trx_data2[0])
                x12 = float(trx_data2[1])
                r23 = float(trx_data2[3])
                x23 = float(trx_data2[4])
                r31 = float(trx_data2[6])
                x31 = float(trx_data2[7])

                l1.r = 0.5 * (r12 + r31 - r23)
                l1.x = 0.5 * (x12 + x31 - x23)
                l2.r = 0.5 * (r12 + r23 - r31)
                l2.x = 0.5 * (x12 + x23 - x31)
                l3.r = 0.5 * (r23 + r31 - r12)
                l3.x = 0.5 * (x23 + x31 - x12)

                for l in [l1, l2, l3]:
                    if abs(l.x) < 1e-5:
                        logger.warning("Zero branch reactance [%s]." % l.name)
                        l.x = self.xtol
                    if abs(complex(l.r, l.x)) < 0.00001:
                        logger.warning("Zero branch impedance [%s]." % l.name)

                l1.ratio = float(trx_data3[0])
                l1.phase_shift = float(trx_data3[2])
                l2.ratio = float(trx_data4[0])
                l2.phase_shift = float(trx_data4[2])
                l3.ratio = float(trx_data5[0])
                l3.phase_shift = float(trx_data5[2])

                rate_a1 = float(trx_data3[3])
                rate_b1 = float(trx_data3[4])
                rate_c1 = float(trx_data3[5])
                if rate_a1 > 0.0:
                    l1.rate_a = rate_a1
                if rate_b1 > 0.0:
                    l1.rate_b = rate_b1
                if rate_c1 > 0.0:
                    l1.rate_c = rate_c1

                rate_a2 = float(trx_data4[3])
                rate_b2 = float(trx_data4[4])
                rate_c2 = float(trx_data4[5])
                if rate_a2 > 0.0:
                    l2.rate_a = rate_a2
                if rate_b2 > 0.0:
                    l2.rate_b = rate_b2
                if rate_c2 > 0.0:
                    l2.rate_c = rate_c2

                rate_a3 = float(trx_data5[3])
                rate_b3 = float(trx_data5[4])
                rate_c3 = float(trx_data5[5])
                if rate_a3 > 0.0:
                    l3.rate_a = rate_a3
                if rate_b2 > 0.0:
                    l3.rate_b = rate_b3
                if rate_c2 > 0.0:
                    l3.rate_c = rate_c3

                case.buses.append(tmp_bus)
                case.branches.append(l1)
                case.branches.append(l2)
                case.branches.append(l3)

                trx_data = file.next().split(",")

        # Area interchange data.
        # I, ISW, PDES, PTOL, 'ARNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring area interchange data.")
            trx_data = file.next().split(",")

        # Two-terminal DC line data.
        # I,MDC,RDC,SETVL,VSCHD,VCMOD,RCOMP,DELTI,METER,DCVMIN,CCCITMX,CCCACC
        # IPR,NBR,ALFMX,ALFMN,RCR,XCR,EBASR,TRR,TAPR,TMXR,TMNR,STPR,ICR,IFR,ITR,IDR,XCAPR
        # IPI,NBI,GAMMX,GAMMN,RCI,XCI,EBASI,TRI,TAPI,TMXI,TMNI,STPI,ICI,IFI,ITI,IDI,XCAPI
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring two-terminal DC line data.")
            trx_data = file.next().split(",")

        # VSC DC line data.
        # 'NAME', MDC, RDC, O1, F1, ... O4, F4
        # IBUS,TYPE,MODE,DOCET,ACSET,ALOSS,BLOSS,MINOSS,SMAX,IMAX,PWF,MAXQ,MINQ,
        # REMOT,RMPCT
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring VSC DC line data.")
            trx_data = file.next().split(",")

        # Switched shunt data.
        # I,MODSW,VSWHI,VSWLO,SWREM,RMPCT,'RMIDNT',BINIT,N1,B1,N2,B2,...N8,B8
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            bus = self.bus_map[abs(int(trx_data[0]))]
            bus.b_shunt += float(trx_data[7])
            trx_data = file.next().split(",")

        # Transformer impedance correction table.
        # I, T1, F1, T2, F2, T3, F3, ... T11, F11
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring transformer X correction table data.")
            trx_data = file.next().split(",")

        # Multi-terminal dc line data.
        # I, NCONV, NDCBS, NDCLN, MDC, VCONV, VCMOD, VCONVN
        # IB,N,ANGMX,ANGMN,RC,XC,EBAS,TR,TAP,TPMX,TPMN,TSTP,SETVL,DCPF,MARG,CNVCOD
        # IDC, IB, IA, ZONE, 'NAME', IDC2, RGRND, OWNER
        # IDC, JDC, DCCKT, RDC, LDC
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multi-terminal dc line data.")
            trx_data = file.next().split(",")

        # Multisection line data.
        # I,J,ID,DUM1,DUM2,...DUM9
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multisection line data.")
            trx_data = file.next().split(",")

        # Zone data.
        # I,'ZONAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring zone data.")
            trx_data = file.next().split(",")

        # Interarea transfer data.
        # ARFROM, ARTO, TRID, PTRAN
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring interarea transfer data.")
            trx_data = file.next().split(",")

        # Owner data.
        # I,'OWNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring owner data.")
            trx_data = file.next().split(",")

        # FACTS device data.
        # N,I,J,MODE,PDES,QDES,VSET,SHMX,TRMX,VTMN,VTMX,VSMX,IMX,LINX,RMPCT,OWNER,SET1,SET2,VSREF
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring FACTS device data.")
            trx_data = file.next().split(",")

        return case