class OpenDSSProcedure: def __init__(self): self._opendssinterface = OpenDSSInterface() self._pvderAggProcedure = PVDERAggregatedProcedure() #=================================================================================================== def setup(self): self._opendssinterface.setup() #=================================================================================================== def initialize(self,targetS ,Vpcc ,tol): derP = {} derQ = {} P, Q, convergedFlg = self._opendssinterface.initialize(Vpcc, targetS, tol) if OpenDSSData.config['myconfig']['solarFlag']: # Re-setup DER after reload the OpenDSS S0 = self._opendssinterface.getLoads() V0 = self._opendssinterface.getVoltage(vtype='actual') pvdermap = self._pvderAggProcedure.setup(S0, V0) self._opendssinterface.setupDER(pvdermap) for n in range(200):# 25 cycles to synchronize V = self._opendssinterface.getVoltage(vtype='actual') derP, derQ = self._pvderAggProcedure.run(V) self._opendssinterface.pvderInjection(derP, derQ) P,Q,Converged = self._opendssinterface.getS(pccName='Vsource.source') return P, Q #=================================================================================================== def setVoltage(self, Vpu,Vang,pccName): self._opendssinterface.setVoltage(Vpu,Vang,pccName) #=================================================================================================== def getLoads(self, pccName): derP = {} derQ = {} if OpenDSSData.config['myconfig']['solarFlag']: V = self._opendssinterface.getVoltage(vtype='actual') derP, derQ = self._pvderAggProcedure.run(V) self._opendssinterface.pvderInjection(derP, derQ) P,Q,Converged = self._opendssinterface.getS(pccName=pccName) return P,Q,Converged #=================================================================================================== def scaleLoad(self,scale): self._opendssinterface.scaleLoad(scale) return None #=================================================================================================== def monitor(self,msg): res=self._opendssinterface.monitor(msg) return res
def test_setupDER(self): model = OpenDSSInterface() model.setup() Vpcc = 0.99 targetS = [70.0, 23.0] tol = 0.0001 OpenDSSData.config['myconfig']['solarFlag'] = 0 P0, Q0, convergedFlg = model.initialize(Vpcc, targetS, tol) model = OpenDSSInterface() model.setup() pvdermap = { '49': { 0: 5, 'nSolar_at_this_node': 1 }, '300': { 0: 7, 'nSolar_at_this_node': 1 }, '149': { 0: 3, 'nSolar_at_this_node': 1 }, '150r': { 0: 1, 'nSolar_at_this_node': 1 }, '62': { 0: 4, 'nSolar_at_this_node': 1 }, '72': { 0: 0, 'nSolar_at_this_node': 1 }, '67': { 0: 6, 'nSolar_at_this_node': 1 }, '105': { 0: 2, 'nSolar_at_this_node': 1 } } OpenDSSData.data['DNet']['DER'] = { 'PVDERData':{} } OpenDSSData.data['DNet']['DER']['PVDERData']['PNominal'] = 46.0 OpenDSSData.data['DNet']['DER']['PVDERData']['QNominal'] = 0.0 model.setupDER(pvdermap) Vpcc = 0.99 targetS = [70.0, 23.0] tol = 0.0001 P, Q, convergedFlg = model.initialize(Vpcc, targetS, tol) self.assertNotEqual(Q, Q0)
def test_getVoltage(self): model = OpenDSSInterface() model.setup() Vpcc = 0.99 targetS = [70.0, 23.0] tol = 0.0001 OpenDSSData.config['myconfig']['solarFlag'] = 0 P0, Q0, convergedFlg = model.initialize(Vpcc, targetS, tol) V = model.getVoltage() self.assertNotEqual(V, {})
def test_initialize(self): model = OpenDSSInterface() model.setup() Vpcc = 0.99 targetS = [70.0, 23.0] tol = 0.0001 OpenDSSData.config['myconfig']['solarFlag'] = 0 P, Q, convergedFlg = model.initialize(Vpcc, targetS, tol) self.assertNotEqual(P, 0) self.assertNotEqual(Q, 0) OpenDSSData.config['myconfig']['solarFlag'] = 1
def test_getS(self): model = OpenDSSInterface() model.setup() Vpcc = 0.99 Vpcc2 = 1.2 targetS = [70.0, 23.0] tol = 0.0001 OpenDSSData.config['myconfig']['solarFlag'] = 0 P0, Q0, convergedFlg = model.initialize(Vpcc, targetS, tol) S0 = model.getS() self.assertNotEqual(S0[0], 0) self.assertNotEqual(S0[1], 0)
def test_pvderInjection(self): OpenDSSData.data['DNet']['DER'] = { 'DERParameters': {}, 'PVDERData': {} } OpenDSSData.config['myconfig']['DERParameters']['pvderScale'] = 1.0 OpenDSSData.data['DNet']['DER']['PVDERMap'] = {u'48': {0: 3, 'nSolar_at_this_node': 1}, u'49': {0: 5, 'nSolar_at_this_node': 1}, u'300': {0: 7, 'nSolar_at_this_node': 1}, u'44': {0: 0, 'nSolar_at_this_node': 1}, u'149': {0: 3, 'nSolar_at_this_node': 1}, u'150r': {0: 1, 1: 5, 'nSolar_at_this_node': 2}, u'98': {0: 1, 'nSolar_at_this_node': 1}, u'62': {0: 4, 'nSolar_at_this_node': 1}, u'63': {0: 6, 'nSolar_at_this_node': 1}, u'72': {0: 0, 'nSolar_at_this_node': 1}, u'7': {0: 7, 'nSolar_at_this_node': 1}, u'67': {0: 6, 'nSolar_at_this_node': 1}, u'100': {0: 2, 'nSolar_at_this_node': 1}, u'67_tfr': {0: 4, 'nSolar_at_this_node': 1}, u'105': {0: 2, 'nSolar_at_this_node': 1}} model = OpenDSSInterface() model.setup() Vpcc = 0.99 Vpcc2 = 1.2 targetS = [70.0, 23.0] tol = 0.0001 OpenDSSData.config['myconfig']['solarFlag'] = 0 P0, Q0, convergedFlg = model.initialize(Vpcc, targetS, tol) derP = {u'48': -44.69103342903622, u'49': -44.68064050719606, u'300': -44.69106249193092, u'44': -44.68063934322397, u'149': -44.718762087964095, u'150r': -89.41020467637001, u'98': -44.719429553534326, u'62': -44.69105434902211, u'63': -44.691054548732076, u'72': -44.70889191108346, u'7': -44.708146180554635, u'67': -44.71909186975394, u'100': -44.6910616004745, u'67_tfr': -44.7351812582093, u'105': -44.708465001022766} derQ = {u'48': 2.7087276146591264e-05, u'49': 2.7275438870380825e-05, u'300': 3.884907059227724e-05, u'44': 2.6806615256708347e-05, u'149': -3.094056994715726e-05, u'150r': -2.79567973725623e-05, u'98': 1.1422168051453575e-05, u'62': 3.601215152282528e-05, u'63': 3.6357942899110594e-05, u'72': 7.5089284429261965e-06, u'7': -2.0303052103797546e-05, u'67': 4.201785867901799e-06, u'100': 3.848086404529585e-05, u'67_tfr': 2.188912391977697e-06, u'105': 6.33840605716954e-06} model.pvderInjection(derP, derQ) self.assertNotEqual(OpenDSSData.data['DNet']['DER']['PVDERData']['P'], 0) self.assertNotEqual(OpenDSSData.data['DNet']['DER']['PVDERData']['Q'], 0)
def test_setup(self): model = OpenDSSInterface() model.setup() self.assertNotEqual(model.S0['P'], 0) self.assertNotEqual(model.S0['Q'], 0)
class OpenDSSProcedure(object): def __init__(self): try: self._opendssinterface = OpenDSSInterface() self._pvderAggProcedure = PVDERAggregatedProcedure() self._pvNodes = None except: OpenDSSData.log() #=================================================================================================== def setup(self): try: self._opendssinterface.setup() except: OpenDSSData.log() #=================================================================================================== def initialize(self, targetS, Vpcc, tol): try: derP = {} derQ = {} n_pre_run_steps = 200 if OpenDSSData.config['myconfig']['solarFlag']: # Re-setup DER after reload the OpenDSS S0 = self._opendssinterface.getLoads() V0 = self._opendssinterface.getVoltage(vtype='actual') V0pu = self._opendssinterface.getVoltage(vtype='pu') pvdermap = self._pvderAggProcedure.setup(S0, V0, V0pu=V0pu) self._opendssinterface.setupDER(pvdermap) derType = OpenDSSData.config['openDSSConfig']['DEROdeSolver'] if derType.replace('_', '').replace('-', '').lower() != 'fastder': if six.PY3: tic = time.perf_counter() elif six.PY2: tic = time.clock() for n in range(n_pre_run_steps): # synchronize V = self._opendssinterface.getVoltage(vtype='actual') Vpu = self._opendssinterface.getVoltage(vtype='pu') derP, derQ, derX = self._pvderAggProcedure.run(V, Vpu, t=0, dt=1 / 120.) self._opendssinterface.pvderInjection(derP, derQ) P, Q, Converged = self._opendssinterface.getS( pccName='Vsource.source') if six.PY3: toc = time.perf_counter() elif six.PY2: toc = time.clock() OpenDSSData.log( level=10, msg= "Completed {} steps pre-run at {:.3f} seconds in {:.3f} seconds" .format(n_pre_run_steps, toc, toc - tic)) P, Q, convergedFlg, scale = self._opendssinterface.initialize( Vpcc, targetS, tol) OpenDSSData.log( level=20, msg= "Completed initialize for feeder after {} steps with P:{},Q:{},convergedFlg:{}" .format(n_pre_run_steps, P, Q, convergedFlg)) return P, Q, convergedFlg, scale except: OpenDSSData.log() #=================================================================================================== def setVoltage(self, Vpu, Vang, pccName): try: self._opendssinterface.setVoltage(Vpu, Vang, pccName) except: OpenDSSData.log() #=================================================================================================== def getLoads(self, pccName, t, dt): try: derX = {} if OpenDSSData.config['myconfig']['solarFlag']: P, Q, Converged = self._opendssinterface.getS( pccName=pccName) #### get updated solution V = self._opendssinterface.getVoltage(vtype='actual', busID=self._pvNodes) Vpu = self._opendssinterface.getVoltage(vtype='pu', busID=self._pvNodes) derP, derQ, derX = self._pvderAggProcedure.run(V=V, Vpu=Vpu, t=t, dt=dt) if not self._pvNodes: self._pvNodes = [entry + '_tfr' for entry in derP.keys()] self._opendssinterface.pvderInjection(derP, derQ, busID=self._pvNodes) P, Q, Converged = self._opendssinterface.getS(pccName=pccName) return P, Q, Converged, derX except: OpenDSSData.log() #=================================================================================================== def scaleLoad(self, scale): try: self._opendssinterface.scaleLoad(scale) return None except: OpenDSSData.log() #=================================================================================================== def monitor(self, msg): try: res = self._opendssinterface.monitor(msg) return res except: OpenDSSData.log()