def runopf_w_res(*args): """Runs an optimal power flow with fixed zonal reserves. Runs an optimal power flow with the addition of reserve requirements specified as a set of fixed zonal reserves. See L{runopf} for a description of the input and output arguments, which are the same, with the exception that the case file or dict C{casedata} must define a 'reserves' field, which is a dict with the following fields: - C{zones} C{nrz x ng}, C{zone(i, j) = 1}, if gen C{j} belongs to zone C{i} 0, otherwise - C{req} C{nrz x 1}, zonal reserve requirement in MW - C{cost} (C{ng} or C{ngr}) C{x 1}, cost of reserves in $/MW - C{qty} (C{ng} or C{ngr}) C{x 1}, max quantity of reserves in MW (optional) where C{nrz} is the number of reserve zones and C{ngr} is the number of generators belonging to at least one reserve zone and C{ng} is the total number of generators. In addition to the normal OPF output, the C{results} dict contains a new 'reserves' field with the following fields, in addition to those provided in the input: - C{R} - C{ng x 1}, reserves provided by each gen in MW - C{Rmin} - C{ng x 1}, lower limit on reserves provided by each gen, (MW) - C{Rmax} - C{ng x 1}, upper limit on reserves provided by each gen, (MW) - C{mu.l} - C{ng x 1}, shadow price on reserve lower limit, ($/MW) - C{mu.u} - C{ng x 1}, shadow price on reserve upper limit, ($/MW) - C{mu.Pmax} - C{ng x 1}, shadow price on C{Pg + R <= Pmax} constraint, ($/MW) - C{prc} - C{ng x 1}, reserve price for each gen equal to maximum of the shadow prices on the zonal requirement constraint for each zone the generator belongs to See L{t.t_case30_userfcns} for an example case file with fixed reserves, and L{toggle_reserves} for the implementation. Calling syntax options:: results = runopf_w_res(casedata) results = runopf_w_res(casedata, ppopt) results = runopf_w_res(casedata, ppopt, fname) results = runopf_w_res(casedata, [popt, fname, solvedcase) results, success = runopf_w_res(...) Example:: results = runopf_w_res('t_case30_userfcns') @see: L{runopf}, L{toggle_reserves}, L{t.t_case30_userfcns} @author: Ray Zimmerman (PSERC Cornell) @author: Richard Lincoln """ ppc = loadcase(args[0]) ppc = toggle_reserves(ppc, 'on') r = runopf(ppc, *args[1:]) r = toggle_reserves(r, 'off') return r
def t_opf_userfcns(quiet=False): """Tests for userfcn callbacks (reserves/iflims) w/OPF. Includes high-level tests of reserves and iflims implementations. @author: Ray Zimmerman (PSERC Cornell) @author: Richard Lincoln """ t_begin(38, quiet) tdir = dirname(__file__) casefile = join(tdir, 't_case30_userfcns') verbose = 0#not quiet ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8, PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9) ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=560, OPF_ALG_DC=200) #ppopt = ppoption(ppopt, OUT_ALL=-1, VERBOSE=2, OUT_GEN=1) ## run the OPF with fixed reserves t = 'fixed reserves : ' ppc = loadcase(casefile) ppc = toggle_reserves(ppc, 'on') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'reserves.R']) t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc']) t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) t_ok('P' not in r['if'], [t, 'no iflims']) t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost']) t = 'toggle_reserves(ppc, \'off\') : '; ppc = toggle_reserves(ppc, 'off') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t_ok('P' not in r['if'], [t, 'no iflims']) t = 'interface flow lims (DC) : ' ppc = loadcase(casefile) ppc = toggle_iflims(ppc, 'on') r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) t_is(r['branch'][13, PF], 8.244, 3, [t, 'flow in branch 14']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t = 'reserves + interface flow lims (DC) : ' ppc = loadcase(casefile) ppc = toggle_reserves(ppc, 'on') ppc = toggle_iflims(ppc, 'on') r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 38.2573], 4, [t, 'if.mu.u']) t_is(r['reserves']['R'], [25, 15, 0, 0, 16.9, 3.1], 4, [t, 'reserves.R']) t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc']) t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) t_is(r['reserves']['totalcost'], 179.05, 4, [t, 'totalcost']) t = 'interface flow lims (AC) : ' ppc = toggle_reserves(ppc, 'off') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-9.101, 21.432], 3, [t, 'if.P']) t_is(r['if']['mu']['l'], [0, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 10.198], 3, [t, 'if.mu.u']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t = 'interface flow lims (line out) : ' ppc = loadcase(casefile) ppc = toggle_iflims(ppc, 'on') ppc['branch'][11, BR_STATUS] = 0 ## take out line 6-10 r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) t_is(r['branch'][13, PF], 10.814, 3, [t, 'flow in branch 14']) t_ok('R' not in r['reserves'], [t, 'no reserves']) # r['reserves']['R'] # r['reserves']['prc'] # r['reserves']['mu.Pmax'] # r['reserves']['mu']['l'] # r['reserves']['mu']['u'] # r['reserves']['totalcost'] # # r['if']['P'] # r['if']['mu']['l'] # r['if']['mu']['u'] t_end()
def t_opf_userfcns(quiet=False): """Tests for userfcn callbacks (reserves/iflims) w/OPF. Includes high-level tests of reserves and iflims implementations. @author: Ray Zimmerman (PSERC Cornell) @author: Richard Lincoln """ t_begin(38, quiet) tdir = dirname(__file__) casefile = join(tdir, 't_case30_userfcns') verbose = 0 #not quiet ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8, PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9) ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=560, OPF_ALG_DC=200) #ppopt = ppoption(ppopt, OUT_ALL=-1, VERBOSE=2, OUT_GEN=1) ## run the OPF with fixed reserves t = 'fixed reserves : ' ppc = loadcase(casefile) ppc = toggle_reserves(ppc, 'on') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'reserves.R']) t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc']) t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) t_ok('P' not in r['if'], [t, 'no iflims']) t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost']) t = 'toggle_reserves(ppc, \'off\') : ' ppc = toggle_reserves(ppc, 'off') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t_ok('P' not in r['if'], [t, 'no iflims']) t = 'interface flow lims (DC) : ' ppc = loadcase(casefile) ppc = toggle_iflims(ppc, 'on') r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) t_is(r['branch'][13, PF], 8.244, 3, [t, 'flow in branch 14']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t = 'reserves + interface flow lims (DC) : ' ppc = loadcase(casefile) ppc = toggle_reserves(ppc, 'on') ppc = toggle_iflims(ppc, 'on') r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 38.2573], 4, [t, 'if.mu.u']) t_is(r['reserves']['R'], [25, 15, 0, 0, 16.9, 3.1], 4, [t, 'reserves.R']) t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc']) t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) t_is(r['reserves']['totalcost'], 179.05, 4, [t, 'totalcost']) t = 'interface flow lims (AC) : ' ppc = toggle_reserves(ppc, 'off') r = runopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-9.101, 21.432], 3, [t, 'if.P']) t_is(r['if']['mu']['l'], [0, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 10.198], 3, [t, 'if.mu.u']) t_ok('R' not in r['reserves'], [t, 'no reserves']) t = 'interface flow lims (line out) : ' ppc = loadcase(casefile) ppc = toggle_iflims(ppc, 'on') ppc['branch'][11, BR_STATUS] = 0 ## take out line 6-10 r = rundcopf(ppc, ppopt) t_ok(r['success'], [t, 'success']) t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) t_is(r['branch'][13, PF], 10.814, 3, [t, 'flow in branch 14']) t_ok('R' not in r['reserves'], [t, 'no reserves']) # r['reserves']['R'] # r['reserves']['prc'] # r['reserves']['mu.Pmax'] # r['reserves']['mu']['l'] # r['reserves']['mu']['u'] # r['reserves']['totalcost'] # # r['if']['P'] # r['if']['mu']['l'] # r['if']['mu']['u'] t_end()