Home > matpower7.1 > lib > cpf_vlim_event_cb.m

cpf_vlim_event_cb

PURPOSE ^

CPF_VLIM_EVENT_CB Callback to handle VLIM events

SYNOPSIS ^

function [nx, cx, done, rollback, evnts, cb_data, results] = cpf_vlim_event_cb(k, nx, cx, px, done, rollback, evnts, cb_data, cb_args, results)

DESCRIPTION ^

CPF_VLIM_EVENT_CB  Callback to handle VLIM events
   [NX, CX, DONE, ROLLBACK, EVNTS, CB_DATA, RESULTS] =
       CPF_VLIM_EVENT_CB(K, NX, CX, PX, DONE, ROLLBACK, EVNTS, ...
                               CB_DATA, CB_ARGS, RESULTS)

   Callback to handle VLIM (bus voltage magnitude limit violation) events,
   triggered by event function CPF_VLIM_EVENT to indicate the point at which
   an upper or lower voltage magnitude limit is reached for a bus.

   All bus voltages are expected to be within limits for the base case,
   otherwise the continuation terminates.

   This function sets the msg field of the event when the voltage magnitude
   at any bus reaches its upper or lower limit, raises the DONE.flag and sets
   the DONE.msg.

   See CPF_DEFAULT_CALLBACK for details of the input and output arguments.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [nx, cx, done, rollback, evnts, cb_data, results] = cpf_vlim_event_cb(...
0002         k, nx, cx, px, done, rollback, evnts, cb_data, cb_args, results)
0003 %CPF_VLIM_EVENT_CB  Callback to handle VLIM events
0004 %   [NX, CX, DONE, ROLLBACK, EVNTS, CB_DATA, RESULTS] =
0005 %       CPF_VLIM_EVENT_CB(K, NX, CX, PX, DONE, ROLLBACK, EVNTS, ...
0006 %                               CB_DATA, CB_ARGS, RESULTS)
0007 %
0008 %   Callback to handle VLIM (bus voltage magnitude limit violation) events,
0009 %   triggered by event function CPF_VLIM_EVENT to indicate the point at which
0010 %   an upper or lower voltage magnitude limit is reached for a bus.
0011 %
0012 %   All bus voltages are expected to be within limits for the base case,
0013 %   otherwise the continuation terminates.
0014 %
0015 %   This function sets the msg field of the event when the voltage magnitude
0016 %   at any bus reaches its upper or lower limit, raises the DONE.flag and sets
0017 %   the DONE.msg.
0018 %
0019 %   See CPF_DEFAULT_CALLBACK for details of the input and output arguments.
0020 
0021 %   MATPOWER
0022 %   Copyright (c) 2016-2017, Power Systems Engineering Research Center (PSERC)
0023 %   by Ray Zimmerman, PSERC Cornell
0024 %   and Ahmad Abubakar Sadiq, Federal University of Technology Minna, Nigeria
0025 %   and Shrirang Abhyankar, Argonne National Laboratory
0026 %
0027 %   This file is part of MATPOWER.
0028 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0029 %   See https://matpower.org for more info.
0030 
0031 %% define named indices into bus, gen, branch matrices
0032 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0033     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0034 
0035 %% base case data
0036 mpc = cb_data.mpc_base;
0037 nb = size(mpc.bus, 1);
0038 i2e_bus = mpc.order.bus.i2e;
0039 
0040 %% initialize
0041 if k == 0
0042     %% check initial bus Vm
0043     if any(mpc.bus(:, VM) < mpc.bus(:, VMIN)) || any(mpc.bus(:, VM) > mpc.bus(:, VMAX))
0044         %% find the bus(es) and which lim(s)
0045         ib = find([mpc.bus(:, VM) < mpc.bus(:, VMIN);mpc.bus(:, VM) > mpc.bus(:, VMAX)]);
0046         for j = 1:length(ib)
0047             b = ib(j);          %% index of critical bus event of interest
0048             if b > nb
0049                 b = b - nb;
0050                 msg = sprintf('bus voltage magnitude limit violated in base case: bus %d exceeds Vmax limit %g p.u.',...
0051                    i2e_bus(b), mpc.bus(b,VMAX));
0052             else
0053                 msg = sprintf('bus voltage magnitude limit violated in base case: bus %d exceeds Vmin limit %g p.u.',...
0054                    i2e_bus(b), mpc.bus(b,VMIN));
0055             end
0056         end
0057         
0058         done.flag = 1;
0059         done.msg = msg;
0060     end
0061 end
0062 
0063 %% skip if finalize or done
0064 if k < 0 || done.flag
0065     return;
0066 end
0067 
0068 %% handle event
0069 for i = 1:length(evnts)
0070     if strcmp(evnts(i).name, 'VLIM') && evnts(i).zero
0071         if cb_data.mpopt.verbose > 3
0072             msg = sprintf('%s\n    ', evnts(i).msg);
0073         else
0074             msg = '';
0075         end
0076         
0077         %% find the bus(es) and which lim(s)
0078         ib = evnts(i).idx;
0079         for j = 1:length(ib)
0080             b = ib(j);          %% index of critical bus event of interest
0081             if b > nb
0082                 b = b - nb;
0083                 msg = sprintf('%sbus voltage magnitude limit reached\nbus %d at VMAX limit %g p.u. @ lambda = %.4g, in %d continuation steps',...
0084                     msg, i2e_bus(b), mpc.bus(b,VMAX), nx.lam, k);
0085             else
0086                 msg = sprintf('%sbus voltage magnitude limit reached\nbus %d at Vmin limit %g p.u. @ lambda = %.4g, in %d continuation steps',...
0087                     msg, i2e_bus(b), mpc.bus(b,VMIN),nx.lam, k);
0088             end
0089         end
0090         
0091         done.flag = 1;
0092         done.msg = msg;
0093     end
0094 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005