Hi Baljinnyam, (Sorry, but I’m used to putting my response above the quoted e-mail I’m replying to. I think it makes sense to stick to that convention on this list, since it seems to be the expected behavior, at least on most lists I’m on).
It is true that there have been significant changes in the OPF code structure since version 6.0 in order to facilitate the inclusion of user-defined nonlinear costs and constraints. The main difference as you pointed out is that the evaluation of the constraint function, gradient and hessian are now handled by the om object which calls functions that have been registered with it (in opf_setup.m) as opposed to this being hard coded directly in opf_consfcn() and opf_hessfcn() . The code that actually does the evaluation of the power balance equations and the branch flow inequalities has been moved to opf_power_balance_fcn() and opf_branch_flow_fcn(), respectively. Similarly, with opf_hessfcn() code being moved to opf_power_balance_hess() and opf_branch_flow_hess(). It may be helpful for us to have a conversation about this via Skype or something just for me to be able to walk you through the structure of the code and discuss the approach. I’ll send you an e-mail off-list to set up a time. Ray > On Feb 1, 2018, at 8:55 AM, Baljinnyam Sereeter <b.seree...@tudelft.nl> wrote: > > On 01/25/2018 05:09 PM, Baljinnyam Sereeter wrote: >> Hi Baljinnyam, >> >> Thanks for your offer to contribute. This would be a nice addition to >> MATPOWER. >> >> I suggest starting by adding two new MATPOWER options, each with default >> values of 0 … >> >> opf.current_balance = 0 (complex power balance) or 1 (complex current >> balance) >> opf.v_cartesian = 0 (polar) or 1 (Cartesian) >> >> Then find all the places in the existing OPF code where the current >> (default) formulation is assumed and add conditionals to implement the other >> variations. You might find it useful to use the MATLAB Profiler with a >> simple runopf() call to map out the functions that are called. I think much >> of the work will be in opf_setup(), where we’ll need to use different >> variables and constraints. >> >> Another thing to do early in the process is to duplicate the t/t_opf_mips.m >> file for each of the 3 new variations. The initial goal will be to get all >> of those tests to pass for each of the versions. >> >> Of course, you will want to begin all of this on your own fresh fork of the >> current MATPOWER development branch using the guidelines in the >> Contributor’s Guide >> <https://github.com/MATPOWER/matpower/blob/master/CONTRIBUTING.md#submitting-additions-or-modifications-to-the-code>. >> >> Don’t hesitate to ask if you have questions or need any help along the way. >> >> Thanks again, >> >> Ray > Dear Ray, > > I use Matpower 6.0 version that I understand in code level and know where I > can make changes. However, I have some problems with Matpower repository that > I cloned. It seems that this is a new version that is still not released yet. > I see that functions where I would make my changes are changed as > [g, dg] and [h, dh] are computed using om.eval_nln_constraint(x, 1); > > d2G and d2H are computed using om.eval_nln_constraint_hess(x, > lambda.ineqnonlin, 0); > In the new verion, a lot is changed including structure and code. Therefore, > this is hard for me to understand and make changes in the code. So what > should I do? I can do it easily in Matpower 6.0 version. > > Regards, > > Baljinnyam >