Combining Symbolic and Numeric Tools for Power System Network ...

12 downloads 541 Views 193KB Size Report
Page 1 ... equality constrained optimization problem associated to networks. .... Combining Symbolic and Numeric Tools for Power System Network Optimization.
Combining Symbolic and Numeric Tools for Power System Network Optimization 

Rainer Bacher

Abstract This paper describes a concept for the au-

tomatic code generation of the critical code parts of an equality constrained optimization problem associated to networks. The association to networks is quite general, however, a) restricted to a certain mathematical optimization problem structure and b) restricted to instances of function types associated to node and edge types. An equality constrained network optimization problem has code parts which remain unchanged for a wide variety of network component models. This part is hard-coded with Matlab using sparsity and array based, fast operations. Those Matlab code parts, however, which are node and edge network component dependent are autogenerated from a high-level symbolic Maple V de nition. The generated high quality code together with a robust algorithmic solution approach leads to a problem solving environment which satis es the robustness, code quality and code enhancement requirements of an on-line Energy Mananagement System (EMS) environment where the nal problem solution code should be used.

Introduction

Energy Management Systems (EMS) represent computer based systems to support the control and operation of high voltage electrical power systems. The electrical power system consists of network components which allow the transfer of power generated at hydro or thermal power stations to locations in other geographic areas where power is consumed (so-called loads). This transfer of electrical power has a very high degree of freedom because power can in principle be generated at any generator location within the physical limits of the generation system. However, the transfer to the loads is governed by two problems: First the Kirchho laws force the power through the transmission network in a way which is not easily predictable and secondly, the transmission elements themselves have operational limits which must be considered by controlling the power system. The most important controls in an electric power systems are generator active powers, generator reactive powers or voltages, transformer tap positions, shunt element and recently, FACTS (Flexible AC Transmission Elements) devices to in uence the impedances  Postal

address: ETH Zurich, The Swiss Federal Institute of Technology, ETL J34, CH-8092 Zurich, Switzerland; Email: [email protected]; WWW: http://www.eus.ee.ethz.ch/~bacher

