I've made a few changes which I think might be right. But I have a lot of
errors that I've copied below.
I've attached the modified code as well.
Index exceeds matrix dimensions.
Error in opf_setup>@(x)power_flow_fcn(x,nlc{6}{:})
Error in opt_model/eval_nln_constraint (line 81)
[gk, dgk] = fcn(xx); %% evaluate kth constraint and gradient
Error in opf_consfcn (line 53)
[g, dg] = om.eval_nln_constraint(x, 1); %% equalities (power flow)
Error in
mipsopf_solver>@(x)opf_consfcn(x,om,Ybus,Yf(il,:),Yt(il,:),mpopt,il) (line
116)
gh_fcn = @(x)opf_consfcn(x, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il);
Error in mips (line 353)
[hn, gn, dhn, dgn] = gh_fcn(x); %% nonlinear constraints
Error in mipsopf_solver (line 119)
mips(f_fcn, x0, A, l, u, xmin, xmax, gh_fcn, hess_fcn, opt);
Error in opf_execute (line 70)
[results, success, raw] = mipsopf_solver(om, mpopt);
Error in opf (line 232)
[results, success, raw] = opf_execute(om, mpopt);
Error in runopf (line 75)
[r, success] = opf(casedata, mpopt);
Error in problem1 (line 8)
r = runopf(mpc);
Monisha Raju
Graduate Research Assistant
University at Buffalo
On Thu, Dec 7, 2017 at 12:29 PM, Monisha Raju <[email protected]> wrote:
> Hello Ray,
>
> I'm trying to add power flow constraints such that Pf - f(V) = 0 and also
> adding the power flows as variables in the code.
>
> I've attached my code for more clarity. I'm unsure about formulating the
> hessian function. I'm adding these constraints so that I can verify
> Lagrangian function later on to find global solution with perhaps an
> extended range.
>
> Regards,
> Monisha
>
> Monisha Raju
> Graduate Research Assistant
> University at Buffalo
>
> On Tue, Dec 5, 2017 at 3:52 PM, Ray Zimmerman <[email protected]> wrote:
>
>> I’m not sure what you mean by add them *before* running the OPF. The
>> results struct and its x field do not exist until after running the OPF.
>>
>> In any case, I’m not sure why you want to do this. Maybe if you give a
>> little more detail on what you are trying to accomplish, we can suggest a
>> better approach.
>>
>> Ray
>>
>>
>> On Dec 4, 2017, at 1:27 PM, Monisha Raju <[email protected]> wrote:
>>
>> Hi,
>>
>> I was wondering if there was a way I could add power flows Pf, Qf, Pt and
>> Qt to the .x (final value of optimization variables) field at the output.
>>
>> I'm adding power flows from branch data after executing runopf into the
>> .x field. I would like to know if I could do this before execution.
>>
>> Regards,
>> Monisha Raju
>> Graduate Research Assistant
>> University at Buffalo
>>
>>
>>
>
function [g, dg] = power_flow_fcn(x, mpc, Yf, Yt, il, mpopt)
%% Extract required data
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
%% unpack data
branch = mpc.branch;
[Va, Vm] = deal(x{:});
V = Vm .* exp(1j * Va);
Pf0 = branch(:, PF); Pt0 = branch(:, PT);
Qf0 = branch(:, QF); Qt0 = branch(:, QT);
Sf = V(branch(il, F_BUS)) .* conj(Yf * V);
St = V(branch(il, T_BUS)) .* conj(Yt * V);
Pf = real(Sf); Qf = imag(Sf);
Pt = real(St); Qt = imag(St);
mpc.user_vars = {'Pf', nl, Pf, Pmin, Pmax};
mpc.user_vars = {'Qf', nl, Qf, Qmin, Qmax};
mpc.user_vars = {'Pt', nl, Pt, Pmin, Pmax};
mpc.user_vars = {'Qt', nl, Qt, Qmin, Qmax};
g = [Pf-Pf0; Qf-Qf0; Pt-Pt0; Qt-Qt0];
dAf_dPf = 2*(Pf-Pf0);
dAf_dQf = 2*(Qf-Qf0);
dAt_dPt = 2*(Pt-Pt0);
dAt_dQt = 2*(Qt-Qt0);
dg = [dAf_dPf zeros(nl, 3);
zeros(nl,1) dAf_dQf zeros(nl,2);
zeros(nl,2) dAt_dPt zeros(nl,1);
zeros(nl,3) dAt_dQt]; function d2G = power_flow_hess(x, lambda, mpc)
nl = size(mpc.branch,1);
d2G(1:nl, 1) = 2*lambda;
d2G(nl+1:2*nl, 2) = 2*lambda;
d2G(2*nl+1:3*nl, 3) = 2*lambda;
d2G(3*nl+1:4*nl, 4) = 2*lambda;
mpc = loadcase('case9');
nl = size(mpc.branch,1);
%% Non-linear equality branch flow constraints
mpc.user_constraints.nle = {
{'flow_constraint', 4*nl, 'power_flow_fcn', 'power_flow_hess', {'Va', 'Vm'}}
};
r = runopf(mpc);