Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._init()
def init0(self, dae):
dae.y[self.v] = self.voltage
def gcall(self, dae):
dae.g[self.v] -= dae.y[self.I]
dae.g[self.I] = self.voltage - dae.y[self.v]
def jac0(self, dae):
dae.add_jac(Gy0, -self.u, self.v, self.I)
dae.add_jac(Gy0, self.u - 1 - 1e-6, self.I, self.I)
dae.add_jac(Gy0, -self.u, self.I, self.v)
class DCgen(DCBase):
"""A simple DC generator to impose constantactive power injection"""
def __init__(self, system, name):
super().__init__(system, name)
self._name = 'DCgen'
self._params.extend(['P', 'Sn'])
self._data.update({'P': 0.0,
})
self._descr.update({'P': 'Active power generation'})
self._units.update({'P': 'pu'})
self._powers.extend(['P'])
self.calls.update({'pflow': True,
'gcall': True,
'stagen': True,
})
self._init()
self.calls.update({'pflow': True,
'gcall': True,
'stagen': True,
})
self._init()
def gcall(self, dae):
dae.g -= spmatrix(div(mul(self.u, self.P), self.v12), self.v1, [0] * self.n, (dae.m, 1), 'd')
dae.g -= spmatrix(-div(mul(self.u, self.P), self.v12), self.v2, [0] * self.n, (dae.m, 1), 'd')
def disable_gen(self, idx):
self.u[self.uid[idx]] = 0
self.system.dae.factorize = True
class DCload(DCBase):
"""A simple DC load to impose constant active power consumption"""
def __init__(self, system, name):
super().__init__(system, name)
self._name = 'DCload'
self._params.extend(['P', 'Sn'])
self._data.update({'P': 0.0,
})
self._powers.extend(['P'])
self._descr.update({'P': 'Active power load'})
self._units.update({'P': 'pu'})
self.calls.update({'pflow': True,
'gcall': True,
})
self._init()
def speed_fxcall(self, dae):
pass
def speed_gycall(self, dae):
pass
def speed_jac0(self, dae):
dae.add_jac(Gy0, -self.u - 1e-6, self.ref1, self.ref1)
dae.add_jac(Gx0, self.u, self.ref1, self.xw)
dae.add_jac(Fy0, self.u, self.adq, self.ref1)
dae.add_jac(Fx0, -mul(self.D, self.iM, self.u), self.xw, self.xw)
dae.add_jac(Fy0, -mul(self.iM, self.u), self.xw, self.p)
class VSC2_Common(DCBase):
"""Common equations for voltage-source controlled VSC"""
def __init__(self, system, name):
super(VSC2_Common, self).__init__(system, name)
self._group = 'AC/DC'
self._data.update({
'vsc': None,
})
self._descr.update({'vsc': 'static vsc idx'})
self._params.extend(['vsc', 'Sn'])
self._mandatory.extend(['vsc'])
self._algebs.extend(['p', 'q', 'vd', 'vq'])
self._fnamey.extend(['P', 'Q', 'v_d', 'v_q'])
self._service.extend(['qref0', 'vref0', 'wref0', 'pref0'])
self._units.update({
'Vdcn': 'kV',
'Idcn': 'A',
})
self._dc = {
'node1': 'v1',
'node2': 'v2',
}
self._mandatory.extend(['node1', 'node2', 'Vdcn'])
@property
def v12(self):
return self.system.dae.y[self.v1] - self.system.dae.y[self.v2]
class R(DCBase):
"""DC Resistence line class"""
def __init__(self, system, name):
super().__init__(system, name)
self._name = 'R'
self._params.extend(['R'])
self._data.update({
'R': 0.01,
})
self._r.extend(['R'])
self.calls.update({
'pflow': True,
'gcall': True,
'jac0': True,
})
self._algebs.extend(['Idc'])
def fcall(self, dae):
dae.f[self.vC] = -mul(dae.y[self.Idc], self.iC)
def jac0(self, dae):
dae.add_jac(Gx0, self.u, self.Idc, self.vC)
dae.add_jac(Gy0, -self.u, self.Idc, self.v1)
dae.add_jac(Gy0, self.u, self.Idc, self.v2)
dae.add_jac(Gy0, 1e-6 - self.R, self.Idc, self.Idc)
dae.add_jac(Gy0, -self.u, self.v1, self.Idc)
dae.add_jac(Gy0, self.u, self.v2, self.Idc)
dae.add_jac(Fy0, -self.iC, self.vC, self.Idc)
class RLCs(DCBase):
"""RLC series"""
def __init__(self, system, name):
super(RLCs, self).__init__(system, name)
self._name = 'RLCs'
self._params.extend(['R', 'L', 'C'])
self._data.update({'R': 0.01, 'L': 0.001, 'C': 0.001})
self._params.extend(['R', 'L', 'C'])
self._r.extend(['R', 'L'])
self._g.extend(['C'])
self._algebs.extend(['Idc'])
self._fnamey.extend(['I_{dc}'])
self._states.extend(['IL', 'vC'])
self._fnamex.extend(['I_L', 'v_C'])
self.calls.update({
'pflow': True,
dae.add_jac(Gy0, -self.u, self.v, self.qsh)
dae.add_jac(Gy0, -self.u - 1e-6, self.Ish, self.Ish)
dae.add_jac(Gy0, -self.u - 1e-6, self.pdc, self.pdc)
dae.add_jac(Gy0, mul(self.u, self.k1), self.pdc, self.Ish)
def disable(self, idx):
"""Disable an element and reset the outputs"""
if idx not in self.uid.keys():
self.log('Element index {0} does not exist.'.format(idx))
return
self.u[self.uid[idx]] = 0
class VSC1_Common(DCBase):
"""Common equations for VSC1"""
def __init__(self, system, name):
super(VSC1_Common, self).__init__(system, name)
self._group = 'AC/DC'
self._data.update({
'vsc': None,
'Kdc': 0,
'Kf': 0,
'KV': 0,
'Kp': 0,
})
self._mandatory.extend(['vsc'])
self._descr.update({
'vsc': 'static vsc idx',
'Kdc': 'droop of dc voltage on active power',
def fcall(self, dae):
dae.f[self.IL] = mul(self.v12 - mul(self.R, dae.x[self.IL], self.u),
self.iL)
def jac0(self, dae):
dae.add_jac(Gx0, self.u, self.Idc, self.IL)
dae.add_jac(Gy0, self.u + 1e-6, self.Idc, self.Idc)
dae.add_jac(Gy0, -self.u, self.v1, self.Idc)
dae.add_jac(Gy0, self.u, self.v2, self.Idc)
dae.add_jac(Fx0, -mul(self.R, self.iL, self.u) + 1e-6, self.IL,
self.IL)
dae.add_jac(Fy0, mul(self.u, self.iL), self.IL, self.v1)
dae.add_jac(Fy0, -mul(self.u, self.iL), self.IL, self.v2)
class RCp(DCBase):
"""RC parallel line"""
def __init__(self, system, name):
super(RCp, self).__init__(system, name)
self._name = 'RCp'
self._params.extend(['R', 'C'])
self._data.update({
'R': 0.01,
'C': 0.001,
})
self._params.extend(['R', 'C'])
self._r.extend(['R'])
self._g.extend(['C'])
self._algebs.extend(['Idc'])
self._fnamey.extend(['I_{dc}'])
self._states.extend(['vC'])
def jac0(self, dae):
dae.add_jac(Gx0, self.u, self.Idc, self.IL)
dae.add_jac(Gy0, self.u, self.Idc, self.Idc)
dae.add_jac(Gy0, -self.u, self.v1, self.Idc)
dae.add_jac(Gy0, self.u, self.v2, self.Idc)
dae.add_jac(Fx0, -mul(self.R, self.iL), self.IL, self.IL)
dae.add_jac(Fy0, self.iL, self.IL, self.v1)
dae.add_jac(Fy0, -self.iL, self.IL, self.v2)
dae.add_jac(Fx0, -self.iL, self.IL, self.vC)
dae.add_jac(Fx0, self.iC, self.vC, self.IL)
class Ground(DCBase):
"""DC Ground node"""
def __init__(self, system, name):
super().__init__(system, name)
self.param_remove('node1')
self.param_remove('node2')
self.param_remove('v')
self._data.update({
'node': None,
'voltage': 0.0,
})
self._algebs.extend(['I'])
self._unamey = ['I']
self._fnamey = ['I']
self._dc = {'node': 'v'}
dae.add_jac(Gx0, self.u, self.Idc, self.vC)
dae.add_jac(Gy0, -self.u, self.Idc, self.v1)
dae.add_jac(Gy0, self.u, self.Idc, self.v2)
dae.add_jac(Gy0, 1e-6, self.Idc, self.Idc)
dae.add_jac(Gy0, -self.u, self.v1, self.Idc)
dae.add_jac(Gy0, self.u, self.v2, self.Idc)
dae.add_jac(Fx0, self.iL, self.IL, self.vC)
dae.add_jac(Fy0, -self.iC, self.vC, self.Idc)
dae.add_jac(Fx0, -mul(self.iR, self.iC), self.vC, self.vC)
dae.add_jac(Fx0, -self.iC, self.vC, self.IL)
class RCs(DCBase):
"""RC series line"""
def __init__(self, system, name):
super(RCs, self).__init__(system, name)
self._name = 'RCs'
self._data.update({'R': 0.01, 'C': 0.001})
self._params.extend(['R', 'C'])
self._r.extend(['R'])
self._g.extend(['C'])
self._algebs.extend(['Idc'])
self._fnamey.extend(['I_{dc}'])
self._states.extend(['vC'])
self._fnamex.extend(['vC'])
self._service.extend(['iC', 'iR'])
self.calls.update({
'pflow': True,
import logging
from cvxopt import matrix, mul, spmatrix, div, sin, cos
from .dcbase import DCBase
from ..consts import Fx, Fy, Gx, Gy # NOQA
from ..consts import Fx0, Fy0, Gx0, Gy0 # NOQA
from ..utils.math import zeros, conj, polar
logger = logging.getLogger(__name__)
class VSC(DCBase):
"""VSC model for power flow study"""
def __init__(self, system, name):
super().__init__(system, name)
self._group = 'AC/DC'
self._name = 'VSC'
self._ac = {'bus': ['a', 'v']}
self._params.extend([
'rsh', 'xsh', 'vshmax', 'vshmin', 'Ishmax', 'pref0', 'qref0',
'vref0', 'v0', 'vdcref0', 'k0', 'k1', 'k2', 'droop', 'K', 'vhigh',
'vlow'
])
self._data.update({
'rsh': 0.0025,
'xsh': 0.06,
'vshmax': 1.1,