
Учебники / 0841558_16EA1_federico_milano_power_system_modelling_and_scripting
.pdf506 |
A Python Libraries |
Returns:
samples there are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).
step (only if retstep is True) size of spacing between samples.
Examples:
>>> numpy.linspace(2.0, |
3.0, |
num=5) |
|
|
|||
array([ 2. |
, |
2.25, |
2.5 , |
2.75, |
3. |
]) |
|
>>> numpy.linspace(2.0, |
3.0, |
num=5, |
endpoint=False) |
||||
array([ 2. |
, |
2.2, |
2.4, 2.6, 2.8]) |
|
|||
>>> numpy.linspace(2.0, |
3.0, |
num=5, |
retstep=True) |
||||
(array([ 2. |
|
, 2.25, |
2.5 , |
2.75, |
3. |
]), 0.25) |
linalg.eigvals(A) computes the eigenvalues of a general matrix.
Parameters:
Aa complex or real square matrix whose eigenvalues and eigenvectors have to be computed.
Returns:
wthe eigenvalues. Each eigenvalue is repeated according to its multiplicity. Eigenvalues are not ordered and can be complex.
linalg.eig(A) computes eigenvalues and right eigenvectors of an array.
Parameters:
A a complex or real square matrix.
Returns:
w the eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ordered, nor are they necessarily real for real matrices.
v the normalized eigenvector corresponding to the eigenvalue w[i] is the column v[:,i].
meshgrid(x, y) returns coordinate matrices from two coordinate vectors.
Parameters:
x, y two one-dimensional arrays representing the x and y coordinates of a grid.
Returns:
X, Y for vectors x, y with lengths Nx=len(x) and Ny=len(y), return X, Y where X and Y are (Ny, Nx) shaped arrays with the elements of x and y repeated to fill the matrix along the first dimension for x, the second for y.
A.3 Matplotlib |
507 |
A.3 Matplotlib
Matplotlib is a library for making 2D plots of arrays in Python. The syntax is similar to that of Matlab graphic commands. However, Matplotlib is independent of Matlab, and can be used in a object oriented way. Matplotlib is based on NumPy.
axhline(y=0, xmin=0, xmax=1, **kwargs) draws a horizontal line at y from xmin to xmax. The line always spans the horizontal extent of the axes.
Optional arguments:
color any matplotlib color, e.g., ’k’ for black.
linestyle any line style expression, e.g., ’-’, ’--’, ’-.’, ’:’.
axvline(x=0, ymin=0, ymax=1, **kwargs) draws a vertical line at x from ymin to ymax. The line always spans the vertical extent of the axes. Optional arguments are same as for axhline.
figure(num=None) creates a new figure and returns an instance of the class matplotlib.figure.Figure. If num = None, the figure number is incremented and a new figure is created. The returned figure objects have a number attribute holding this number. If num must be an integer. If figure(num) already exists, the figure becomes active and a handle to that figure is returned. If figure(num) does not exist, a new figure is created.
grid(self, b=None, **kwargs) sets the axis grids on or o ; b is a Boolean. If b is None and len(kwargs)==0, the grid state is toggled. If kwargs are supplied, b is set to True. kwargs are used for setting the grid line properties.
hold(b=None) sets the hold state. If b is None (default), the hold state is toggled, otherwise the hold state is set to b. Examples:
hold() |
# toggle hold |
hold(True) # hold is on
hold(False) # hold is off
If hold is True, subsequent plot commands are added to the current axes. If hold is False, the current axes and figure are cleared on the next plot command.
legend(*args, **kwargs) places a legend on the current axes at location loc. Labels are a sequence of strings and loc can be a string or an integer that specifies the legend location. Available locations are ’upper right’,
’upper left’, ’lower left’, ’lower right’, etc.
plot(*args, **kwargs) plots lines and/or markers to the current axes. args is a variable length argument, allowing for multiple x, y pairs with an optional format string. For example, each of the following statement is allowed.
A.3 Matplotlib |
509 |
Arguments:
fname a string containing a path to a file name, or a Python file-like object. If format is None and fname is a string, the output format is deduced from the extension of the file name.
format one of the file extensions supported by the active back-end. Most back-ends support png, pdf, ps, eps and svg formats.
show() shows all the figures. This function should conclude the script. xlabel(s) sets the x-axis label of the current axis to string s. xlim(*args, **kwargs) sets or gets the x-limits of the current axes. The
new x-axis limits are returned as a length 2 tuple. Examples:
xmin, xmax = |
xlim() |
# return the current xlim |
|||||||
xlim( |
(xmin, |
xmax) |
) |
# set |
the |
xlim |
to |
xmin, |
xmax |
xlim( |
xmin, xmax ) |
|
# set |
the |
xlim |
to |
xmin, |
xmax |
ylabel(s) sets the y-axis label of the current axis to string s.
ylim(*args, **kwargs) sets or gets the y-limits of the current axes. The new y-axis limits are returned as a two-element tuple. Examples:
ymin, ymax = |
ylim() |
# return the current ylim |
|||||||
ylim( |
(ymin, |
ymax) |
) |
# set |
the |
ylim |
to |
ymin, |
ymax |
ylim( |
ymin, ymax ) |
|
# set |
the |
ylim |
to |
ymin, |
ymax |
Appendix B
System Classes
This appendix provides a quick reference of the classes DAE, Settings, CPF and OPF. These classes are used in the scripts provided in the book.
B.1 System Properties and Settings
DAE Di erential and algebraic equations, functions and Jacobians matrices.
Ac |
Complete DAE Jacobian matrix for numerical integration. |
|
f |
Di erential equations f . |
|
factorize If |
True, it forces the factorization of the system Jacobian |
|
|
matrix. |
|
Fx |
Jacobian matrix of di erential equations f x. |
|
Fy |
Jacobian matrix of di erential equations f y . |
|
h |
Inequality constraints h. |
|
g |
Algebraic equations g. |
|
Gmu |
Jacobian matrix of algebraic equations gμ. |
|
Gx |
Jacobian matrix of algebraic equations gx . |
|
Gy |
Jacobian matrix of algebraic equations gy . |
|
Gz |
Jacobian matrix of algebraic equations gz . |
|
Hes |
Hessian matrix multiplied by dual variables. |
|
Hz |
Jacobian matrix of inequality constraints hz . |
|
kg |
Variable for distributing losses among generators. |
|
mu |
Continuation parameter or loading level μ. |
|
ng |
Number of equality constraints. |
|
nh |
Number of inequality constraints. |
|
nx |
Number of state variables. |
|
ny |
Number of algebraic variables. |
|
nz |
Number of algebraic variables used in OPF analysis. |
|
obj |
Objective function ϕ. |
|
Oz |
Jacobian matrix of the objective function ϕz . |
|
pi |
Dual variables π of inequality constraints. |
|
F. Milano: Power System Modelling and Scripting, Power Systems, pp. 511–513. |
||
springerlink.com |
c Springer-Verlag Berlin Heidelberg 2010 |

