Hi,

I'm trying to add power flow constraints and Pf, Qf, Pt and Qt as
variables. I've tried a few different ways but I'm not sure what I'm
missing. It looks like the 6th field in the user_constraints is required.
However I can't pass any parameters.

I've sent an email regarding this issue before. I was hoping I could get
some guidance. I've attached the required files for clarity.

Regards,
Monisha Raju
Graduate Research Assistant
University at Buffalo
function [g, dg] = power_flow_fcn(x, mpc)

[F_BUS, T_BUS] = idx_brch;

%% unpack data
branch = mpc.branch;
[Va, Vm] = deal(x{:});

V = Vm .* exp(1j * Va);

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};
mpc.user_vars = {'Qf', nl, Qf};
mpc.user_vars = {'Pt', nl, Pt};
mpc.user_vars = {'Qt', nl, Qt};

Pf0 = mpc.branch(:, PF); Pt0 = mpc.branch(:, PT);
Qf0 = mpc.branch(:, QF); Qt0 = mpc.branch(:, QT);

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_fcn', {'Va', 'Vm'}}
    };
r = runopf(mpc);

Reply via email to