of the network at certain locations. Through these control means a high degree of freedom is introduced into the transfer and generation of power. This high degree of freedom and the Kirchho laws make the ows of highly meshed networks quite unpredictable. This has created the need for sophisticated EMS. EMS are today an embedded part of the control system to optimally schedule controls, manage power transfers, maintain transmission security (no black-outs even when one network elements is outaged), manage environmental issues (generate as much as possible \clean" power), keep total power generation and network maintenance costs low. EMS contain a large model of the real-world power system. This large model allows the consideration of the Kirchho laws and operational constraints of the power transmission in a computer simulation. This model comprises transmission lines, voltage transformers, active power generators, reactive power consumers or generators. Today, the electrical behavior of these elements is well understood: The model \quality" depends mainly on the time frame during which they are used. In this paper we concentrate on the so-called stationary network conditions. Stationary conditions are never exactly satisi ed in the real-world power system, however, for normal operational conditions they are satis ed to a very high degree. Perfectly sinusoidal signals for voltages, currents and powers as function of time are equivalent with stationary conditions. Stationary conditions allow the transformation of the time domain model to complex variable based models for the electrical power transmission network. Assuming that a transmission network can be represented as nodes and edges between nodes, the network model can be completely described by formulas related to nodes and edges. Depending on the node and edge type different formulas are necessary. It is important to note, however, that although a power transmission model can consist of more than thousand nodes and more than 1500 edges, the number of types of edges and the number of types of nodes is much smaller: Typically a model comprises less than 10 node types (PV-generator node, PQgenerator node, PQ-load node, Slack-generator node, Area-Slack node, remotely controlled node, node with variable shunt reactance, etc.) and also less than 10 edge types (High voltage transmission line, phase shifter transformers, voltage magnitude transformer, series reactance, etc.). Each of these node and edge types is modelled with a set of di erent algebraic non-linear formulas. Each formula is a function of given parameters and unknown variables.

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

1

Combining Symbolic and Numeric Tools for Power System Network Optimization Throughout this paper the set of parameters and unknown variables is identical for each node or edge type. However, the actual values for these parameters and unknowns will vary for each of the 1000 nodes and 1500 edges. This node and edge type oriented model functionality is bound together by the Kirchho laws which sets conditions at each node: First, the currents at any node must add up to zero and second, nodes and connected edges have identical voltages. To summarize, the approach described in this paper assumes a network where model based characteristics must be de ned. Model characteristics are based on node and connected edge types which are shown in Fig. 1. L1

L2 1

2

3

4

7

8

L3 5

6

9

with variables of connected edges. It is important to understand that what remains constant for every EMS application is the fact that Kirchho laws must be valid. However, the types of nodes and edges, associated nonlinear functional behavior together with parameter and unknown variable sets vary strongly dependent on the application and on the installed devices of the power transmission network. It is this wide variation of the model which a power system engineer or organization developing EMS software must manage. The resulting EMS software must also satisfy the requirements of high computational robustness (code should never crash and must end in a controlled way), high execution speed (real-time software supporting real-world, important societal processes), easy code maintenance and adaptability. The approach presented in this paper combines a

exible model formulation with a power system application area, the equality constrained network optimization. It is presented in Fig. 2. Symbolic framework definition (Language: Maple V) (PHASE A)

12 11

10

13

14

is input to L4

L6 L5

G1

G2

G3

Figure 1: Example of a 14 nodes/16 edges network Of the 14 nodes in Fig. 1, nodes 1, 3, 6, 12 have an associated symbol Li. This indicates the type Loadnode (LD) for these nodes. Node 13 has an associated symbol G2. This indicates the type generatornode (GN) for node 13. Nodes 10 and 14 have both associated symbols Li and Gj. These nodes are called Load , Generatornodes (LG). Nodes 9 and 11 have an associated shunt device and are called shuntnodes (SN). The remaining nodes 2; 4; 5; 7; 8 have only edge connections and are thus called zeroload nodes (ZN). Of the 16 edges, edges between nodes 1-5, 2-6, 3-8 and 4-9 have a special associated symbol. These edges are called transformer (TR) branches in contrast to the others which are called transmissionline (LI) branches. For this network example we have used 5 node types (LD, GN, LG, SN, ZN) and 2 edge types (LI, TR). Each of these types has a special model formulation with a given parameter and unknown variable set. Each instance of a node and edge type has individual parameters. Depending on the actual (optimization) problem formulation these node and edge types and associated parameter and unknown variable sets can vary from one power system model problem to the next. Often, parameters in one problem formulation will be unknowns in the next or vice-versa. In addition, for all nodes, the Kirchho laws are valid. In a generalized view they state that certain variables at every node must add up to a give value and certain variables related to nodes have identical values

Symbolic program to generate framework dependent matlab code (Language: Maple V) (PHASE B)

generates adaptive parts of

influences format of

Formatted network parameter and initial value data

is input to

constitutes static parts of

Optimization problem solver code (Language: Matlab) (PHASE C)

computes iteratively

Numeric problem solution

Figure 2: Overview of approach In phase A, the exible model formulationis achieved using the high-level symbolic formulation capabilities of Maple V. The other requirements such as algorithmic robustness, high execution speed and easy code adaptability are achieved by using Matlab (phase C) as the numeric computational and coding environment for those parts of the algorithm which remain constant within the chosen application area. Those parts of the Matlab code which vary depending on modelling assumptions are autogenerated from the Maple V high level symbolic formulation using the expression di erentiation, simpli cation and code generation facilities of this package (phase B). The approach presented in this paper is applied to the domain of network optimization. Conceptually similar approaches have been published: [1] describes a domain concept to realize general non-linear network op-

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

2

Hard-coded optimization problem parts (Language: Matlab)

Combining Symbolic and Numeric Tools for Power System Network Optimization timization problems. The paper concentrates on formalization. [2] uses a knowledge based approach which allows to specify scienti c-computing problems. This speci cation results in a high-level language description that is transformed by domain-independent rules. [3] summarizes the strenghts of problem solving environments (PSE). Using the de nitions of this paper, the present approach can be de ned as a PSE. Other approaches are described in [4] and [5]. There, the e ort is concentrated on automatic code di erentiation and automatic code generation of rst order partial derivatives of any FORTRAN 77 (in ADIFOR [4]) and rst and second order partial derivatives of Maple V (in [5]) code representing functions. The research presented in this paper is currently also extended to include the approach of automatic code di erentiation. ADIFOR, however, does not need the domain structures presented in this paper. It must be seen on a more generic compiler level. The paper is organized as follows: In section 2, the application area of the equality constrained network optimization and the associated solution algorithm is brie y explained. In section 3, the special structure of equality constraints and the objective function related to network optimization problems is discussed. In section 4, a framework is discussed which includes the concept of node and edge functionality together with associated symbol sets. Section 5 shows how the optimization problem is formally de ned using the framework de nitions of sections 3 and 4. In section 6 software aspects of combining symbolic (Maple V) and numeric (Matlab) tools are discussed to realize the numeric algorithm of section 2 combined with the user-speci cation of the equality constrained optimization problem of section 5. In section 7, important aspects of code maintenance and adaptability including code quality and correctness are discussed. The paper ends with conclusions in section 8 and the references.

large (several 1000) the BFGS is considered a rather slow method due to a rather inaccurate approximation of the inverse of the Hessian. In general, for problems in the domain of electrical power networks, the Newton method converges much quicker and satis es industrial requirements. The main algorithmic step is the solution of the following sparse linear system of equations (The index (k) refers to numerical values at NR iteration k):

The equality constrained optimization can be stated as follows: Minimize F (x) subject to g(x) = 0 (1) All equations and terms in (1) are twice continuously di erentiable. All variables x are real and continuous. The general equality constrained optimization problem (1) is solved by applying a Newton-Raphson (NR) to the Karush-Kuhn-Tucker optimality conditions of the equality constrained optimization problem which are the right hand side functions of (2). The algorithmic method itself is not the main subject of this paper. It is only indicated here to show the coding complexity associated to the chosen algorithmic solution. An alternative to the chosen approach is the BFGS method. Due to the fact, that the number of variables, equality and inequality constraints can be quite

Equality constrained network optimization: Structure

Equality constrained network optimization: Algorithmic approach





H kk J k T J 0 ( )

( )

( )

with 2 H(k) = @ @Fx(2x)



k

x( )

+

x kk  = ,  r kk g  ( )

( )

( )

( )

m  X i=1

ik

( )

@ 2 g (x) @ x2 i





k

(2)

(3)

x( )

and (k )

J

h (k) i  @g(x) = @x (k) ; gr (k) = x

@F (x) @ x x(k)

+ J(k)T (k) g(x(k) )



(4)

The problem (1) is solved as follows with an iterative NR approach: Set k = 0; With given values for x(k); (k), the linear system (2) is solved. The  (solution k+1)); (k+1) := vector is then added to the previous solution: x  (k) (k)   x ;  + x(k); (k) . k is increased by 1. With the new solution x(k); (k), (2) is solved again, variables are updated, etc. Finally a converged solution is obtained, if the maximumabsolute rhs-value of (2) is below a prede ned tolerance . The software engineering challenge of this algorithm is the correct coding of all terms in the Hessian H (3), the Jacobian J (4) and the right hand side terms of (2) considering at the same time the inherent sparsity of these matrices when the optimization problem is applied to a network.

