def __init__(self,from_bus=Bus3(),to_bus=Bus3(),voltregs=[],yt=0,base_mva= 1.0,base_kv=12.0,case_base_mva=1.0,case_base_kv=12.0,E_high= 12.47, E_low=4.16, type_connection='YgYg',type='Step-Down'):
        Line3.__init__(self,from_bus,to_bus)
        #print voltregs
#        self.Z=zeros([3,3])
        self.voltrega=voltregs[0]
        self.voltregb=voltregs[1]
        self.voltregc=voltregs[2]
        self.voltregs=[self.voltrega, self.voltregb, self.voltregc]
        self.from_bus=from_bus
        self.to_bus=to_bus
        self.line_a=eye(3)
        self.line_b=zeros([3,3])
        self.line_c=zeros([3,3])
        self.line_d=zeros([3,3])
        self.line_A=inv(self.line_a)
        self.line_B=dot(inv(self.line_a),self.line_b)
        # attaching voltregs to buses
        ## from_bus
        self.voltrega.from_bus=self.from_bus.Busa
        self.voltregb.from_bus=self.from_bus.Busb
        self.voltregc.from_bus=self.from_bus.Busc
        ## to_bus
        self.voltrega.to_bus=self.to_bus.Busa
        self.voltregb.to_bus=self.to_bus.Busb
        self.voltregc.to_bus=self.to_bus.Busc
        self.a_R=eye(3)
        self.A_R=eye(3)
        self.d_R=zeros([3,3])
        self.Taps=zeros(3)
        self.base_mva=base_mva*ones(3)
        self.base_kv=base_kv*ones(3)
        self.base_A=self.base_mva*1000./(self.base_kv)
        self.childrenBuses=[] # buses influenced by change of taps. They are all nodes connected to self.to_bus. until a transformer is found.
 def __init__(self,
              from_bus=Bus3(),
              to_bus=Bus3(),
              voltregs=[],
              yt=0,
              base_mva=1.0,
              base_kv=12.0,
              case_base_mva=1.0,
              case_base_kv=12.0,
              E_high=12.47,
              E_low=4.16,
              type_connection='YgYg',
              type='Step-Down'):
     Line3.__init__(self, from_bus, to_bus)
     #print voltregs
     #        self.Z=zeros([3,3])
     self.voltrega = voltregs[0]
     self.voltregb = voltregs[1]
     self.voltregc = voltregs[2]
     self.voltregs = [self.voltrega, self.voltregb, self.voltregc]
     self.from_bus = from_bus
     self.to_bus = to_bus
     self.line_a = eye(3)
     self.line_b = zeros([3, 3])
     self.line_c = zeros([3, 3])
     self.line_d = zeros([3, 3])
     self.line_A = inv(self.line_a)
     self.line_B = dot(inv(self.line_a), self.line_b)
     # attaching voltregs to buses
     ## from_bus
     self.voltrega.from_bus = self.from_bus.Busa
     self.voltregb.from_bus = self.from_bus.Busb
     self.voltregc.from_bus = self.from_bus.Busc
     ## to_bus
     self.voltrega.to_bus = self.to_bus.Busa
     self.voltregb.to_bus = self.to_bus.Busb
     self.voltregc.to_bus = self.to_bus.Busc
     self.a_R = eye(3)
     self.A_R = eye(3)
     self.d_R = zeros([3, 3])
     self.Taps = zeros(3)
     self.base_mva = base_mva * ones(3)
     self.base_kv = base_kv * ones(3)
     self.base_A = self.base_mva * 1000. / (self.base_kv)
     self.childrenBuses = [
     ]  # buses influenced by change of taps. They are all nodes connected to self.to_bus. until a transformer is found.
    def __init__(self,from_bus=Bus3(),to_bus=Bus3(),yt=0,base_mva= 1.0,base_kv=12.0,case_base_mva=1.0,case_base_kv=12.0,E_high= 12.47, E_low=4.16, type_connection='YgYg',type='Step-Down',ps=0, alpha=1.0,beta=1.0 ):
        Line3.__init__(self,from_bus,to_bus)
        # constants
        self.YI=eye(3)*yt#
        self.YII=array([[2.,-1.,-1.],[-1.,2.,-1.],[-1.,-1.,2.]])*yt/3.
        self.YIII=array([[-1.,1.,0.],[0.,-1.,1.],[1.,0.,-1.]])*yt/sqrt(3.0)
        self.YIV=array([[1.,-1.,0.],[-1.,2.,-1.],[0.,-1.,1.]])*yt/3.
        self.YV=array([[-1.,1.,0.],[0.,-1.,1.],[0.,0.,0.]])*yt/sqrt(3.0)
        self.YVI=array([[1.,0.,0.],[0.,1.,0.],[0.,0.,0.]])*yt
        self.type=type
        self.yt=yt
	self.Yabc=self.YI.copy()# phase admitance matrix
	self.Zabc=inv(self.Yabc) # phase impedance matrix
	self.Z012=dot(dot(P,self.Zabc),Pinv)
        self.type_connection=type_connection
        self.base_mva=base_mva
        self.base_kv=base_kv
        self.E_high=E_high
        self.E_low=E_low
        self.E_from0=0.0 # set initial zero sequence voltage to 0.
        #self.to_bus.base_kv=self.from_bus.base_kv*self.E_low*sqrt(3)/(self.E_high)
        self.ps=ps # how much is secondary side voltage is shifted in radians
        
        # It is important to remember that in the following models, YD connection 
        # will INCREASE phase angle by 30 degrees when we move from Y side to D side.
        # this is a DEFAULT mode named POSITIVE MODE
        
        # When I evaluate the 4 bus feeder test case provided by IEEE, I have found 
        # that It follow reverse convention. In other words, as we move from Y to D
        # side, phase angle are DECREASED by 30 degrees.
        # This is named NEGATIVE MODE
        if self.type_connection=='YgYg': # tested. there are more to model
            self.Ypp=self.YI.copy()
            self.Yps=-self.YI.copy()
            self.Ysp=-self.YI.copy()
            self.Yss=self.YI.copy()
        if self.type_connection=='YgY':
            self.Ypp=self.YII.copy()
            self.Yps=-self.YII.copy()
            self.Ysp=-self.YII.copy()
            self.Yss=self.YII.copy()
        if self.type_connection=='YgD':
            self.Ypp=self.YI.copy()
            self.Yps=self.YIII.copy()
            self.Ysp=self.YIII.transpose().copy()
            self.Yss=self.YII.copy()
        if self.type_connection=='YD':
            self.Ypp=self.YII.copy()
            self.Yps=self.YIII.copy()
            self.Ysp=self.YIII.transpose().copy()
            self.Yss=self.YII.copy()
        if self.type_connection=='DYg':
            self.Ypp=self.YII.copy()
            self.Yps=self.YIII.copy()
            self.Ysp=self.YIII.transpose().copy()
            self.Yss=self.YI.copy()
        if self.type_connection=='DD':
            self.Ypp=self.YII.copy()
            self.Yps=-self.YII.copy()
            self.Ysp=-self.YII.transpose().copy()
            self.Yss=self.YI.copy()
            #print 
        if self.type_connection=='UV':
            self.Ypp=self.YVI.copy()
            self.Yps=self.YV.copy()
            self.Ysp=self.Yps.transpose().copy()
            self.Yss=self.YIV.copy()
        if type=='Step-Up':
            self.reverseMode()
        self.calculateSubmatrices()