512 |
B System Classes |
q Vector q used in numerical integration. rho Dual variables ρ of equality constraints.
sSlack variables s for OPF analysis.
tCurrent simulation time.
xState variables x.
yAlgebraic variables y.
zAlgebraic variables z used in OPF analysis.
Settings General settings and parameters for power flow computations and numerical integration.
deltat Time step for time domain integrations in seconds. deltatmax Maximum time step in seconds.
deltatmin Minimum time step in seconds.
disturbance If True, it forces the call of an external disturbance function during numerical integration.
dynmit Maximum number of iterations for each step of the numerical integration.
error Maximum equation mismatch.
fixt If True, it forces a fixed time step for numerical integration. freq System frequency rating in Hz.
tol Mismatch tolerance for static analyses (default 10−5).
method Numerical integration method (e.g., trapezoidal method, backward Euler, etc.).
mva System power rating in MVA (default 100 MVA).
pf max iter Maximum number of iteration of the power flow solver. pfsolver Power flow solver.
’DC’ Dc power flow. ’NR’ Newton’s method.
’XB’ XB variation of fast decoupled power flow. ’BX’ BX variation of fast decoupled power flow.
’RK’ Runge-Kutta-based continuous Newton’s method. ’IW’ Iwamoto’s method.
’SR’ Simple robust method.
rad System frequency rating in rad/s. t0 Initial simulation time in seconds. tf Final simulation time in seconds.
tstep Fixed step length Δt in seconds for numerical integration.
CPF Continuation power flow settings. |
|
method Method for corrector step. |
|
’perpendicular intersection’ |
Perpendicular intersection. |
’local parametrization’ |
Local parametrization. |
OPF Optimal power flow settings. |
|

B.1 System Properties and Settings |
513 |
eps1 Error tolerance of the power flow equations. eps2 Error tolerance of the objective function. eps mu Error tolerance of the barrier parameter μˆ. gamma Safety factor γ.
max iter Maximum number of iterations of the NLP solver.
method Method used for computing the variable directions and increments.
’Newton’ Newton’s directions. ’Mehrotra’ Mehrotra’s predictor-corrector.
sigma Centering parameter σ.

Appendix C
Control Diagrams
This appendix describes the representation of transfer functions through control diagrams and defines the notation used in the book. The control diagram approach is particularly suited for illustrating regulators but, in principle, can be used for any DAE system. Modelling and implementation of windup and anti-windup limits are also discussed.
C.1 Representation of Basic Functions
A control diagram is an oriented graph where arcs (arrows) indicate signal flows and nodes (blocks) indicate transfer functions (e.g., gain and integrator) or operations (e.g., sum and product). For example, Figure C.1 shows the detailed and compact notation of a lag transfer function:
x˙ = |
1 |
(Ky − x) |
|
(C.1) |
T |
|
|||
In Figure C.1, s represents the di erential operator, i.e., s = |
d |
. |
||
|
||||
|
|
|
dt |
Another example is shown in Figure C.2 that shows three possible representations of a lead-lag transfer function. The “parallel” model is described
by: |
1 − T2 |
y − x T2 |
|
||
x˙ = |
(C.2) |
||||
|
|
T1 |
|
1 |
|
w= T1 y + x T2
whereas the “series” model leads to the DAE system:
x˙ = |
1 |
(y |
− x ) |
|
(C.3) |
T2 |
|
||||
|
|
|
|
T1 |
|
w = T1x˙ + x = |
|
(y − x ) + x |
|||
T2 |
|||||
F. Milano: Power System Modelling and Scripting, Power Systems, pp. 515–521. |
|||||
springerlink.com |
|
c |
Springer-Verlag Berlin Heidelberg 2010 |