The equality constrained optimization problem formulation and its subsequent automatic NR code generation parts are restricted to a special structure of a network oriented objective function and equality constraints. This objective function will consist of partially separable functions where each individual function (called basic function) belongs to an instance of an edge type or a node type.

Objective function structure: F (x) = +

P

P

k2Oed

k2Ond

P

) Minimum

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

P

(xkndi ) i2NOk gkndi  

ij2EdOk gkedij

xkedij

3

(5)

Combining Symbolic and Numeric Tools for Power System Network Optimization

Equality constraints structure: Equality constraints

must be formulated per node or edge type and must be dependent on the parameters and unknown variables of basic node or edge functions. Equality constraints can only be formulated for all instances of nodes and edges of a node or edge type. gkndi (xkndi )  gkedij xkedij

= 0 (k 2 End ; i 2 NEk ) = 0 (k 2 Eed ; ij 2 EdEk )

(6)

The used abbreviations are as follows: nd A (graph) node. ed gkndi gkedij

xkndi xkedij F Nd F Ed Nd Ed Ond Oed End Eed NOk NEk EdOk EdEk Edki

A (graph) directed edge connects two nodes. Basic node function k associatedto node i (twice continuously di erentiable) Basic edge function k associated to edge ij (twice continuously di erentiable) Unknown node variable set of gkndi Unknown edge variable set of gkedij Main set of basic node functions Main set of basic edge functions Main set of node types Main set of edge types Subset of F Nd for objective (O) function parts Subset of F Ed for objective (O) function parts Subset of F Nd for equality (E ) constraints Subset of F Ed for equality (E ) constraints Subset of Nd associated to Ondk (the k-th entry of Ond ) Subset of Nd associated to Endk (the k-th entry of End ) Subset of Ed associated to Oedk (the k-th entry of Oed ) Subset of Ed associated to Eedk (the k-th entry of Eed ) Subset of Ed associated to Gki

Framework speci cation

In addition to node and edge related equality constraints, the so-called Kirchho laws can be instantiated as equality constraints. The Kirchho laws are assumed to be hardcoded, however, they can be parametrized as follows: The rst Kirchho law is generalized in such a way that at every node i of the network graph the sum of a variable named \var" at the node itself and the sum of a variable with the same \ ow base name" \var" of all connected edges adds up to a user de ned parameter flowvari for each node i. vari +

X

j 2i

varij = flowvari ; 8 nodes i

vari , varij = 0 ; 8 nodes i and all connected edges j (8) Similar to the \ ow base names" of variables the model speci er can give \potential base names" for which this law (8) must be valid. Any number of potential base names can be speci ed. However, the basic functions for node and edge types must use the same \potential base name" in order to allow a correct instantiation of the potential law equations. The following rules are important: Variable of edge related basic functions belonging to the set of \ ow" or \potential variables" must have as one part a \ ow/potential base name" and as a second part an index 1 or 2 indicating the two ends of the edge. This implies that an edge is directed in the model. Variables of node types belonging to the set of \ ow" or \potential variables" must have a name identical to the \ ow/potential base name\ without any additional index.

(7)

In (7), j 2 i indicates that all edges (of any edge type) connected to node i are included. The \ ow base name" of a variable is the part of the variable name without any indices. The user can specify any set of \ ow base names" of variables for which this ow law must be satis ed. This notation implies that the user uses the same \ ow base name" for node and edge related functions when specifying the basic functions. The second Kirchho law allows the formulation of identities of variables of nodes with those of connected edges:

