Ejemplo n.º 1
0
    def __init__(self, system, config):
        REECA1Model.__init__(self, system, config)
        self.busrocof = DeviceFinder(
            self.busroc,
            link=self.bus,
            idx_name='bus',
        )

        self.df = ExtAlgeb(
            model='FreqMeasurement',
            src='WO_y',
            indexer=self.busrocof,
            export=False,
            info='Bus frequency deviation',
        )

        self.dfdt = ExtAlgeb(
            model='FreqMeasurement',
            src='Wf_y',
            indexer=self.busrocof,
            export=False,
            info='Bus ROCOF',
            unit='p.u.',
        )

        self.Pref.e_str += '- Kdf * dfdt - Kf * df'
Ejemplo n.º 2
0
    def __init__(self, system, config):
        ACEData.__init__(self)
        Model.__init__(self, system, config)

        self.flags.tds = True

        self.config.add(OrderedDict([('freq_model', 'BusFreq')]))
        self.config.add_extra(
            '_help', {'freq_model': 'default freq. measurement model'})
        self.config.add_extra('_alt', {'freq_model': ('BusFreq', )})

        self.area = ExtParam(model='Bus',
                             src='area',
                             indexer=self.bus,
                             export=False)

        self.busf.model = self.config.freq_model
        self.busfreq = DeviceFinder(self.busf, link=self.bus, idx_name='bus')

        self.f = ExtAlgeb(
            model='FreqMeasurement',
            src='f',
            indexer=self.busfreq,
            export=False,
            info='Bus frequency',
        )

        self.ace = Algeb(
            info='area control error',
            unit='MW (p.u.)',
            tex_name='ace',
            e_str='10 * bias * (f - 1) - ace',
        )
Ejemplo n.º 3
0
    def __init__(self, system, config):
        Model.__init__(self, system, config)
        self.group = 'DynLoad'
        self.flags.tds = True

        self.bus = ExtParam(model='PQ', src='bus', indexer=self.pq)

        self.p0 = ExtService(
            model='PQ',
            src='Ppf',
            indexer=self.pq,
            tex_name='P_0',
        )
        self.q0 = ExtService(
            model='PQ',
            src='Qpf',
            indexer=self.pq,
            tex_name='Q_0',
        )
        self.v0 = ExtService(
            model='Bus',
            src='v',
            indexer=self.bus,
            tex_name='V_0',
        )

        self.busfreq = DeviceFinder(
            u=self.busf,
            link=self.bus,
            idx_name='bus',
            info='found idx of BusFreq',
        )

        self.f = ExtAlgeb(
            model='FreqMeasurement',
            src='f',
            indexer=self.busfreq,
            tex_name='f',
        )

        self.pv0 = ConstService(v_str='u * kp/100 * p0 / (v0) ** ap ')
        self.qv0 = ConstService(v_str='u * kq/100 * q0 / (v0) ** aq ')

        self.a = ExtAlgeb(
            model='Bus',
            src='a',
            indexer=self.bus,
            tex_name=r'\theta',
            e_str='pv0 * (v ** ap) * (f ** bp)',
        )

        self.v = ExtAlgeb(
            model='Bus',
            src='v',
            indexer=self.bus,
            tex_name='V',
            e_str='qv0 * (v ** aq) * (f ** bq)',
        )
Ejemplo n.º 4
0
    def __init__(self, system, config):
        ACEData.__init__(self)
        Model.__init__(self, system, config)

        self.flags.tds = True
        self.group = 'Calculation'

        self.config.add(
            OrderedDict([
                ('freq_model', 'BusFreq'),
                ('interval', 4.0),
                ('offset', 0.0),
            ]))
        self.config.add_extra(
            '_help', {
                'freq_model': 'default freq. measurement model',
                'interval': 'sampling time interval',
                'offset': 'sampling time offset'
            })

        self.config.add_extra('_alt', {'freq_model': ('BusFreq', )})

        self.area = ExtParam(model='Bus',
                             src='area',
                             indexer=self.bus,
                             export=False)

        self.busf.model = self.config.freq_model
        self.busfreq = DeviceFinder(self.busf, link=self.bus, idx_name='bus')

        self.f = ExtAlgeb(
            model='FreqMeasurement',
            src='f',
            indexer=self.busfreq,
            export=False,
            info='Bus frequency',
        )

        self.fs = Sampling(
            self.f,
            interval=self.config.interval,
            offset=self.config.offset,
            tex_name='f_s',
            info='Sampled freq.',
        )

        self.ace = Algeb(
            info='area control error',
            unit='MW (p.u.)',
            tex_name='ace',
            e_str='10 * bias * (fs_v - 1) - ace',
        )