516 |
C Control Diagrams |
Gain |
Integrator |
|
|
Lag |
y |
+ |
x |
y |
x |
|
1 |
|
|
K |
K |
|
|
|
|
|
T s |
|
|
1 + sT |
|
− |
|
|
|
|
(a) |
|
|
(b) |
Fig. C.1 Lag diagram: (a) detailed diagram, and (b) compact diagram
y |
w |
1+ sT1
1+ sT2
|
|
|
|
|
|
|
|
|
|
|
Lead-lag |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(a) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y |
|
|
T1/T2 |
|
+ |
w |
|
y |
1 |
x |
+ |
|
|
w |
||||||
|
|
|
|
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
1 + sT2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ |
|
|
|
|
|
|
|
|
|
|
+ |
|||
|
|
|
T1 |
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
1 − T2 |
|
|
|
|
|
|
|
|
|
|
|
sT1 |
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 + sT2 |
x |
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(b) |
|
|
|
|
|
|
|
|
|
|
(c) |
|
|
|
Fig. C.2 Lead-lag diagram: (a) compact notation, (b) “parallel” model, and (c) “series” model
The state variable x in (C.2) takes di erent values than x in (C.3). Clearly, the output w is the same for the two models. Multi-pole and multi-zero transfer functions can be decomposed by both the “series” and the “parallel” approaches, but the “series” approach is generally more intuitive an easier to apply (see for example the transfer function of Figure 16.17 in Chapter 16).
C.2 Hard Limits
An important issue related to control systems is the way hard limits are handled. Hard limits consist in locking the output of a variable when it reaches a limit (or saturates). The simplest manner for modelling a hard limit is the windup model shown in Figure C.3.a. Mathematically, one has:

C.2 Hard Limits |
|
|
|
|
|
517 |
|||||||||
|
|
|
|
|
|
|
xmax |
|
|
|
|
|
xmax |
||
|
|
|
|
|
x˜ |
x |
|
|
|
|
|
|
x |
||
|
y |
1 |
|
|
|
y |
|
1 |
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 + sT |
|
|
|
|
|
|
|
1 + sT |
|
|
||
|
|
|
|
|
|
|
xmin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmin |
||||||
|
|
|
|
|
(a) |
|
|
|
|
|
(b) |
Fig. C.3 Hard limit diagrams: (a) windup model, (b) anti-windup model
xmax, if x˜ ≥ xmax
x = x,˜ if xmin < x˜ < xmax |
(C.4) |
xmin, if x˜ ≤ xmin
The windup limiter is also the simplest saturation model. Other saturation models are described in Subsection 15.1.8 of Chapter 15.
The windup limiter introduces a delay, also known as windup e ect. Figure C.4 illustrates the windup e ect of the system of Figure C.3.a assuming y(t) = sin(t), T = 1 s, xmax = 0.5 and xmin = −0.5. When the state variable x˜ > xmax at t = 1.34 s, the output x is locked. Afterwards, x remains locked until x˜ < xmax, which happens at t = 3.18 s.
The windup limiter is not adequate for modelling the behavior of the majority of real controllers, for which x is decreased when x˙ < 0. Figure C.4 also shows the output of the anti-windup limiter that, as expected, removes the windup e ect, i.e., x starts decreasing at t = 2.62 s, which is the instant for which x˙ becomes negative. Mathematically, the anti-windup limiter imposes conditions on both the state variable x and its time derivative x˙ , as follows:
if x ≥ xmax and x˙ ≥ 0 |
x |
= xmax and x˙ = 0 |
(C.5) |
if x ≤ xmin and x˙ ≤ 0 |
x |
= xmin and x˙ = 0 |
|
otherwise |
x˙ |
= (y − x)/T |
|
The amount of the delay introduced by windup limiters depends on how fast is the response of the system. The higher is the time constant T , the higher is the windup e ect, i.e., the delay. Hence, for low time constants (e.g., T < 0.1 s), the output of windup and anti-windup limiters is practically the same. Moreover, the windup e ect does not exist for algebraic variables, since these can be considered state variables with an infinitely fast dynamic (i.e., T → 0).
While it is relatively easy to implement an anti-windup limiter for a pure integrator or a lag transfer function, the model of an anti-windup limiter for lead-lags or PI (i.e., proportional and integral) controllers are not so