Hello,

I'm trying to add additional power flow constraints Pf, Qf, Pt and Qt such
that,
V'FpV = Pf ----> V'FpV-Pf = 0

I've used both the direct and indirect methods of adding user defined
constraints but I'm still unable to get results. These are the errors I'm
getting.

Insufficient number of outputs from right hand side of equal sign to satisfy
assignment.

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);

I've attached the required files for clarity. I'm hoping for some
clarification with how to formulate nln constraints.

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

%% 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;

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

g = [x'*Pf(:,:,1)*x; x'*Pf(:,:,2)*x; x'*Pf(:,:,3)*x; x'*Pf(:,:,4)*x; 
x'*Pf(:,:,5)*x; x'*Pf(:,:,6)*x; x'*Pf(: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f, Qf, Pt, Qt)

d2G = 2*lam*[Pf(:,:,1); Pf(:,:,2); Pf(:,:,3); Pf(:,:,4); Pf(:,:,5); Pf(:,:,6); 
Pf(:,:,7); Pf(:,:,8); Pf(:,:,9);
    Qf(:,:,1); Qf(:,:,2); Qf(:,:,3); Qf(:,:,4); Qf(:,:,5); Qf(:,:,6); 
Qf(:,:,7); Qf(:,:,8); Qf(:,:,9);
    Pt(:,:,1); Pt(:,:,2); Pt(:,:,3); Pt(:,:,4); Pt(:,:,5); Pt(:,:,6); 
Pt(:,:,7); Pt(:,:,8); Pt(:,:,9);
    Qt(:,:,1); Qt(:,:,2); Qt(:,:,3); Qt(:,:,4); Qt(:,:,5); Qt(:,:,6); 
Qt(:,:,7); Qt(:,:,8); Qt(:,:,9)];
function mpc = toggle_power_flow(mpc, on_off)

if strcmp(upper(on_off), 'ON')
    mpc = add_userfcn(mpc, 'formulation', @userfcn_power_flow_formulation);
elseif strcmp(upper(on_off), 'OFF')
    mpc = remove_userfcn(mpc, 'formulation', @userfcn_power_flow_formulation);
else
    error('toggle_reserves: 2nd argument must be ''on'',  or ''off''');
end

%%-----  formulation  --------------------------------------------------
function om = userfcn_power_flow_formulation(om, mpopt, args)

%% initialize some things
mpc = om.get_mpc();
nl = size(mpc.branch,1);
nbus = size(mpc.bus,1);
ngen = size(mpc.gen,1);
n = 2*(nbus+ngen);

matobject = matfile('M.mat', 'Writable', true);
M = matobject.Mat; 

Fp = real(M.FlowF); Fq = imag(M.FlowF);
Tp = real(M.FlowT); Tq = imag(M.FlowT);

Pf = zeros(n,n,nbus); Qf = zeros(n,n,nbus);
Pt = zeros(n,n,nbus); Qt = zeros(n,n,nbus);

Pf(1:2*nbus, 1:2*nbus,:) = Fp; Qf(1:2*nbus, 1:2*nbus,:) = Fq;
Pt(1:2*nbus, 1:2*nbus,:) = Tp; Qt(1:2*nbus, 1:2*nbus,:) = Tq;
%% add them to the model
om.add_nln_constraint('Flow_constraints', 4*nl, 1, 'power_flow_fcn', 
'power_flow_hess',{}, {'Pf','Qf','Pt','Qt'});

Reply via email to