Ejemplo n.º 5
0
    def __init__(self, system, config):
        ACEData.__init__(self)
        Model.__init__(self, system, config)

        self.flags.tds = True
        self.group = 'Calculation'

        self.config.add(OrderedDict([
            ('freq_model', 'BusFreq'),
        ]))
        self.config.add_extra('_help', {
            'freq_model': 'default freq. measurement model',
        })
        self.config.add_extra('_alt', {'freq_model': ('BusFreq', )})

        self.area = ExtParam(model='Bus',
                             src='area',
                             indexer=self.bus,
                             export=False)

        self.busf.model = self.config.freq_model
        self.busfreq = DeviceFinder(self.busf,
                                    link=self.bus,
                                    idx_name='bus',
                                    default_model='BusFreq')

        self.imva = ConstService(v_str='1/sys_mva',
                                 info='reciprocal of system mva',
                                 tex_name='1/S_{b, sys}')

        self.f = ExtAlgeb(model='FreqMeasurement',
                          src='f',
                          indexer=self.busfreq,
                          export=False,
                          info='Bus frequency',
                          unit='p.u. (Hz)')
        self.ace = Algeb(
            info='area control error',
            unit='p.u. (MW)',
            tex_name='ace',
            e_str='10 * (bias * imva) * sys_f * (f - 1) - ace',
        )
Ejemplo n.º 6
0
    def __init__(self, system, config):
        REGCA1Model.__init__(self, system, config)
        self.pllidx = DeviceFinder(
            self.pll,
            link=self.bus,
            idx_name='bus',
            default_model='PLL1',
        )

        self.am = ExtState(model='PLL', src='am', indexer=self.pllidx)

        self.vd = Algeb(v_str='v',
                        info='d-axis voltage',
                        tex_name='V_d',
                        e_str='vd - v*cos(a - am)')

        self.vq = Algeb(v_str='0',
                        info='q-axis voltage',
                        tex_name='V_q',
                        e_str='-vq - v*sin(a - am)')

        self.Pe.e_str = '(vd * Ipout + vq * Iqout_y) - Pe'

        self.Qe.e_str = '(vd * Iqout_y - vq * Ipout) - Qe'