To establish a user-de nable framework which sets the functional boundaries of the equality constrained optimization problem (5) ... (8), basic functions together with sets of associated symbols have to be de ned. In addition, names for all \ ow base variables" and \potential base variables" must be given to allow Matlab code generation for the Kirchho laws. This rst step does not de ne the type of equality constrained optimization which, however, will be de ned later using the framework de nition of node/edge types, basic functions and associated symbols, \potential" and \ ow" base names.

Basic functions and associated symbols

A set of basic node and edge functions of a typical framework for power transmission network models is shown in (9) thereby using a rectangular coordinate formulation which is similar to the current mismatch based power ow formulation [6], [7]. function formula basic function g1ndi eIe + fIf , P g2ndi g3ndi g4ndi g5ndi g6ndi g7edij g8edij g9edij g10edij

fIe , eIf , Q ,e2 , ,f 2 + V 2  2 1 w  P , P (0) 2 P ,  2 1 w  Q , Q(0) 2 Q , 2 1 w  V 2 , V 2(0) 2 V2 Ie1 , (g11 e1 , b11 f1 ) , (g12 e2 , b12 f2 ) If1 , (g11 f1 + b11 e1 ) , (g12 f2 + b12 e2 ) Ie2 , (g21 e1 , b21 f1 ) , (g22 e2 , b22 f2 ) If2 , (g21 f1 + b21 e1 ) , (g22 f2 + b22 e2 )

In (9), e; f; e1 ; e2; f1 ; f2 represent the real (e) and imaginary part (f) of the complex voltage at a node and edges (edge ends 1/2), P; Q represent the active and reactive power at a node, g11, b11, g12, b12, g21, b21,

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

4

(9)

Combining Symbolic and Numeric Tools for Power System Network Optimization g22, b22 the two-port parameters of a transmission line or transformer branch from node i to node j, V 2 the squared voltage magnitude at a node, P (0); Q(0) represent the measured active and reactive power at node i, V 2(0) the measured squared voltage magnitude at a (PV-generator) node. Ie, If, Ie1 , Ie2 , If1 , If2 represent the real part (Ie) and the imaginary part (If) of the current of nodes or edges. Index 1 indicates side 1 of the edge, index 2 indicates the other side 2 of the edge. The symbols used in (9) are formally speci ed: symbol set basic function g1ndi g2ndi g3ndi g4ndi g5ndi g6ndi g7edij g8edij g9edij g10edij

e; f; P; Q; Ie e; f; P; Q; If e; f; V 2 wP ; P; P (0) wQ ; Q; Q(0) wV 2 ; V 2; V 2(0) Ie1 ; e1 ; f1 ; e2 ; f2 ; g11 ; b11 ; g12 ; b12 If1 ; e1 ; f1 ; e2 ; f2 ; g11 ; b11 ; g12 ; b12 Ie2 ; e1 ; f1 ; e2 ; f2 ; g21 ; b21 ; g22 ; b22 If2 ; e1 ; f1 ; e2 ; f2 ; g21 ; b21 ; g22 ; b22

(10)

All symbols used in (9) must be speci ed without any exception. From (9) one concludes that FNd = f 1, 2, 3, 4, 5, 6 g (the main set of basic node functions) and FEd = f7; 8; 9; 10g (the main set of basic edge functions).

\Potential" and \ ow base name" symbol sets Based on the symbols de ned in (10) the \ ow" and \potential" base name sets are speci ed as follows:

ow base names fIe; If g potential base names fe; f g

Node and edge types

The set of node (ND) and edge (ED) types has been arbitrarily de ned based on the network example given in the section \Introduction": ND f LD, GN, LG, SN, ZN g ED f LI, TR g. Advanced power system network models comprise more node and edge types. They are omitted for space reasons and for clearer presentation.

Speci cation of the equality constrained optimization problem using framework de nitions

The basic functions de ned in (9) are functions of symbols (10) which can either be unknown variables or given

parameters, depending on the node or edge type and the type of equality constrained network optimization. Variables and constants must be distinguished in order to allow automatic derivative computation of all basic functions with respect to those symbols which are unknows in the application. All symbols characterized as constant parameters are assumed not to change for any equality constrained optimization program execution with the autogenerated code. They are assumed to be read from an input data set as given, xed parameter values. Each input data set constitutes a network instance. Since the objective functions are by de nition (5) sums of basic node and edge type functions, the rst and second order derivatives of the objective function is identical with the sums of rst and second order derivatives of a user-speci ed subset of all basic functions. Thus the informationwhich needs to be user-speci ed is which ones of the basic node and edge functions are to be used in the objective function and which ones as equality constraints. Note that in the objective function it is implied that the sum over all instances of a basic function for a speci ed node or edge type is to computed. For equality constraints, it is implied that an individual equality constraint is computed for all instances of a basic function for a speci ed node or edge type. To explain how this optimization problem is speci ed, an example of an equality constrained optimization problem for an electrical power transmission network is given: P

