Beispiel #1
0
 def __init__(self):
     try:
         self._opendssinterface = OpenDSSInterface()
         self._pvderAggProcedure = PVDERAggregatedProcedure()
         self._pvNodes = None
     except:
         OpenDSSData.log()
Beispiel #2
0
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
Beispiel #3
0
    def test_run(self):
        model = PVDERAggregatedProcedure()

        pvdermap = model.setup(S0, V0)

        P, Q = model.run(V)

        for node in pvdermap:
            print(
                'DER aggregated power -- Active:{} kW,Reactive:{} kVAR'.format(
                    P[node], Q[node]))
            self.assertIsInstance(P[node], float)
            self.assertIsInstance(Q[node], float)
Beispiel #4
0
    def test_setup(self):
        model = PVDERAggregatedProcedure()

        pvdermap = model.setup(S0, V0)

        self.assertTrue(
            len(pvdermap) == len(model._pvderAggModel._pvders),
            msg=
            'Number of PV-DER nodes should be equal to number of PV-DER instances'
        )
        for node in pvdermap:
            self.assertTrue(pvdermap[node]['nSolar_at_this_node'] == 1,
                            msg='Node should contain only one PV-DER instance')

        for model in model._pvderAggModel._pvders.values():
            self.assertIsInstance(
                model._pvderModel.PV_model,
                SolarPV_DER_ThreePhase,
                msg='Node should contain a 3 phase PV-DER instance')
Beispiel #5
0
 def test_init(self):
     model = PVDERAggregatedProcedure()
     self.assertIsInstance(model, PVDERAggregatedProcedure)
Beispiel #6
0
 def __init__(self):        
     
     self._opendssinterface = OpenDSSInterface()        
     self._pvderAggProcedure = PVDERAggregatedProcedure()            
Beispiel #7
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()