Ejemplo n.º 7
0
    def __init__(self, system, config):
        Model.__init__(self, system, config)
        self.flags.tds = True
        self.group = 'DG'

        self.config.add(OrderedDict((('plim', 0),
                                     )))

        self.config.add_extra('_help',
                              plim='enable input power limit check bound by [0, pmx]',
                              )
        self.config.add_extra('_tex',
                              plim='P_{lim}',
                              )
        self.config.add_extra('_alt',
                              plim=(0, 1),
                              )

        self.SWPQ = Switcher(u=self.pqflag, options=(0, 1), tex_name='SW_{PQ}', cache=True)

        self.buss = DataSelect(self.igreg, self.bus,
                               info='selected bus (bus or igreg)',
                               )

        self.busfreq = DeviceFinder(self.busf, link=self.buss, idx_name='bus')

        # --- initial values from power flow ---
        # a : bus voltage angle
        # v : bus voltage magnitude
        # p0s : active power from connected static PV generator
        # q0s : reactive power from connected static PV generator
        # pref0 : initial active power set point for the PVD1 device
        # qref0 : initial reactive power set point for the PVD1 device

        self.a = ExtAlgeb(model='Bus', src='a', indexer=self.buss, tex_name=r'\theta',
                          info='bus (or igreg) phase angle',
                          unit='rad.',
                          e_str='-Ipout_y * v * u',
                          ename='P',
                          tex_ename='P',
                          )

        self.v = ExtAlgeb(model='Bus', src='v', indexer=self.buss, tex_name='V',
                          info='bus (or igreg) terminal voltage',
                          unit='p.u.',
                          e_str='-Iqout_y * v * u',
                          ename='Q',
                          tex_ename='Q',
                          )

        self.p0s = ExtService(model='StaticGen',
                              src='p',
                              indexer=self.gen,
                              tex_name='P_{0s}',
                              info='Initial P from static gen',
                              )
        self.q0s = ExtService(model='StaticGen',
                              src='q',
                              indexer=self.gen,
                              tex_name='Q_{0s}',
                              info='Initial Q from static gen',
                              )
        # --- calculate the initial P and Q for this distributed device ---
        self.pref0 = ConstService(v_str='gammap * p0s', tex_name='P_{ref0}',
                                  info='Initial P for the PVD1 device',
                                  )
        self.qref0 = ConstService(v_str='gammaq * q0s', tex_name='Q_{ref0}',
                                  info='Initial Q for the PVD1 device',
                                  )

        # frequency measurement variable `f`
        self.f = ExtAlgeb(model='FreqMeasurement', src='f', indexer=self.busfreq, export=False,
                          info='Bus frequency', unit='p.u.',
                          )

        self.fHz = Algeb(info='frequency in Hz',
                         v_str='fn * f', e_str='fn * f - fHz',
                         unit='Hz',
                         tex_name='f_{Hz}',
                         )

        # --- frequency branch ---
        self.FL1 = Limiter(u=self.fHz, lower=self.ft0, upper=self.ft1,
                           info='Under frequency comparer', no_warn=True,
                           )
        self.FL2 = Limiter(u=self.fHz, lower=self.ft2, upper=self.ft3,
                           info='Over frequency comparer', no_warn=True,
                           )

        self.Kft01 = ConstService(v_str='1/(ft1 - ft0)', tex_name='K_{ft01}')

        self.Ffl = Algeb(info='Coeff. for under frequency',
                         v_str='FL1_zi * Kft01 * (fHz - ft0) + FL1_zu',
                         e_str='FL1_zi * Kft01 * (fHz - ft0) + FL1_zu - Ffl',
                         tex_name='F_{fl}',
                         discrete=self.FL1,
                         )

        self.Kft23 = ConstService(v_str='1/(ft3 - ft2)', tex_name='K_{ft23}')

        self.Ffh = Algeb(info='Coeff. for over frequency',
                         v_str='FL2_zl + FL2_zi * (1 + Kft23 * (ft2 - fHz))',
                         e_str='FL2_zl + FL2_zi * (1 + Kft23 * (ft2 - fHz)) - Ffh',
                         tex_name='F_{fh}',
                         discrete=self.FL2,
                         )

        self.Fdev = Algeb(info='Frequency deviation',
                          v_str='fn - fHz', e_str='fn - fHz - Fdev',
                          unit='Hz', tex_name='f_{dev}',
                          )

        self.DB = DeadBand1(u=self.Fdev, center=0.0, lower=self.fdbd, upper=0.0, gain=self.ddn,
                            info='frequency deviation deadband with gain',
                            )  # outputs   `Pdrp`
        self.DB.db.no_warn = True

        # --- Voltage flags ---
        self.VL1 = Limiter(u=self.v, lower=self.vt0, upper=self.vt1,
                           info='Under voltage comparer', no_warn=True,
                           )
        self.VL2 = Limiter(u=self.v, lower=self.vt2, upper=self.vt3,
                           info='Over voltage comparer', no_warn=True,
                           )

        self.Kvt01 = ConstService(v_str='1/(vt1 - vt0)', tex_name='K_{vt01}')

        self.Fvl = Algeb(info='Coeff. for under voltage',
                         v_str='VL1_zi * Kvt01 * (v - vt0) + VL1_zu',
                         e_str='VL1_zi * Kvt01 * (v - vt0) + VL1_zu - Fvl',
                         tex_name='F_{vl}',
                         discrete=self.VL1,
                         )

        self.Kvt23 = ConstService(v_str='1/(vt3 - vt2)', tex_name='K_{vt23}')

        self.Fvh = Algeb(info='Coeff. for over voltage',
                         v_str='VL2_zl + VL2_zi * (1 + Kvt23 * (vt2 - v))',
                         e_str='VL2_zl + VL2_zi * (1 + Kvt23 * (vt2 - v)) - Fvh',
                         tex_name='F_{vh}',
                         discrete=self.VL2,
                         )
        # --- sensed voltage with lower limit of 0.01 ---
        self.VLo = Limiter(u=self.v, lower=0.01, upper=999, no_upper=True,
                           info='Voltage lower limit (0.01) flag',
                           )

        self.vp = Algeb(tex_name='V_p',
                        info='Sensed positive voltage',
                        v_str='v * VLo_zi + 0.01 * VLo_zl',
                        e_str='v * VLo_zi + 0.01 * VLo_zl - vp',
                        )

        self.Pext0 = ConstService(info='External additional signal added to Pext',
                                  tex_name='P_{ext0}',
                                  v_str='0',
                                  )

        self.Pext = Algeb(tex_name='P_{ext}',
                          info='External power signal (for AGC)',
                          v_str='u * Pext0',
                          e_str='u * Pext0 - Pext'
                          )

        self.Pref = Algeb(tex_name='P_{ref}',
                          info='Reference power signal (for scheduling setpoint)',
                          v_str='u * pref0',
                          e_str='u * pref0 - Pref'
                          )

        self.Psum = Algeb(tex_name='P_{tot}',
                          info='Sum of P signals',
                          v_str='u * (Pext + Pref + DB_y)',
                          e_str='u * (Pext + Pref + DB_y) - Psum',
                          )  # `DB_y` is `Pdrp` (f droop)

        self.PHL = Limiter(u=self.Psum, lower=0.0, upper=self.pmx,
                           enable=self.config.plim,
                           info='limiter for Psum in [0, pmx]',
                           )

        self.Vcomp = VarService(v_str='abs(v*exp(1j*a) + (1j * xc) * (Ipout_y + 1j * Iqout_y))',
                                info='Voltage before Xc compensation',
                                tex_name='V_{comp}'
                                )

        self.Vqu = ConstService(v_str='v1 - (qref0 - qmn) / dqdv',
                                info='Upper voltage bound => qmx',
                                tex_name='V_{qu}',
                                )

        self.Vql = ConstService(v_str='v0 + (qmx - qref0) / dqdv',
                                info='Lower voltage bound => qmn',
                                tex_name='V_{ql}',
                                )

        self.VQ1 = Limiter(u=self.Vcomp, lower=self.Vql, upper=self.v0,
                           info='Under voltage comparer for Q droop',
                           no_warn=True,
                           )

        self.VQ2 = Limiter(u=self.Vcomp, lower=self.v1, upper=self.Vqu,
                           info='Over voltage comparer for Q droop',
                           no_warn=True,
                           )

        Qdrp = 'u * VQ1_zl * qmx + VQ2_zu * qmn + ' \
               'u * VQ1_zi * (qmx + dqdv *(Vqu - Vcomp)) + ' \
               'u * VQ2_zi * (dqdv * (v1 - Vcomp)) '

        self.Qdrp = Algeb(tex_name='Q_{drp}',
                          info='External power signal (for AGC)',
                          v_str=Qdrp,
                          e_str=f'{Qdrp} - Qdrp',
                          discrete=(self.VQ1, self.VQ2),
                          )

        self.Qref = Algeb(tex_name=r'Q_{ref}',
                          info='Reference power signal (for scheduling setpoint)',
                          v_str='u * qref0',
                          e_str='u * qref0 - Qref'
                          )

        self.Qsum = Algeb(tex_name=r'Q_{tot}',
                          info='Sum of Q signals',
                          v_str=f'u * (qref0 + {Qdrp})',
                          e_str='u * (Qref + Qdrp) - Qsum',
                          discrete=(self.VQ1, self.VQ2),
                          )

        self.Ipul = Algeb(info='Ipcmd before Ip hard limit',
                          v_str='(Psum * PHL_zi + pmx * PHL_zu) / vp',
                          e_str='(Psum * PHL_zi + pmx * PHL_zu) / vp - Ipul',
                          tex_name='I_{p,ul}',
                          )

        self.Iqul = Algeb(info='Iqcmd before Iq hard limit',
                          v_str='Qsum / vp',
                          e_str='Qsum / vp - Iqul',
                          tex_name='I_{q,ul}',
                          )

        # --- Ipmax, Iqmax and Iqmin ---
        Ipmaxsq = "(Piecewise((0, Le(ialim**2 - Iqcmd_y**2, 0)), ((ialim**2 - Iqcmd_y ** 2), True)))"
        Ipmaxsq0 = "(Piecewise((0, Le(ialim**2 - (u*qref0/v)**2, 0)), ((ialim**2 - (u*qref0/v) ** 2), True)))"
        self.Ipmaxsq = VarService(v_str=Ipmaxsq, tex_name='I_{pmax}^2')
        self.Ipmaxsq0 = ConstService(v_str=Ipmaxsq0, tex_name='I_{pmax0}^2')

        self.Ipmax = Algeb(v_str='(SWPQ_s1 * ialim + SWPQ_s0 * sqrt(Ipmaxsq0))',
                           e_str='(SWPQ_s1 * ialim + SWPQ_s0 * sqrt(Ipmaxsq)) - Ipmax',
                           tex_name='I_{pmax}',
                           )

        Iqmaxsq = "(Piecewise((0, Le(ialim**2 - Ipcmd_y**2, 0)), ((ialim**2 - Ipcmd_y ** 2), True)))"
        Iqmaxsq0 = "(Piecewise((0, Le(ialim**2 - (u*pref0/v)**2, 0)), ((ialim**2 - (u*pref0/v) ** 2), True)))"
        self.Iqmaxsq = VarService(v_str=Iqmaxsq, tex_name='I_{qmax}^2')
        self.Iqmaxsq0 = ConstService(v_str=Iqmaxsq0, tex_name='I_{qmax0}^2')

        self.Iqmax = Algeb(v_str='SWPQ_s0 * ialim + SWPQ_s1 * sqrt(Iqmaxsq0)',
                           e_str='SWPQ_s0 * ialim + SWPQ_s1 * sqrt(Iqmaxsq) - Iqmax',
                           tex_name='I_{qmax}',
                           )

        # TODO: set option whether to use degrading gain
        # --- `Ipcmd` and `Iqcmd` ---
        self.Ipcmd = GainLimiter(u=self.Ipul,
                                 K=1, R='Fvl * Fvh * Ffl * Ffh * recflag + 1 * (1 - recflag)',
                                 lower=0, upper=self.Ipmax,
                                 info='Ip with limiter and coeff.',
                                 tex_name='I^{pcmd}',
                                 )

        self.Iqcmd = GainLimiter(u=self.Iqul,
                                 K=1, R='Fvl * Fvh * Ffl * Ffh * recflag + 1 * (1 - recflag)',
                                 lower=self.Iqmax, sign_lower=-1,
                                 upper=self.Iqmax,
                                 info='Iq with limiter and coeff.',
                                 tex_name='I^{qcmd}',
                                 )

        self.Ipout = Lag(u=self.Ipcmd_y, T=self.tip, K=1.0,
                         info='Output Ip filter',
                         )

        self.Iqout = Lag(u=self.Iqcmd_y, T=self.tiq, K=1.0,
                         info='Output Iq filter',
                         )