Minimize F (x) = P i2all nodes g4ndi (Pi ) + Pi2LD, ZN g5ndi (Qi) + i2GN, LG, SN g6ndi (V 2i ) subject to g1ndi (ei ; fi ; Pi ; Qi ; Iei ; Ifi ) = 0 (i : all nodes) g2ndi (ei ; fi ; Pi ; Qi ; Iei ; Ifi ) = 0 (i : all nodes) g3ndi (ei ; fi ; V 2i ) = 0 (i : GN, LG, SN) g7edij (Ie1ij ; e1ij ; e2ij ; f 1ij ; f 2ij ) = 0 (ij : all edges) g8edij (If 1ij ; e1ij ; e2ij ; f 1ij ; f 2ij ) = 0 (ij : all edges) g9edij (Ie2ij ; e1ij ; e2ij ; f 1ij ; f 2ij ) = 0 (ij : all edges) g10edij (If 2ij ; e1ij ; e2ij ; f 1ij ; f 2ij ) = 0 (ij : all edges) (11)

In additionPthe Kirchho laws must be satis ed: P Iei + Pj2i Ie1ij + Pj2i Ie2ij Ifi + j2i If 1ij + j2i If 2ij ei , e1ij ei , e2ij fi , f 1ij fi , f 2ij

=0 =0 =0 =0

= 0 (i : all nodes) = 0 (i : all nodes) (i : all nodes and j 2 i) (i : all nodes i and j 2 i) (12) (i : all nodes i and j 2 i) (i : all nodes i and j 2 i)

Both (11) and (12) have to be entered in a formalized way: (12) is entered as follows:

KH1 = ffIe; 0g ; fIf; 0gg and KH2 = fe; f g. In KH1, a pair such as fIe; 0g indicates that the sum of all \ ow variables" with a base name of Ie must add

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

5

Combining Symbolic and Numeric Tools for Power System Network Optimization up to zero (this value of zero is the second parameter of each pair) at all nodes. In KH2, each entry indicates identity of all variables of a node and all connected edges having the same \potential base name". This de nition is equivalent to (12). The objective function (O) and the equality constraints (E ) (with the exception of the Kirchho laws (12)) are de ned as follows: For each basic function i which is used in either O or E the developer has to specify a) the associated node types, b) the set of unknown variables and c) the set of constant parameters. Points a), b) and c) are speci ed as sets. A basic function may be used several times with di erent associated node types, unknown variable sets or di erent constant parameter sets. Formally, this is done by specifying fi; fa)g ; fb)g ; fc)gg for each of these combination to be used in either O or E . For each set fi; fa)g ; fb)g ; fc)gg, the combined set of unknown variables fb)g and constant parameters fc)g must be the complete set of symbols, associated to a basic function i, see (10). For the above application example this speci cation is as follows for the objective function O:

all basic functions with respect to all unknown variables of these basic functions for the associated node or edge types. The desired functionality of the equality constraint network optimization can easily be expanded by additional node and edge types typical for electrical power transmission systems (for example PQ-generator nodes, slack nodes, phase shift transformer branches, DC line branches, etc.) together with associated basic functions, unknown variable and parameter sets. The key point in the creation of the nal functionality of the equality constrained optimization problem is the fact that the nal optimization code will be based on instances of an individual basic function for all nodes or edges of a speci ed node or edge type.

Symbolic and numeric software aspects

