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_setVoltage(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() model.setVoltage(Vpcc2) S1 = model.getS() self.assertNotEqual(S0, S1)
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()