MATPOWER / matpower

MATPOWER – steady state power flow simulation and optimization for MATLAB and Octave
https://matpower.org
Other
417 stars 151 forks source link

How to Add Linear Constraints to a Simple Transmission Cross Section in a Standard OPF? #239

Open hygge-coder opened 1 month ago

hygge-coder commented 1 month ago

Hi Dr. Zimmerman, Here is my code,

    function [ om ] = userfcn_case9lineartest(om,mpopt,args)
    mpc = om.get_mpc();
    BranchNum = size(mpc.branch, 1);
    line_indices = [1,4,7]; 
    Line_num = length(line_indices);
    A =sparse(1, line_indices, ones(1, Line_num), 1, BranchNum);
    l=-Inf;
    u=300/mpc.baseMVA;
    om = om.add_lin_constraint('line_flow_limit1', A, l, u,{'Pf'});

I want to add a transmission section constraint by limiting the sum of the transmission power of a few transmission lines of the branch matrix, and then apply this simple linear constraint using add_userfcn(mpc, 'formulation', @userfcn_case9lineartest, []);however Since 'Pf' is not the default variable of matpower, unlike the default variable 'Pg' of matpower which is so easy to use, how should I use the add_varstatement to reach the optimization of the branch matrix's transmission power Kind Regards hygge

rdzman commented 1 month ago

Does toggle_iflims(), described in Section 7.6.2 in the MATPOWER User's Manual do what you want?

hygge-coder commented 1 month ago

Does toggle_iflims(), described in Section 7.6.2 in the MATPOWER User's Manual do what you want?

Dr. Zimmerman, I understand it can be done, but I would like to become more familiar with MATPOWER by writing this example myself. Could you please guide me on how to use the add_var statement to callPf data? Thank you.

rdzman commented 1 month ago

As you mention, Pf is not a variable, but it is a linear function of the Va variables. It can be computed using the Bf and Pfinj returned by makeBdc() as Pf = Br * Va + Pfinj.

So as you can see here ... https://github.com/MATPOWER/matpower/blob/0ea002687d2e38eeca53aed2ea6a12c84363d075/lib/toggle_iflims.m#L134-L160 ... we use that to build up the constraint matrices and bounds as functions of Va.

hygge-coder commented 1 month ago

Thank you, Dr. Zimmerman. I have resolved the issue, thanks to your assistance. I appreciate your help.