From a software point of view several problems must be solved: One is the algorithmic solution to the equality constrained network optimization. The problem is the correct coding of the sparse Hessian (3), Jacobian matrices and the right hand side optimality conditions   These code parts depend on the model properties (0) O =  4; fLD; GN; LG; SN; ; f P g ; wP ; P ; (4). of the objective functions and the equality constraints  ZN g(0) ; and cannot be hard coded. In addition, the huge sparse 5; fLD; ZN g ; fQg ; wQ ; Q  6; fGN; LG; SN g ; fV 2g ; wV 2 ; V 2(0) linear system of equations (2) has to be solved by an (13) ecient sparse linear system solver. Matlab solves the general system of equations The equality constraints are speci ed as follows: Ax = b (15) E= with a given sparse matrix A and a given right hand ff1; fLD; GN; LG; SN; ZN g ; fe; f; P; Q; Ie; If g ; fgg ; side vector b for the unknowns x. The user has to input f2; fLD; GN; LG; SN; ZN g ; fe; f; P; Q; Ie; If g ; fgg ; the desired matrix coeents Aij by de ning in principle f3; fGN; LG; SN g ; fe; f; V 2g ; fgg ; three arrays row, col, value, where a triplet row(k) = f7; fLI; TRg ; fIe1 ; e1; f1 ; e2; f2g ; fg11; b11; g12; b12gg ; i; col(k) = j; value(k) = Aij de nes a non-zero entry f8; fLI; TRg ; fIf1 ; e1; f1 ; e2; f2g ; fg11; b11; g12; b12gg ; Aij . The vector b is full. It is important to understand f9; fLI; TRg ; fIe2 ; e1; f1 ; e2; f2g ; fg21; b21; g22; b22gg ; that in Matlab, row, col and value can be speci ed as f10; fLI; TRg fIf2 ; e1 ; f1; e2; f2 g ; fg21; b21; g22; b22ggg (14) arrays. In order to create sparse matrices these three This information allows the computation of the fol- arrays must be lled with triplet data sets. Another problem is the de nition of the framework lowing using a tool such as Maple V: Each node or edge has a unique associated node or edge type. Each node parts associated to classes of equality constrained optimization problems. This framework has been speci ed or edge type has a superset of unknown variables and in detail in the preceding sections, however, its software constant parameters: This superset can be determined from (13) and (14). For example the node type GN will realization has not yet been discussed. In the software process the following important points must have the set of unknowns fe; f; P; Q; Ie; If; V 2g and the engineering  be considered: (0) set of parameters wV 2; V 2 . All instances of a node The framework parameters must be enterable in an or edge type will have these identical sets of unknown easy way. This allows later modi cation and functional variables and parameters. expansion of the framework. This has been achieved by In addition, one derives the information related to allowing the user only to enter simple lists of node/edge basic objective function parts and equality constraints types, lists of basic functions, etc. from (13) and (14) for each node and edge type. For exAll entered framework parameters must be interample the node type LD will have the objective function pretable by a symbolic program (in this case Maple V related basic functions f4; 5g and the equality constraint has been chosen). This program must have the capabilrelated basic functions f1; 2g. ity of computing derivatives, of printing these computed Thus, the information in (9), (13) and (14) is susymbolic expression in another language (Matlab has cient to compute all rst and second order derivatives of Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

6

Combining Symbolic and Numeric Tools for Power System Network Optimization

User symbols and internal symbols

Two types of program symbols are used: \User" symbols (i.e. sets of unknown user variables, sets of given user parameters) and \internal" symbols: User symbols refer to those names which are used in the Maple V speci cation (10). In the Matlab code generation process they will be used in the generated Matlab code to allow an easier analysis of the generated Matlab code. The in-

ternal symbols, however, indicate the variables x and  which are used when solving the sparse linear system of equations (2) with the general purpose sparsity solver package. Although this is not the most ecient solution, user and internal variable values are copied back and forth (Matlab code steps C, H). This approach, however, allows the generation of rst and second order derivative Matlab code using user symbols. Internal symbols are used for the sparsity solver. Experience has shown that this approach is the best compromise between eciency (best would be to code all Matlab parts using internal variables) to highest readability (all Matlab code parts using user variables). The chosen approach allows the speci cation of well known symbol names by a domain specialist. These symbol names will also appear in the generated Matlab code. The complexity of generating code which maps user to internal data and vice-versa, can best be discussed at the example of the linear system matrix of (2). Using the framework speci cation boundaries and formally restricted way of de ning an equality constrained optimization problem leads to a special structure for the matrices H and J in (2). x  JT

H

r

A=

b=

J

0

g

Figure 3: Linear System matrix and right hand side

xNodes

xNodes LD GN

0

xEdges

0

0

LD

H=

xEdges

been chosen) which has in its nal form fast numeric execution capabilities. Before printing expressions in another language, usually language speci c code parts must be added to create correct syntax. Also, capabilities must exist which allow the simpli cation of derived expressions. Without this feature the generated code would loose runtime eciency which would not be tolerated by a user community used to hand-coding problems. Maple V satis es all these requirements. Interfaces have to be generated which allow the computation of the generalized sparse linear system form needed in Matlab from the expressions mentioned above. General information has to be generated and added to the Matlab code which allows to understand the generated program parts by an experienced programmer. Often this includes generated comment statements. Beside these problems the developer has to decide which parts of the algorithmic Matlab based solution will be hard-coded and which parts will be generated from the Maple V based optimization problem speci cation. Fig. 6 shows the structure of the Maple V program which handles the user-speci cation of the framework, the speci cation of the equality constrained optimization problem and the generation of all those Matlab code parts of the algorithmic solution which are dependent on these speci cations. Fig. 7 shows the most important parts of the numeric equality constrained optimization algorithm. Some parts of this algorithm are hard-coded, some are generated by the Maple V program shown in Fig. 6. In Fig. 6 parts 1 ... 6 represent the parts which allow the user the speci cation of the framework (1 ... 4) and the equality constrained optimization problem (5 ... 6). Parts 7 ... 11 represent Maple V code which generates model dependent Matlab code parts. In Fig. 7, part A allows to read network data which is then assigned (part B) to user data (both unknown variables and parameters). Part C uses a Maple generated part to assign/copy the user data of the unknown variables to internal data arrays x and . Parts D and E use mapping information to initialize matrices and arrays. Part F is autogenerated and is heavily dependent on Maple V user speci cation: At runtime, executing this code part allow the display of all user variables (each having a user speci ed name). Parts G ... I form the main Newton-Raphson iteration: The linear system matrix and the right hand side vectors of (2) are computed using auto-generated code until nal convergence is reached.

LI

0

TR

0

LI

0

TR

