-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
148 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function [constraint_function, Lxx] = build_local_constraint_function(mpc_opf, om, mpopt) | ||
[Ybus, Yf, Yt] = makeYbus(mpc_opf); | ||
il = find(mpc_opf.branch(:, 6) ~= 0 & mpc_opf.branch(:, 6) < 1e10); | ||
|
||
constraint_function = @(x)opf_consfcn(x, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il); | ||
Lxx = @(x, lambda, cost_mult)opf_hessfcn(x, lambda, cost_mult, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function dims = build_local_dimensions(mpc_opf, ineq) | ||
Nbus = size(mpc_opf.bus, 1); | ||
Ngen = size(mpc_opf.gen, 1); | ||
dims.state = 2 * (Nbus + Ngen); | ||
dims.eq = 2 * Nbus; | ||
%% ToDo! | ||
% verification missing!!! | ||
x = rand(dims.state, 1); | ||
dims.ineq = numel(ineq(x)); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function [eq, eq_jac] = build_local_equalities(constraint_function, local_buses_to_remove) | ||
eq = @(x)get_eq_cons(x, constraint_function, copy_buses_local); | ||
eq_jac = @(x)get_eq_cons_jacobian(x, constraint_function); | ||
end | ||
|
||
%% equalities | ||
function g = get_eq_cons(x, gh_fcn, local_buses_to_remove) | ||
[~,g,~,~] = gh_fcn(x); | ||
% remove power flow equations for all copy buses | ||
inds = [local_buses_to_remove; 2 * local_buses_to_remove]; | ||
g(inds) = []; | ||
end | ||
|
||
function dg = get_eq_cons_jacobian(x, gh_fcn) | ||
[~,~,~,dg] = gh_fcn(x); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function [ineq, ineq_jac] = build_local_inequalities(constraint_function) | ||
ineq = @(x)get_ineq_cons(x, constraint_function); | ||
ineq_jac = @(x)get_ineq_cons_jacobian(x, constraint_function); | ||
end | ||
|
||
%% inequalities | ||
function h = get_ineq_cons(x, gh_fcn) | ||
[h,~,~,~] = gh_fcn(x); | ||
end | ||
|
||
function dh = get_ineq_cons_jacobian(x, gh_fcn) | ||
[~,~,dh,~] = gh_fcn(x); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function state = build_local_state(mpc, names, postfix) | ||
Ngen_on = size(mpc.gen, 1); | ||
Ncopy = numel(mpc.(names.copy_buses.local)); | ||
Ncore = size(mpc.bus, 1) - Ncopy; | ||
[Vang_core, Vmag_core, Pg, Qg] = create_state_mp(postfix, Ncore, Ngen_on); | ||
[Vang_copy, Vmag_copy, ~, ~] = create_state_mp(strcat(postfix, '_copy'), Ncopy, 0); | ||
|
||
Vang = [Vang_core; Vang_copy]; | ||
Vmag = [Vmag_core; Vmag_copy]; | ||
|
||
state = stack_state(Vang, Vmag, Pg, Qg); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [mpc_opf, om, copy_buses_local, mpopt] = prepare_case_file(mpc, names) | ||
%% | ||
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... | ||
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... | ||
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; | ||
|
||
mpc = ext2int(mpc); | ||
copy_buses_local = mpc.(names.copy_buses.local); | ||
copy_bus_types = get_bus_types(mpc.bus, copy_buses_local); | ||
|
||
%% turn off generators at copy nodes | ||
for i = 1:length(copy_bus_types) | ||
if copy_bus_types(i) == 2 || copy_bus_types(i) == 3 | ||
% get correct generator row in mpc.gen field | ||
gen_entry = find_generator_gen_entry(mpc, copy_buses_local(i)); | ||
% turn off corresponding generator | ||
mpc.gen(gen_entry, GEN_STATUS) = 0; | ||
end | ||
end | ||
%% we changed the case file after it was switched to internal indexing | ||
% we need to account for that | ||
mpc.order.state = 'e'; | ||
%% return values | ||
[mpc_opf, mpopt] = opf_args(mpc); % only respect most simple opf formulation so far | ||
mpc_opf = ext2int(mpc_opf); | ||
om = opf_setup(mpc_opf, mpopt); | ||
end | ||
|
||
function types = get_bus_types(bus, buses) | ||
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... | ||
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; | ||
types = bus(buses, BUS_TYPE); | ||
end |