Ejemplo n.º 8
0
    def __init__(self, system, config):
        PSSBase.__init__(self, system, config)

        # ALL THE FOLLOWING IS FOR INPUT 2
        # retrieve indices of bus and bus freq
        self.buss2 = DataSelect(self.busr2,
                                self.bus,
                                info='selected bus (bus or busr)')

        self.busfreq2 = DeviceFinder(self.busf2,
                                     link=self.buss2,
                                     idx_name='bus')

        # from Bus
        self.v2 = ExtAlgeb(
            model='Bus',
            src='v',
            indexer=self.buss2,
            tex_name=r'V',
            info='Bus (or busr2, if given) terminal voltage',
        )

        # from BusFreq 2
        self.f2 = ExtAlgeb(model='FreqMeasurement',
                           src='f',
                           indexer=self.busfreq2,
                           export=False,
                           info='Bus frequency 2')

        # Config
        self.config.add(OrderedDict([('freq_model', 'BusFreq')]))
        self.config.add_extra(
            '_help', {'freq_model': 'default freq. measurement model'})
        self.config.add_extra('_alt', {'freq_model': ('BusFreq', )})

        self.busf.model = self.config.freq_model
        self.busf2.model = self.config.freq_model

        # input signal switch
        self.dv = Derivative(self.v)
        self.dv2 = Derivative(self.v2)

        self.SnSb = ExtService(
            model='SynGen',
            src='M',
            indexer=self.syn,
            attr='pu_coeff',
            info='Machine base to sys base factor for power',
            tex_name='(Sb/Sn)')

        self.SW = Switcher(
            u=self.MODE,
            options=[0, 1, 2, 3, 4, 5, 6, np.nan],
        )
        self.SW2 = Switcher(
            u=self.MODE2,
            options=[0, 1, 2, 3, 4, 5, 6, np.nan],
        )

        # Input signals
        self.sig = Algeb(
            tex_name='S_{ig}',
            info='Input signal',
        )
        self.sig.v_str = 'SW_s1*(omega-1) + SW_s2*0 + SW_s3*(tm0/SnSb) + ' \
                         'SW_s4*(tm-tm0) + SW_s5*v + SW_s6*0'
        self.sig.e_str = 'SW_s1*(omega-1) + SW_s2*(f-1) + SW_s3*(te/SnSb) + ' \
                         'SW_s4*(tm-tm0) + SW_s5*v + SW_s6*dv_v - sig'

        self.sig2 = Algeb(
            tex_name='S_{ig2}',
            info='Input signal 2',
        )
        self.sig2.v_str = 'SW2_s1*(omega-1) + SW2_s2*0 + SW2_s3*(tm0/SnSb) + ' \
                          'SW2_s4*(tm-tm0) + SW2_s5*v2 + SW2_s6*0'
        self.sig2.e_str = 'SW2_s1*(omega-1) + SW2_s2*(f2-1) + SW2_s3*(te/SnSb) + ' \
                          'SW2_s4*(tm-tm0) + SW2_s5*v2 + SW2_s6*dv2_v - sig2'

        self.L1 = Lag(
            u=self.sig,
            K=self.K1,
            T=self.T1,
            info='Transducer 1',
        )
        self.L2 = Lag(
            u=self.sig2,
            K=self.K2,
            T=self.T2,
            info='Transducer 2',
        )
        self.IN = Algeb(
            tex_name='I_N',
            info='Sum of inputs',
            v_str='L1_y + L2_y',
            e_str='L1_y + L2_y - IN',
        )

        self.WO = WashoutOrLag(
            u=self.IN,
            K=self.T3,
            T=self.T4,
        )

        self.LL1 = LeadLag(
            u=self.WO_y,
            T1=self.T5,
            T2=self.T6,
            zero_out=True,
        )

        self.LL2 = LeadLag(
            u=self.LL1_y,
            T1=self.T7,
            T2=self.T8,
            zero_out=True,
        )

        self.LL3 = LeadLag(
            u=self.LL2_y,
            T1=self.T9,
            T2=self.T10,
            zero_out=True,
        )

        self.VSS = GainLimiter(u=self.LL3_y,
                               K=1,
                               lower=self.LSMIN,
                               upper=self.LSMAX)

        self.VOU = ConstService(v_str='VCUr + v0')
        self.VOL = ConstService(v_str='VCLr + v0')

        self.OLIM = Limiter(u=self.v,
                            lower=self.VOL,
                            upper=self.VOU,
                            info='output limiter')

        self.vsout.e_str = 'OLIM_zi * VSS_y - vsout'
