In Matpower, a continuation power flow is executed by calling runcpf with two Matpower
cases (case structs or case file names) as the first two arguments, basecasedata and
targetcasedata, respectively. The first contains the base loading/generation profile while
the second contains the target loading/generation profile. In addition to printing output to
the screen, which it does by default, runcpf optionally returns the solution in a results
struct.
Additional optional input arguments can be used to set options (mpopt) and provide
file names for saving the pretty printed output (fname) or the solved case data
(solvedcase).
The results struct is a superset of the input Matpowercase struct mpc, with some
additional fields as well as additional columns in some of the existing data fields. In
addition to the solution values included in the results for a simple power flow, shown in
Table 4-1 in Section 4.4, the following additional continuation power flow solution values
are stored in the cpf field as shown in Table 5-1.
Table 5-1:Continuation Power Flow Results
name
description
results.cpf
CPF output struct whose content depends on any user callback functions,where default contains fields:
done_msg
string with message describing cause of continuation termination
events(eidx)
a structure array of size, whereis the number of events located,with fields:
k
continuation step number at which event was located
name
name of event
idx
index(es) of critical elements in corresponding event function, e.g. index ofgenerator reaching VAr limit
msg
descriptive text detailing the event
iterations
, number of continuation steps performed
lam
vector ofvalues from correction steps†
lam_hat
vector ofvalues from prediction steps†
max_lam
maximum value offound in results.cpf.lam
steps
vector of step sizes for each continuation step performed†
V
matrix of complex bus voltages from correction steps†
V_hat
matrix of complex bus voltages from prediction steps†
†is one more than the number of continuation steps, i.e., so the first element corresponds to the startingpoint.
The options that control the continuation power flow simulation are listed in Table 5-2.
All the power flow options for Newton’s method (tolerance, maximum iterations) and for
controlling the output on the screen (see Tables 4-2 and 4-3) are also available with the
continuation power flow.
Table 5-2:Continuation Power Flow Options
name
default
description
cpf.parameterization
3
choice of parameterization
1 — natural
2 — arc length
3 — pseudo arc length
cpf.stop_at
'NOSE'
determines stopping criterion
'NOSE' — stop when nose point is reached
'FULL' — trace full nose curve
— stop upon reaching targetvalue
cpf.enforce_p_lims
0
enforce gen active power limits
0 — do not enforce limits
1 — enforce limits
cpf.enforce_q_lims
0
enforce gen reactive power limits at expense of
0 — do not enforce limits
1 — enforce limits
cpf.enforce_v_lims
0
enforce bus voltage magnitude limits
0 — do not enforce limits
1 — enforce limits
cpf.enforce_flow_lims
0
enforce branch MVA flow limits
0 — do not enforce limits
1 — enforce limits
cpf.step
0.05
default value for continuation power flow step size
tolerance for generator active power limit detection(MW)
cpf.q_lims_tol
tolerance for generator reactive power limit detection(MVAr)
cpf.v_lims_tol
tolerance for bus voltage magnitude limit detection (p.u)
cpf.flow_lims_tol
0.01
tolerance for branch flow limit detection (MVA)
cpf.plot.level
0
control plotting of nose curve
0 — do not plot nose curve
1 — plot when completed
2 — plot incrementally at each iteration
3 — same as 2, with pause at each iteration
cpf.plot.bus
empty
index of bus whose voltage is to be plotted
cpf.user_callback
empty
string or cell array of strings with names of user callbackfunctions†
†See help cpf_default_callback for details.
5.6.1 CPF Callback Functions
Matpower’s continuation power flow provides a callback mechanism to give the user
access to the iteration process for executing custom code at each iteration, for
example, to implement custom incremental plotting of a PV nose curve or to
handle a detected event. This callback mechanism is used internally to handle
default plotting functionality as well as to handle the standard CPF events. The
cpf_default_callback function, for example, is used to collect the and results
from each predictor and corrector iteration and optionally plot the PV nose
curve.
and the input and output arguments are described in Tables 5-3 through 5-5 and in the help
for cpf_default_callback. Each registered CPF callback function is called in
three different contexts, distinguished by the value of the first argument k as
follows:
1.
initial – called with k = 0, without results input/output arguments, after base
power flow, before first CPF step.
2.
iterations – called with k , without results input/output arguments, at
each iteration, after predictor-corrector step
3.
final – called with k , with results input/output arguments, after exiting
predictor-corrector loop, inputs identical to last iteration call, except k negated
Table 5-3:Continuation Power Flow Callback Input Arguments
name
description
k
continuation step iteration count
nx
next CPF state*,corresponding to proposed next step
cx
current CPF state*,corresponding to most recent successful step
px
previous CPF state*,corresponding to last successful step prior to cx
done
struct, with flag to indicate CPF termination and reason, with fields:
.flag
termination flag, 1terminate, 0continue
.msg
string containing reason for termination
rollback
scalar flag to indicate that the current step should be rolled back andretried with a different step size, etc.
evnts
struct array listing any events detected for this step‡
cb_data
struct containing static data§ , with the following fields (all based oninternal indexing):
.mpc_base
Matpowercase struct of base case
.mpc_target
Matpowercase struct of target case
.Sbusb
handle of function returningvector of complex base case businjections in p.u. and derivatives w.r.t.
.Sbust
handle of function returningvector of complex target case businjections in p.u. and derivatives w.r.t.
.Ybus
bus admittance matrix
.Yf
branch admittance matrix, “from” end of branches
.Yt
branch admittance matrix, “to” end of branches
.pv
list of indices of PV buses
.pq
list of indices of PQ buses
.ref
list of indices of reference buses
.idx_pmax
vector of gen indices of gens at PMAX
.mpopt
Matpoweroptions struct
cb_args
arbitrary data structure containing user-provided callback arguments
results
initial value of output struct to be assigned to cpf field of results structreturned by runcpf
*See Table5-5for details of the CPF state.‡See cpf_detect_events for details of the evnts field.§Please note that any callback that modifies the underlying problem is responsible to update the contents of cb_dataaccordingly. E.g. converting a bus from PV to PQ requires updates to mpc_base, mpc_target, Sbusb, Sbust, pv, pq,and possibly ref. So, cb_data should only be thought of as static for a fixed base and target case pair.
Table 5-4:Continuation Power Flow Callback Output Arguments
name
description
All are updated versions of the corresponding input arguments, see Table5-3for more details.
nx
next CPF state*,user state (cb field) should be updated here if rollbackis false
cx
current CPF state*,may contain updated this_step or this_parm valuesto be used if rollback is true
done
callback may have requested termination and set the msg field
rollback
callback can request a rollback step, even if it was not indicated by anevent function†
evnts
msg field for a given event may be updated‡
cb_data
this data should only be modified if the underlying problem has beenchanged (e.g. generator limit reached), in which case it should always befollowed by a step of zero length, i.e. set nx.this_step to 0§
results
updated version of results input argument to be assigned to cpf field ofresults struct returned by runcpf
*See Table5-5for details of the CPF state.†In this case, the callback should also modify the step size or parameterization to be used for the re-try, by setting thethis_step or this_parm fields in cx.‡See cpf_detect_events for details of the evnts field.§It is the job of any callback modifying cb_data to ensure that all data in cb_data is kept consistent.
Table 5-5:Continuation Power Flow State
name
description
lam_hat
value ofafter predictor step
V_hat
vector of complex bus voltages after predictor step
lam
value ofafter corrector step
V
vector of complex bus voltages after corrector step
z
normalized tangent predictor,
default_step
default step size
default_parm
default parameterization*
this_step
step size for this step only
this_parm
parameterization* for this step only
step
current step size
parm
current parameterization*
events
event log
cb
user state for callbacks† , a user-defined struct containing any informationa callback function would like to pass from one invokation to the next
ef
cell array of event function values
*Corresponding to the cpf.parameterization option in Table5-2.†Replaces cb_state from Matpower5.
The user can define their own callback functions which take the same form and are
called in the same contexts as cpf_default_callback. User callback functions are specified
via the Matpoweroption cpf.user_callback. This option can be a string containing the
name of the callback function, or a struct with the following fields, where all but the first
are optional:
fcn - string with name of callback function
priority - numerical value specifying callback priority,30
default = 20
args - arbitrary value (any type) passed to the callback as cb_args each time
it is invoked
Multiple user callbacks can be registered by assigning a cell array of such strings and/or
structs to the cpf.user_callback option.
5.6.2 CPF Example
The following is an example of running a continuation power flow using a version of the
9-bus system, looking at increasing all loads by a factor of 2.5. This example plots the nose
curve shown in Figure 5-1.
define_constants; mpopt = mpoption('out.all', 0, 'verbose', 2); mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.step', 0.2); mpopt = mpoption(mpopt, 'cpf.plot.level', 2); mpcb = loadcase('t_case9_pfv2'); % load base case mpct = mpcb; % set up target case with mpct.gen(:, [PG QG]) = mpcb.gen(:, [PG QG]) * 2.5; % increased generation mpct.bus(:, [PD QD]) = mpcb.bus(:, [PD QD]) * 2.5; % and increased load results = runcpf(mpcb, mpct, mpopt);
This should result in something like the following output to the screen.