gen3 = Generator3(bus5, type='PV')
gen2.updateS(ones(3) * (.01 + 0.00j))
gen3.updateS(ones(3) * (.0 + 0.01j))
gen3.E = gen3.E
# Load at bus5
bus5.loads = [load1]

# line data
# from substation to transfomer
zd = array([[0.1414 + 1j * 0.5353, 0.0361 + 1j * 0.3225, 0.0361 + 1j * 0.2752],
            [0.0361 + 1j * 0.3225, 0.1414 + 1j * 0.5353, 0.0361 + 1j * 0.2955],
            [0.0361 + 1j * 0.2752, 0.0361 + 1j * 0.2955,
             0.1414 + 1j * 0.5353]])  # Ohm
#zd=eye(3,3)
Z1 = zd / (Zbase)
branch1 = Line3(bus1, bus2, Z1)

#transformer data
t_connection = 'Step-Down'
t_MVA = 6.0
t_kVLL_high = 12.47
t_zbase = t_kVLL_high**2 / t_MVA
t_kVLL_low = 2.4 * sqrt(3)
t_R = 0.01  # pu
t_X = 0.06  # pu
t_a = (MVAbase / t_MVA) * (t_kVLL_high / kVbase)**2  # adjustment factor
t_z = (t_R + 1j * t_X) * t_a
t_y = 1 / t_z
trafo1 = Trafo3(bus2,
                busvr,
                yt=t_y,