Figure 4: Matrix H properties Fig. 3 shows the structure of the linear system matrix as used in the generated code. Both H (Fig. 4) and J (Fig. 5) use rst the node variables and then edge

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

7

Combining Symbolic and Numeric Tools for Power System Network Optimization xNodes

xEdges

gndi

LD GN

0

0

0

LD LI

gedij

TR

gKH 1

J=

0

TR

1 1 1

gKH 2

LI

0

1

0

1 1 1

1 1

1

-1 1

-1 1

-1

Figure 5: Matrix J properties variables. Node and edge variables are grouped in such a way that all those variables belonging to the same node or edge come behind each other. In the matrix J, the equations are ordered as follows: First, the node related, then edge related, then ow law (Kirchho 1) related, then potential law (Kirchho 2) related. This creates block diagonal matrices which are for illustration purposes denoted with LD, GN, ... ,TR in Fig. 4 and in Fig. 5. These block matrices contain mostly non-zero elements which must be computed at every iteration of the Newton-Raphson step. Identical node and edge types in the blocks of Figs. 4 and 5 indicate that these nodes or edges have the same associated set of unknown variables and, they have one or more associated sets of the form fi; fa)g ; fb)g ; fc)gg either objective function O or equality constraints E related. For the Matlab code which computes the terms in these block matrices one array statement is generated for each basic function of a set fi; fa)g ; fb)g ; fc)gg. These array statements include two index arrays pointing to the correct row and column o sets for each node or edge instance in (4) and (5). These index arrays are also automatically generated: At Matlab program generation time one knows the number of unknown variables per node or edge type which allows the generation of these index arrays. The creation of the entries +1 or ,1 in the two lower submatrices of J follows a slightly di erent rule: Here the code generating Maple V program nds the place of

ow and potential variables within the variables of the unknown variable set of nodes and edge types to be used in the equality constrained optimization program. Thus Matlab code is generated which goes over all nodes and edges of a network instance and sets the correct +1 or ,1 values in these submatrices. Again, array statements

allow the generation of relatively simple and easy to read Matlab code parts. Finally the Matlab code for the numeric computation of the right hand side functions r and g of (2) has to be generated. This is, however, quite simple: Node and edge related objective and equality constraint terms are separated. Code generation creates the code parts for each separated symbolical function. Again, index arrays have to be generated which set the correct o sets for the speci c nodes and edges. All these index arrays de ne the mapping of internal to user variables and vice-versa. The Matlab language is ideally suited because it allows the coding of these index arrays for copying data sets, pointing to a whole set of matrix places of a sparse matrix and forming the complete linear system matrix (2) from the H and J submatrices. In addition to these key algorithmic parts additional information is generated which helps to understand intermediate steps of the algorithm (for example step F in Fig. 7). One place where the framework speci cation and subsequent Matlab code generation comes in con ict with hard-coded parts are parts A and B of the Matlab code part. In part A, network data is read from domain speci c \standardized" ASCII-data sets into Matlab variables. These Matlab variables, however, have no formalized association to the framework symbols. At this stage of the development process, the transfer of Matlab variables to user parameter data and to set initial values for the unknown user variables is hard-coded. This has the disadvantage that this code part has to be changed for the same network data set type, whenever symbols are changed in the framework speci cation. An automatic code generation will only be possible for this part of the Matlab program if the format of the ASCII-data set and the mapping to user data (both unknown variables and parameters) can also be userspeci ed in an extended framework.

Code maintenance, adaptability, quality and correctness

This concept has been realized and been tested with electrical networks of more than 500 nodes and edges. This has lead to linear systems of more then 4000 variables. During the development process several interesting points have been observed: Coding errors have appeared at various places of the development process: In those Maple code parts which generate the model dependent Matlab code sections, in the hard-coded Matlab code parts which use interfaces to generated code parts, in the sections where the Maple V framework and the equality constrained optimization structure are speci ed. Assuming correct Matlab syntax the executed code has usually performed totally wrong (strongly diverging cases; singular matrix generation; non-quadratic matrix generation) in cases where

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

8

Combining Symbolic and Numeric Tools for Power System Network Optimization code generation errors have propagated into several code parts of the Matlab code. Once the approach is established and tested with a network the experienced user wants to \play" with the code and generates new problem formulations based on slightly modi ed framework and optimization problem formulations. These new problem formulations often solve the same or a similar non-linear optimization problem, however, using for example the polar coordinate formulation and not the cartesian formulation. This contrasts with the traditional approach where the developer hand-codes the problem. Usually one is satis ed with a single software solution to the algorithmic problem. Also, the set of unknown variables and constant parameters is easy to change and slight variations to the equality constrained optimization can lead to executable Matlab programs which lead to new insights into the algorithmic convergence behavior, into solution sensitivities, etc. The concept allows the solution of domain problems from a higher conceptual level: Traditionally, the problem solution code has been hand-coded to solve problems of one domain using array and variable names commonly known in the domain such as the electrical power

