# SEL-421 Directional Elements
#------------- User Settings -------------
visible CTR = 160
visible CTRN = 160
visible PTR = 1200
visible Z1MAG = 1.5
visible Z1ANG = 79.29
visible Z0ANG = 74.53
visible Z2F = 0
visible Z2R = .1
visible Z0F = 0
visible Z0R = .1
visible INMTA = 60
visible Channel_IX_Nominal = 5
visible Channel_IW_Nominal = 5
visible IN.Phasor = 1
visible Z_Limit = 5
#------------- Definitions -------------
# Assign Phasors to Secondary Variables
# Modify Phasor assignments for other relay models as necessary
V1_SEC = V1.Phasor * 1000 / PTR
V2_SEC = V2.Phasor * 1000 / PTR
V0_SEC = V0.Phasor * 1000 / PTR
V1MEM_SEC = V1MEM.Phasor * 1000 / PTR
I1_SEC = I1.Phasor / CTR
I2_SEC = I2.Phasor / CTR
I0_SEC = I0.Phasor / CTR
IN_SEC = IN.Phasor / CTRN
IA_SEC = IA.Phasor / CTR
IB_SEC = IB.Phasor / CTR
IC_SEC = IC.Phasor / CTR
#------------- Equations -------------
# Equations - Positive-Sequence Directional Element - Denominator Check
# All Phase - Phase Elements Forward / Reverse
#
Complex_A=COMPLEX_MA(1,-120)
VPOLVa = (V1MEM_SEC)
VPOLVb = (V1MEM_SEC) * Complex_A
VPOLVc = (V1MEM_SEC) * Complex_A * Complex_A
MABD = Real((Complex_MA(1, Z1ANG) * (IA_SEC - IB_SEC) * Conj(VPOLVa - VPOLVb)))+.00001
MBCD = Real((Complex_MA(1, Z1ANG) * (IB_SEC - IC_SEC) * conj(VPOLVb - VPOLVc)))+.00001
MCAD = Real((Complex_MA(1, Z1ANG) * (IC_SEC - IA_SEC) * conj(VPOLVc - VPOLVa)))+.00001
#
# Equations - Positive-Sequence Directional Element - Angle Check
# Plots Z1 in secondary ohms
Z1 = V1_SEC / I1_SEC
Z1AngT1.Phasor = Complex_MA(1,90+Z1Ang)
Z1AngT2.Phasor = Complex_MA(1, 270+Z1Ang)
#
# Equations - Negative-Sequence Voltage-Polarized Directional Element
# Plots Z2 in secondary ohms
Z2 = (Real((V2_SEC) * (conj(I2_SEC * (complex_ma(1,Z1ANG)))))) / (Mag(I2_SEC) * Mag(I2_SEC))
Z2FT = If((Z2F <= 0),(.75 * Z2F - .25 * mag(V2_SEC / I2_SEC)),(1.25 * Z2F - .25 * mag(V2_SEC / I2_SEC)))
Z2RT = If((Z2R >= 0),(.75 * Z2R + .25 * mag(V2_SEC / I2_SEC)),(1.25 * Z2R + .25 * mag(v2_SEC / I2_SEC)))
# To create Limits to help with Y axis auto scale - in this case limited to -5 to +5
Z2LIM = limit(Z2,-Z_Limit,Z_Limit)
Z2FTLIM = Limit(Z2FT,-Z_Limit, Z_Limit)
Z2RTLIM = Limit(Z2Rt,-Z_Limit, Z_Limit)
#
# Equations - Zero-Sequence Voltage-Polarized Direction Element
# Plots Z0 in secondary ohms
Z0 = (Real((V0_SEC * 3) * (conj(3 * I0_SEC * (complex_ma(1,Z0ANG)))))) / (Mag(3*I0_SEC) * Mag(3*I0_SEC))
Z0FT = If((Z0F <= 0),(.75 * Z0F - .25 * mag(V0_SEC / I0_SEC)),(1.25 * Z0F - .25 * mag(V0_SEC / I0_SEC)))
Z0RT = If((Z0R >= 0),(.75 * Z0R + .25 * mag(V0_SEC / I0_SEC)),(1.25 * Z0R + .25 * mag(V0_SEC / I0_SEC)))
#To create Limits to help with Y axis auto scale - in this case limited to -5 to +5
Z0LIM = limit(Z0,-Z_Limit,Z_Limit)
Z0FTLIM = Limit(Z0FT,-Z_Limit, Z_Limit)
Z0RTLIM = Limit(Z0Rt,-Z_Limit, Z_Limit)
#
# Equations - Channel IN Current-Polarized Directional Element
I0Dir = (Real(((I0_SEC * 3) / CTR) * (conj(IN_SEC * (complex_ma(1,INMTA))))))
I0DirFT = Channel_Ix_Nominal * Channel_Iw_Nominal * .01
I0DirRT = -(Channel_Ix_Nominal * Channel_Iw_Nominal * .01)
#To create Limits to help with Y axis auto scale - in this case limited to -5 to +5
I0DirLIM = limit(I0Dir,-Z_Limit,Z_Limit)
I0DirFTLIM = Limit(I0DirFT,-Z_Limit, Z_Limit)
I0DirRTLIM = Limit(I0DirRt,-Z_Limit, Z_Limit)
