コード例 #1
0
ファイル: case_test.py プロジェクト: Waqquas/pylon
    def testYbus(self):
        """ Test bus and branch admittance matrices.
        """
        self.case.index_buses()
        Ybus, Yf, Yt = self.case.Y

        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpYf = mmread(join(DATA_DIR, self.case_name, "Yf.mtx")).tocsr()
        mpYt = mmread(join(DATA_DIR, self.case_name, "Yt.mtx")).tocsr()

        self.assertTrue(mfeq2(Ybus, mpYbus, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yf, mpYf, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(Yt, mpYt, diff=1e-12), self.case_name)
コード例 #2
0
ファイル: case_test.py プロジェクト: Waqquas/pylon
    def test_dSbus_dV(self):
        """ Test partial derivative of power injection w.r.t. voltage.
        """
        mpYbus = mmread(join(DATA_DIR, self.case_name, "Ybus.mtx")).tocsr()
        mpV0 = mmread(join(DATA_DIR, self.case_name, "V0.mtx")).flatten()

        dSbus_dVm, dSbus_dVa = self.case.dSbus_dV(mpYbus, mpV0)

        mp_dSbus_dVm = mmread(join(DATA_DIR, self.case_name, "dSbus_dVm0.mtx"))
        mp_dSbus_dVa = mmread(join(DATA_DIR, self.case_name, "dSbus_dVa0.mtx"))

        self.assertTrue(mfeq2(dSbus_dVm, mp_dSbus_dVm.tocsr(), 1e-12),
                        self.case_name)
        self.assertTrue(mfeq2(dSbus_dVa, mp_dSbus_dVa.tocsr(), 1e-12),
                        self.case_name)
コード例 #3
0
ファイル: case_test.py プロジェクト: Waqquas/pylon
    def testBdc(self):
        """ Test DCPF B matrices and phase shift injection vectors.
        """
        self.case.index_buses()
        B, Bf, Pbusinj, Pfinj = self.case.Bdc

        mpB = mmread(join(DATA_DIR, self.case_name, "B.mtx")).tocsr()
        self.assertTrue(mfeq2(B, mpB, diff=1e-12), self.case_name)

        mpBf = mmread(join(DATA_DIR, self.case_name, "Bf.mtx")).tocsr()
        self.assertTrue(mfeq2(Bf, mpBf, diff=1e-12), self.case_name)

        mpPbusinj = mmread(join(DATA_DIR, self.case_name,
                                "Pbusinj.mtx")).flatten()
        self.assertTrue(abs(max(Pbusinj - mpPbusinj)) < 1e-14, self.case_name)

        mpPfinj = mmread(join(DATA_DIR, self.case_name, "Pfinj.mtx")).flatten()
        self.assertTrue(abs(max(Pfinj - mpPfinj)) < 1e-14, self.case_name)
コード例 #4
0
ファイル: opf_test.py プロジェクト: Waqquas/pylon
    def test_pwl_costs(self):
        """ Test piecewise linear costs.
        """
        msg = self.case_name
        b, l, g, _ = self.solver._unpack_model(self.om)
        _, ipwl, _, _, _, ny, nxyz = self.solver._dimension_data(b, l, g)
        Npwl, Hpwl, Cpwl, fparm_pwl, _ = \
            self.solver._pwl_costs(ny, nxyz, ipwl)

        if Npwl is not None:
            mpNpwl = mmread(join(DATA_DIR, self.case_name, "opf", "Npwl.mtx"))
            mpHpwl = mmread(join(DATA_DIR, self.case_name, "opf", "Hpwl.mtx"))
            mpCpwl = mmread(join(DATA_DIR, self.case_name, "opf", "Cpwl.mtx"))
            mpfparm = mmread(join(DATA_DIR, self.case_name, "opf","fparm_pwl.mtx"))

            self.assertTrue(mfeq2(Npwl, mpNpwl.tocsr()), msg)
            self.assertTrue(mfeq2(Hpwl.todense(), mpHpwl), msg)
            self.assertTrue(mfeq1(Cpwl, mpCpwl.flatten()), msg)
            self.assertTrue(mfeq1(fparm_pwl.flatten(), mpfparm.flatten()), msg)
コード例 #5
0
ファイル: case_test.py プロジェクト: Waqquas/pylon
    def testB(self):
        """ Test FDPF B matrices.
        """
        self.case.index_buses()
        xbBp, xbBpp = self.case.makeB(method=XB)

        mpxbBp = mmread(join(DATA_DIR, self.case_name, "Bp_XB.mtx")).tocsr()
        mpxbBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_XB.mtx")).tocsr()

        self.assertTrue(mfeq2(xbBp, mpxbBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(xbBpp, mpxbBpp, diff=1e-12), self.case_name)

        bxBp, bxBpp = self.case.makeB(method=BX)

        mpbxBp = mmread(join(DATA_DIR, self.case_name, "Bp_BX.mtx")).tocsr()
        mpbxBpp = mmread(join(DATA_DIR, self.case_name, "Bpp_BX.mtx")).tocsr()

        self.assertTrue(mfeq2(bxBp, mpbxBp, diff=1e-12), self.case_name)
        self.assertTrue(mfeq2(bxBpp, mpbxBpp, diff=1e-12), self.case_name)
コード例 #6
0
ファイル: opf_test.py プロジェクト: Waqquas/pylon
    def test_poly_costs(self):
        """ Test quadratic costs.
        """
        msg = self.case_name
        base_mva = self.om.case.base_mva
        b, l, g, _ = self.solver._unpack_model(self.om)
        ipol, _, _, _, _, _, nxyz = self.solver._dimension_data(b, l, g)
        Npol, Hpol, Cpol, fparm_pol, _, _ = \
            self.solver._quadratic_costs(g, ipol, nxyz, base_mva)

        if Npol is not None:
            mpNpol = mmread(join(DATA_DIR, self.case_name, "opf", "Npol.mtx"))
            mpHpol = mmread(join(DATA_DIR, self.case_name, "opf", "Hpol.mtx"))
            mpCpol = mmread(join(DATA_DIR, self.case_name, "opf", "Cpol.mtx"))
            mpfparm = mmread(join(DATA_DIR, self.case_name, "opf","fparm_pol.mtx"))

            self.assertTrue(mfeq2(Npol, mpNpol.tocsr()), msg)
            self.assertTrue(mfeq2(Hpol, mpHpol.tocsr()), msg)
            self.assertTrue(mfeq1(Cpol, mpCpol.flatten()), msg)
            self.assertTrue(mfeq2(fparm_pol, mpfparm), msg)
コード例 #7
0
ファイル: opf_test.py プロジェクト: Waqquas/pylon
    def test_constraints(self):
        """ Test equality and inequality constraints.
        """
        AA, ll, uu = self.solver._linear_constraints(self.om)

        mpA = mmread(join(DATA_DIR, self.case_name, "opf", "A_DC.mtx"))
        mpl = mmread(join(DATA_DIR, self.case_name, "opf", "l_DC.mtx"))
        mpu = mmread(join(DATA_DIR, self.case_name, "opf", "u_DC.mtx"))

        self.assertTrue(mfeq2(AA, mpA.tocsr()), self.case_name)
        self.assertTrue(mfeq1(ll, mpl.flatten()), self.case_name)
        self.assertTrue(mfeq1(uu, mpu.flatten()), self.case_name)
コード例 #8
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def test_constraints(self):
        """ Test equality and inequality constraints.
        """
        msg = self.case_name
        AA, ll, uu = self.solver._linear_constraints(self.om)

        if AA is not None:
            mpA = mmread(join(DATA_DIR, self.case_name, "opf", "A_AC.mtx"))
            mpl = mmread(join(DATA_DIR, self.case_name, "opf", "l_AC.mtx"))
            mpu = mmread(join(DATA_DIR, self.case_name, "opf", "u_AC.mtx"))

            self.assertTrue(mfeq2(AA, mpA.tocsr()), msg)
            self.assertTrue(mfeq1(ll, mpl.flatten()), msg)
            self.assertTrue(mfeq1(uu, mpu.flatten()), msg)
コード例 #9
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def testAy(self):
        """ Test basin constraints for piece-wise linear gen cost variables.
        """
        msg = self.case_name
        self.case.sort_generators() # ext2int
        _, _, gn = self.opf._remove_isolated(self.case)
        _, ycon = self.opf._pwl_gen_costs(gn, self.case.base_mva)

        if ycon is not None:
            Ay = mmread(join(DATA_DIR, self.case_name, "opf", "Ay_DC.mtx"))
            by = mmread(join(DATA_DIR, self.case_name, "opf", "by_DC.mtx"))

            self.assertTrue(mfeq2(ycon.A, Ay.tocsr()), msg)
            self.assertTrue(mfeq1(ycon.u, by.flatten()), msg)
コード例 #10
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def test_combine_costs(self):
        """ Test combination of pwl and poly costs.
        """
        msg = self.case_name
        base_mva = self.om.case.base_mva
        b, l, g, _ = self.solver._unpack_model(self.om)
        ipol, ipwl, _, _, nw, ny, nxyz = self.solver._dimension_data(b, l, g)
        Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl = self.solver._pwl_costs(ny, nxyz,
                                                                      ipwl)
        Npol, Hpol, Cpol, fparm_pol, _, npol = \
            self.solver._quadratic_costs(g, ipol, nxyz, base_mva)
        NN, HHw, CCw, ffparm = \
            self.solver._combine_costs(Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl,
                                       Npol, Hpol, Cpol, fparm_pol, npol, nw)

        mpNN = mmread(join(DATA_DIR, self.case_name, "opf", "NN.mtx"))
        mpHHw = mmread(join(DATA_DIR, self.case_name, "opf", "HHw.mtx"))
        mpCCw = mmread(join(DATA_DIR, self.case_name, "opf", "CCw.mtx"))
        mpffparm = mmread(join(DATA_DIR, self.case_name, "opf", "ffparm.mtx"))

        self.assertTrue(mfeq2(NN, mpNN.tocsr()), msg)
        self.assertTrue(mfeq2(HHw, mpHHw.tocsr()), msg)
        self.assertTrue(mfeq1(CCw, mpCCw.flatten()), msg)
        self.assertTrue(mfeq2(ffparm, mpffparm), msg)
コード例 #11
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def testVLConstPF(self):
        """ Test dispatchable load, constant power factor constraints.
        """
        msg = self.case_name
        _, _, gn = self.opf._remove_isolated(self.case)
        vl = self.opf._const_pf_constraints(gn, self.case.base_mva)

        if vl.A.shape[0] != 0:
            Avl = mmread(join(DATA_DIR, self.case_name, "opf", "Avl.mtx"))
            self.assertTrue(mfeq2(vl.A, Avl.tocsr()), msg)

        lvl = mmread(join(DATA_DIR, self.case_name, "opf", "lang.mtx"))
        self.assertTrue(mfeq1(vl.l, lvl.flatten()), msg)

        uvl = mmread(join(DATA_DIR, self.case_name, "opf", "uang.mtx"))
        self.assertTrue(mfeq1(vl.u, uvl.flatten()), msg)
コード例 #12
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def testPmis(self):
        """ Test active power mismatch constraints.
        """
        msg = self.case_name
        case = self.case
        case.sort_generators() # ext2int
        B, _, Pbusinj, _ = case.Bdc
        bs, _, gn = self.opf._remove_isolated(case)
        Pmis = self.opf._power_mismatch_dc(bs, gn, B, Pbusinj, case.base_mva)

        mpAmis = mmread(join(DATA_DIR, self.case_name, "opf", "Amis.mtx"))
        mpbmis = mmread(join(DATA_DIR, self.case_name, "opf", "bmis.mtx"))

        self.assertTrue(mfeq2(Pmis.A, mpAmis.tocsr(), 1e-12), msg)
        self.assertTrue(mfeq1(Pmis.l, mpbmis.flatten()), msg)
        self.assertTrue(mfeq1(Pmis.u, mpbmis.flatten()), msg)
コード例 #13
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def testVang(self):
        """ Test voltage angle difference limit constraint.
        """
        msg = self.case_name
        self.opf.ignore_ang_lim = False
        bs, ln, _ = self.opf._remove_isolated(self.case)
        ang = self.opf._voltage_angle_diff_limit(bs, ln)

        if ang.A.shape[0] != 0:
            Aang = mmread(join(DATA_DIR, self.case_name, "opf", "Aang.mtx"))
        else:
            Aang = None
        lang = mmread(join(DATA_DIR, self.case_name, "opf", "lang.mtx"))
        uang = mmread(join(DATA_DIR, self.case_name, "opf", "uang.mtx"))

        if Aang is not None:
            self.assertTrue(mfeq2(ang.A, Aang.tocsr()), msg)
        self.assertTrue(mfeq1(ang.l, lang.flatten()), msg)
        self.assertTrue(mfeq1(ang.u, uang.flatten()), msg)
コード例 #14
0
ファイル: opf_test.py プロジェクト: oosterden/pylon
    def test_coefficient_transformation(self):
        """ Test transformation of quadratic coefficients for w into
            coefficients for X.
        """
        msg = self.case_name
        base_mva = self.om.case.base_mva
        b, l, g, _ = self.solver._unpack_model(self.om)
        ipol, ipwl, _, _, nw, ny, nxyz = self.solver._dimension_data(b, l, g)
        Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl = \
            self.solver._pwl_costs(ny, nxyz, ipwl)
        Npol, Hpol, Cpol, fparm_pol, polycf, npol = \
            self.solver._quadratic_costs(g, ipol, nxyz, base_mva)
        NN, HHw, CCw, ffparm = \
            self.solver._combine_costs(Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl,
                                       Npol, Hpol, Cpol, fparm_pol, npol, nw)
        HH, CC, _ = \
            self.solver._transform_coefficients(NN, HHw, CCw, ffparm, polycf,
                                                any_pwl, npol, nw)

        mpHH = mmread(join(DATA_DIR, self.case_name, "opf", "HH.mtx"))
        mpCC = mmread(join(DATA_DIR, self.case_name, "opf", "CC.mtx"))

        self.assertTrue(mfeq2(HH, mpHH.tocsr()), msg)
        self.assertTrue(mfeq1(CC, mpCC.flatten()), msg)