Ejemplo n.º 9
0
    def __init__(self, system, config):
        super().__init__(system, config)
        self.group = 'PSS'
        self.flags.update({'tds': True})

        self.VCUr = Replace(self.VCU, lambda x: np.equal(x, 0.0), 999)
        self.VCLr = Replace(self.VCL, lambda x: np.equal(x, 0.0), -999)

        # retrieve indices of connected generator, bus, and bus freq
        self.syn = ExtParam(model='Exciter',
                            src='syn',
                            indexer=self.avr,
                            export=False,
                            info='Retrieved generator idx',
                            dtype=str)

        self.bus = ExtParam(
            model='SynGen',
            src='bus',
            indexer=self.syn,
            export=False,
            info='Retrieved bus idx',
            dtype=str,
            default=None,
        )

        self.buss = DataSelect(self.busr,
                               self.bus,
                               info='selected bus (bus or busr)')

        self.busfreq = DeviceFinder(self.busf, link=self.buss, idx_name='bus')

        # from SynGen
        self.Sn = ExtParam(model='SynGen',
                           src='Sn',
                           indexer=self.syn,
                           tex_name='S_n',
                           info='Generator power base',
                           export=False)

        self.omega = ExtState(
            model='SynGen',
            src='omega',
            indexer=self.syn,
            tex_name=r'\omega',
            info='Generator speed',
            unit='p.u.',
        )

        self.tm0 = ExtService(
            model='SynGen',
            src='tm',
            indexer=self.syn,
            tex_name=r'\tau_{m0}',
            info='Initial mechanical input',
        )
        self.tm = ExtAlgeb(
            model='SynGen',
            src='tm',
            indexer=self.syn,
            tex_name=r'\tau_m',
            info='Generator mechanical input',
        )
        self.te = ExtAlgeb(
            model='SynGen',
            src='te',
            indexer=self.syn,
            tex_name=r'\tau_e',
            info='Generator electrical output',
        )
        # from Bus
        self.v = ExtAlgeb(
            model='Bus',
            src='v',
            indexer=self.buss,
            tex_name=r'V',
            info='Bus (or busr, if given) terminal voltage',
        )
        self.v0 = ExtService(
            model='Bus',
            src='v',
            indexer=self.buss,
            tex_name="V_0",
            info='Initial bus voltage',
        )

        # from BusFreq
        self.f = ExtAlgeb(model='FreqMeasurement',
                          src='f',
                          indexer=self.busfreq,
                          export=False,
                          info='Bus frequency')

        # from Exciter
        self.vi = ExtAlgeb(model='Exciter',
                           src='vi',
                           indexer=self.avr,
                           tex_name='v_i',
                           info='Exciter input voltage',
                           e_str='u * vsout')

        self.vsout = Algeb(
            info='PSS output voltage to exciter',
            tex_name='v_{sout}',
        )  # `self.vsout.e_str` to be provided by specific models