ow. This code has never been applicable to applications outside the domain. However, in the presented framework based concept one can imagine the use of the framework for example in the area of gas/water networks: There, networks allow the transportation of a physical material from sources to sinks. Also, the transported material and the network can be modelled with algebraic equations and the network poses constraints on the transported materials.

Conclusions

In this paper the concept of a framework based equality constrained network optimization has been discussed. The rst key point is the creation of the concept of de ning framework boundaries by specifying basic node and edge functions together with associated symbol sets. The framework is \naturally" bound to an instantiation of the so-called Kirchho laws which establish a) identity of node variables to connected edge variables and b) a given sum of same-type variables of a node and connected edges. The second key point is the formalized speci cation of an equality constrained optimization problem which often arises in network related problems. Here, the user must specify which parts of the framework are used in the objective function and also the equality constraints, which framework symbols are unknown variables and which ones are constant parameters. With this information a Maple V program has been written which generates those Matlab code of the NewtonRaphson based numeric solution algorithm which depend on the framework speci cations. Matlab has mainly been chosen because of its strong array operation based code and sparsity features and because of its developer-

friendly coding environment. The concept as presented in this paper could also be realized with other symbolic computational tools. All that is needed are features such as symbolic de nition, derivative computation, expression simpli cation and code generation. Also, Matlab can in principle be replaced by any ecient numeric solution environment which allows the handling of large sparse linear systems of equations. With this approach a good compromise to practical requirements of EMS (Energy Management Systems) has been achieved: Algorithmic robustness is satis ed by the use of a Newton-Raphson approach, algorithmicspeed is achieved by using Matlab array statements and sparsity throughout the concept including an ecient sparse system solver. Code quality is high because of the use of code generation for all critical and model dependent code parts from a high-level formal description including comment generation. Finally, code enhancement is easy even for unexperienced programmers because of the need to simply change sets of user-de nable framework parameters.

References

[1] R. Bacher. Automatic Generation of Optimisation Code Based on Symbolic Non-Linear Domain Formulation. International Symposium on Symbolic and Algebraic Computation (ISSAC ACM conference), Zurich, Switzerland, pages 283{291, July, 1996. [2] E. Kant. Synthesis of mathematical-modeling software. IEEE Software, pages 30{41, May, 1993. [3] E. Gallopoulos, E. Houstis, and J.R. Rice. Problemsolving environments for computational science. IEEE Computational Science and Engineering, pages 11{23, Summer, 1994. [4] Ch. Bischof, A. Carle, P. Khademi, and A. Mauer. The ADIFOR 2.0 system for the automatic di erentiation of fortran 77 programs. Technical Report CRPC-TR94491 or ANL/MCS-P481-1194, Argonne Preprint, 1994. [5] M.B. Monagan and W.M. Neuenschwander. GRADIENT: Algorithmic di erentiation in maple. Proceedings of the 1993 ISSAC, Kiev, Ukraine, (ISBN 0-89791-604-2):68{76, July 6-8, 1993. [6] R. Bacher. Computer aided power ow software engineering and code generation. IEEE Transactions on Power Systems, 11(1):490{496, Feb. 1996. [7] R. Bacher and E. Bullinger. Application of nonstationary iterative methods to an exact newtonraphson solution process for power ow equations. Proceedings of 12th PSCC'96 Power Systems Computations Conference, Dresden, pages 453{459, Aug, 1996.

Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997

9

Combining Symbolic and Numeric Tools for Power System Network Optimization Definition of node and edge related basic functions (including comments)

1 2

Definition of potential and flow base names

3

Definition of objective function (basic function, node/edge types, variables, parameters)

Definition of equality constraints (basic function, node/edge types, variables, parameters)

For each objective function and equality constraints specification:

A

Initialization of unknown

Definition of symbols sets of all basic functions

Definition of node and edge types

Reading of network parameters into user parameter data

B

variables into user variable data (e, f, Ie, If, ..)

Mapping/Copy of user data (e, f, ..) to to internal data (x, lambda)

C

Creation of internal equation order

D

Initialization of internal sparse Jacobian and Hessian matrix structures

E

Display all mapping information Display all internal and user values

F

Set Newton-Raphson convergence properties (max. iterations, etc.)

G

4 5 6

7

Compute first and second order derivatives of basic function with respect to all unknown variables of specification

8

Generate Matlab code functions which compute the first and second order derivatives

9

Copy internal data to user data Compute for all functions of each node/edge type the parts related to the right hand side, the Jacobian and the Hessian and store them in internal data structures

Convergence criterion reached ?

Generate code which handles the mapping of user variables to internal Matlab data and vice-versa

10

Generate code for the handling of the potential and flow base names to realize the Kirchhoff laws including Jacobian terms.

11

No Compute the linear system matrix and the right hand side terms and solve the linear system of equations Update the x and lambda variables (x and lambda is internal data)

H

Yes Stop

I

Figure 6: Maple V code parts to generate model depenFigure 7: Matlab code parts of network optimization dent Matlab parts Paper accepted for publication in MapleTech Special Issue on Maple in the Physical Sciences, to be published 1997 10