Ejemplo n.º 10
0
    def __init__(self, system, config):
        Model.__init__(self, system, config)

        self.group = 'RenPlant'
        self.flags.tds = True

        self.config.add(OrderedDict((
            ('kqs', 2),
            ('ksg', 2),
            ('freeze', 1),
        )))

        self.config.add_extra(
            '_help',
            kqs='Tracking gain for reactive power PI controller',
            ksg='Tracking gain for active power PI controller',
            freeze='Voltage dip freeze flag; 1-enable, 0-disable',
        )
        self.config.add_extra('_tex',
                              kqs='K_{qs}',
                              ksg='K_{sg}',
                              freeze='f_{rz}')

        # --- from RenExciter ---
        self.reg = ExtParam(
            model='RenExciter',
            src='reg',
            indexer=self.ree,
            export=False,
            info='Retrieved RenGen idx',
            vtype=str,
            default=None,
        )
        self.Pext = ExtAlgeb(
            model='RenExciter',
            src='Pref',
            indexer=self.ree,
            info='Pref from RenExciter renamed as Pext',
            tex_name='P_{ext}',
        )

        self.Qext = ExtAlgeb(
            model='RenExciter',
            src='Qref',
            indexer=self.ree,
            info='Qref from RenExciter renamed as Qext',
            tex_name='Q_{ext}',
        )

        # --- from RenGen ---
        self.bus = ExtParam(
            model='RenGen',
            src='bus',
            indexer=self.reg,
            export=False,
            info='Retrieved bus idx',
            vtype=str,
            default=None,
        )

        self.buss = DataSelect(self.busr,
                               self.bus,
                               info='selected bus (bus or busr)')

        self.busfreq = DeviceFinder(self.busf, link=self.buss, idx_name='bus')

        # from Bus
        self.v = ExtAlgeb(
            model='Bus',
            src='v',
            indexer=self.buss,
            tex_name='V',
            info='Bus (or busr, if given) terminal voltage',
        )

        self.a = ExtAlgeb(
            model='Bus',
            src='a',
            indexer=self.buss,
            tex_name=r'\theta',
            info='Bus (or busr, if given) phase angle',
        )

        self.v0 = ExtService(
            model='Bus',
            src='v',
            indexer=self.buss,
            tex_name="V_0",
            info='Initial bus voltage',
        )

        # from BusFreq
        self.f = ExtAlgeb(model='FreqMeasurement',
                          src='f',
                          indexer=self.busfreq,
                          export=False,
                          info='Bus frequency',
                          unit='p.u.')

        # from Line
        self.bus1 = ExtParam(
            model='ACLine',
            src='bus1',
            indexer=self.line,
            export=False,
            info='Retrieved Line.bus1 idx',
            vtype=str,
            default=None,
        )

        self.bus2 = ExtParam(
            model='ACLine',
            src='bus2',
            indexer=self.line,
            export=False,
            info='Retrieved Line.bus2 idx',
            vtype=str,
            default=None,
        )
        self.r = ExtParam(
            model='ACLine',
            src='r',
            indexer=self.line,
            export=False,
            info='Retrieved Line.r',
            vtype=str,
            default=None,
        )

        self.x = ExtParam(
            model='ACLine',
            src='x',
            indexer=self.line,
            export=False,
            info='Retrieved Line.x',
            vtype=str,
            default=None,
        )

        self.v1 = ExtAlgeb(
            model='ACLine',
            src='v1',
            indexer=self.line,
            tex_name='V_1',
            info='Voltage at Line.bus1',
        )

        self.v2 = ExtAlgeb(
            model='ACLine',
            src='v2',
            indexer=self.line,
            tex_name='V_2',
            info='Voltage at Line.bus2',
        )

        self.a1 = ExtAlgeb(
            model='ACLine',
            src='a1',
            indexer=self.line,
            tex_name=r'\theta_1',
            info='Angle at Line.bus1',
        )

        self.a2 = ExtAlgeb(
            model='ACLine',
            src='a2',
            indexer=self.line,
            tex_name=r'\theta_2',
            info='Angle at Line.bus2',
        )

        # -- begin services ---

        self.Isign = CurrentSign(self.bus,
                                 self.bus1,
                                 self.bus2,
                                 tex_name='I_{sign}')

        Iline = '(Isign * (v1*exp(1j*a1) - v2*exp(1j*a2)) / (r + 1j*x))'

        self.Iline = VarService(
            v_str=Iline,
            vtype=complex,
            info='Complex current from bus1 to bus2',
            tex_name='I_{line}',
        )

        self.Iline0 = ConstService(
            v_str='Iline',
            vtype=complex,
            info='Initial complex current from bus1 to bus2',
            tex_name='I_{line0}',
        )

        Pline = 're(Isign * v1*exp(1j*a1) * conj((v1*exp(1j*a1) - v2*exp(1j*a2)) / (r + 1j*x)))'

        self.Pline = VarService(
            v_str=Pline,
            vtype=float,
            info='Complex power from bus1 to bus2',
            tex_name='P_{line}',
        )

        self.Pline0 = ConstService(
            v_str='Pline',
            vtype=float,
            info='Initial vomplex power from bus1 to bus2',
            tex_name='P_{line0}',
        )

        Qline = 'im(Isign * v1*exp(1j*a1) * conj((v1*exp(1j*a1) - v2*exp(1j*a2)) / (r + 1j*x)))'

        self.Qline = VarService(
            v_str=Qline,
            vtype=float,
            info='Complex power from bus1 to bus2',
            tex_name='Q_{line}',
        )

        self.Qline0 = ConstService(
            v_str='Qline',
            vtype=float,
            info='Initial complex power from bus1 to bus2',
            tex_name='Q_{line0}',
        )

        self.Rcs = NumSelect(
            self.Rc,
            self.r,
            info='Line R (Rc if provided, otherwise line.r)',
            tex_name='R_{cs}',
        )

        self.Xcs = NumSelect(
            self.Xc,
            self.x,
            info='Line X (Xc if provided, otherwise line.x)',
            tex_name='X_{cs}',
        )

        self.Vcomp = VarService(
            v_str='abs(v*exp(1j*a) - (Rcs + 1j * Xcs) * Iline)',
            info='Voltage after Rc/Xc compensation',
            tex_name='V_{comp}')

        self.SWVC = Switcher(u=self.VCFlag,
                             options=(0, 1),
                             tex_name='SW_{VC}',
                             cache=True)

        self.SWRef = Switcher(u=self.RefFlag,
                              options=(0, 1),
                              tex_name='SW_{Ref}',
                              cache=True)

        self.SWF = Switcher(u=self.Fflag,
                            options=(0, 1),
                            tex_name='SW_{F}',
                            cache=True)

        self.SWPL = Switcher(u=self.PLflag,
                             options=(0, 1),
                             tex_name='SW_{PL}',
                             cache=True)

        VCsel = '(SWVC_s1 * Vcomp + SWVC_s0 * (Qline * Kc + v))'

        self.Vref0 = ConstService(
            v_str='(SWVC_s1 * Vcomp + SWVC_s0 * (Qline0 * Kc + v))',
            tex_name='V_{ref0}',
        )

        self.s0 = Lag(
            VCsel,
            T=self.Tfltr,
            K=1,
            tex_name='s_0',
            info='V filter',
        )  # s0_y is the filter output of voltage deviation

        self.s1 = Lag(self.Qline, T=self.Tfltr, K=1, tex_name='s_1')

        self.Vref = Algeb(v_str='Vref0',
                          e_str='Vref0 - Vref',
                          tex_name='Q_{ref}')

        self.Qlinef = Algeb(v_str='Qline0',
                            e_str='Qline0 - Qlinef',
                            tex_name='Q_{linef}')

        Refsel = '(SWRef_s0 * (Qlinef - s1_y) + SWRef_s1 * (Vref - s0_y))'

        self.Refsel = Algeb(v_str=Refsel,
                            e_str=f'{Refsel} - Refsel',
                            tex_name='R_{efsel}')

        self.dbd = DeadBand1(
            u=self.Refsel,
            lower=self.dbd1,
            upper=self.dbd2,
            center=0.0,
            tex_name='d^{bd}',
        )

        # --- e Hardlimit and hold logic ---
        self.eHL = Limiter(
            u=self.dbd_y,
            lower=self.emin,
            upper=self.emax,
            tex_name='e_{HL}',
            info='Hardlimit on deadband output',
        )

        self.zf = VarService(
            v_str='Indicator(v < Vfrz) * freeze',
            tex_name='z_f',
            info='PI Q input freeze signal',
        )

        self.enf = Algeb(
            tex_name='e_{nf}',
            info='e Hardlimit output before freeze',
            v_str='dbd_y*eHL_zi + emax*eHL_zu + emin*eHL_zl',
            e_str='dbd_y*eHL_zi + emax*eHL_zu + emin*eHL_zl - enf',
        )

        # --- hold of `enf` when v < vfrz

        self.eHld = VarHold(
            u=self.enf,
            hold=self.zf,
            tex_name='e_{hld}',
            info='e Hardlimit output after conditional hold',
        )

        self.s2 = PITrackAW(
            u='eHld',
            kp=self.Kp,
            ki=self.Ki,
            ks=self.config.kqs,
            lower=self.Qmin,
            upper=self.Qmax,
            info='PI controller for eHL output',
            tex_name='s_2',
        )

        self.s3 = LeadLag(
            u=self.s2_y,
            T1=self.Tft,
            T2=self.Tfv,
            K=1,
            tex_name='s_3',
        )  # s3_y == Qext

        # Active power part

        self.s4 = Lag(
            self.Pline,
            T=self.Tp,
            K=1,
            tex_name='s_4',
            info='Pline filter',
        )

        self.Freq_ref = ConstService(v_str='1.0',
                                     tex_name='f_{ref}',
                                     info='Initial Freq_ref')
        self.ferr = Algeb(
            tex_name='f_{err}',
            info='Frequency deviation',
            unit='p.u. (Hz)',
            v_str='(Freq_ref - f)',
            e_str='(Freq_ref - f) - ferr',
        )

        self.fdbd = DeadBand1(
            u=self.ferr,
            center=0.0,
            lower=self.fdbd1,
            upper=self.fdbd2,
            tex_name='f^{dbd}',
            info='frequency error deadband',
        )

        self.fdlt0 = LessThan(
            self.fdbd_y,
            0.0,
            tex_name='f_{dlt0}',
            info='frequency deadband output less than zero',
        )

        fdroop = '(fdbd_y * Ddn * fdlt0_z1 + fdbd_y * Dup * fdlt0_z0)'

        self.Plant_pref = Algeb(
            tex_name='P_{ref}',
            info='Plant P ref',
            v_str='Pline0',
            e_str='Pline0 - Plant_pref',
        )

        self.Plerr = Algeb(
            tex_name='P_{lerr}',
            info='Pline error',
            v_str='- s4_y + Plant_pref',
            e_str='- s4_y + Plant_pref - Plerr',
        )

        self.Perr = Algeb(
            tex_name='P_{err}',
            info='Power error before fe limits',
            v_str=f'{fdroop} + Plerr * SWPL_s1',
            e_str=f'{fdroop} + Plerr * SWPL_s1 - Perr',
        )

        self.feHL = Limiter(
            self.Perr,
            lower=self.femin,
            upper=self.femax,
            tex_name='f_{eHL}',
            info='Limiter for power (frequency) error',
        )

        feout = '(Perr * feHL_zi + femin * feHL_zl + femax * feHL_zu)'
        self.s5 = PITrackAW(
            u=feout,
            kp=self.Kpg,
            ki=self.Kig,
            ks=self.config.ksg,
            lower=self.Pmin,
            upper=self.Pmax,
            tex_name='s_5',
            info='PI for fe limiter output',
        )

        self.s6 = Lag(
            u=self.s5_y,
            T=self.Tg,
            K=1,
            tex_name='s_6',
            info='Output filter for Pext',
        )

        Qext = '(s3_y)'

        Pext = '(SWF_s1 * s6_y)'

        self.Pext.e_str = Pext

        self.Qext.e_str = Qext