0% found this document useful (0 votes)
75 views

Object-Oriented Programming, C++ and Power System Simulation

This document discusses applying object-oriented programming concepts and the C++ programming language to power system simulation. It proposes an efficient platform for power system simulation applications using C++. A generic power network container is built by emulating a physical power lab. A module is implemented to solve sparse matrix equations of any data type. Two load flow applications, a DC load flow and an AC load flow, are discussed and found to be as efficient as non-OOP implementations.

Uploaded by

jasonkin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Object-Oriented Programming, C++ and Power System Simulation

This document discusses applying object-oriented programming concepts and the C++ programming language to power system simulation. It proposes an efficient platform for power system simulation applications using C++. A generic power network container is built by emulating a physical power lab. A module is implemented to solve sparse matrix equations of any data type. Two load flow applications, a DC load flow and an AC load flow, are discussed and found to be as efficient as non-OOP implementations.

Uploaded by

jasonkin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

206 IEEE Transactions on Power Systems, Vol. 11, No.

1, February 1996

bject-oriented Programming, C++ and Power System Simulation

E.Z. Zhou, MEEE


EDSA Micro Corp.
200 East Long Lake Rd., Suite 177
Bloomfield Hills,MI 48302

Abstract-Application of OOP concepts and the C++ pro- incremental growth. Multiple suppliers are available for
gramming language to power system simulation has been ex- various upgrades. The utility can select the best hardware
plored. An efficient platform for power system simulation a p and software for each phase of the upgrade. One of the key
plications has been proposed. By emulating a physical power features of an open EMS is modular compatible application
lab, a generic power network container has been build. A software[ll]. Third parties will be able to offer new appli-
module, which can be used to solve sparse matrix equations of cation software that function with the existing applications.
any data types, has been implemented. Two load flow applica-
tions: a dc load flow and an ac load flow have been discussed. One promising approach to achieve the modularity is to use
It is found that the OOP based C++ load flow programs are as object-oriented programming (OOP) approaches which are
efficient as their non-OOP counterparts. designed to address the problems associated with large-scale
software developments.
1. Introduction
The potential of OOP for power system simulation appli-
The planning, design and operation of electrical power cations has been well recognized. There are OOP applica-
systems require simulation analyses to evaluate the current tions to database management[4], graphical user interface[5]
and future system performance, reliability, safety, and abil- and power system simulation[ 11. So far these applications
ity to grow with production or operating requirements. To are based on some existing platforms (class library and pro-
perform computer simulation analysis, a power system is gramming environment). On top of a well-developed plat-
represented by a set of data with certain structures. Analysis form one can easily build his application programs through
algorithms are implemented to process the data to produce inheriting the features in the library. One shortcoming of this
simulation results. For different applications the data struc- approach is that one has to tailor his problem to be fitted into
tures are different. Different programs (load flow, short cir- the existing platform. This may sometimes result in a very
cuit, stability.. .) are built for different applications. With complicated, hard-to-understanding representation of an
conventional programming languages (Fortran, C, Pascal) originally simple concept. For example transmission lines
the coupling between the data structures and the algorithm are represented as a Line class, a subclass of class NPort,
procedures are very strong. A minor change may propagate which is then a subclass of class Physical in ref.[l]. The
through a whole program[l]. As a result, software modifica- complicated structure will often create heavy overhead. The
tion and evolution may require a time period proportional to program runs slower because of large amount of unnecessary
the size of the software rather than the magnitude of the message passing between objects and requires more memory.
changes. A test case in ref.[l] indicates that about 40% of the total
CPU time was spent on message passing.
There are serious problems with today's approaches to
build Energy Management Systems (EMS)[2]. The present Application of OOP concepts and the C++ programming
EMS architecture is inflexible. It precludes a logical and lanpge[6] to power system simulation will be explored in
phased replacement of its subsystems and usually ends up this paper. An efficient platform for power system simula-
with an entire replacement in about ten years[3]. The solu- tion applications will be developed by using C++ as a pro-
tion to the problem is to use open system architectures. gramming language (not as an existing platform). The author
Standards are used and key interfaces are disclosed to enable believes that platforms for power system simulation applica-
tions should be created by power engineers. A brief review
of C++ is presented in Section-2. By emulating a physical
power lab, a generic power network container is build in
Section-3. In Section-4 a sparse equation module is intro-
95 WM 210-5 PWRS A paper recommended and approved duced which can be used to solve sparse equations of any
by t h e IEEE Power System Engineering Committee of t h e data structures. Load flow application problems are dis-
IEEE Power Engineering Society f o r presentation a t cussed in Section-5. The efficiency of c++implementation
t h e 1995 IEEE/PES Winter Meeting, January 29, t o
February 2 , 1995, New York, NP. Manuscript submitted of an ac load flow program and a dc load flow program is
J u l y 18, 1994; made a v a i l a b l e f o r p r i n t i n g compared with a Fortran version and a Pascal version in
January 11, 1995. Sec.6.

0885-8950/96/$05.00 0 1995 IEEE


207

2. A Review of C++ (Vect-xy) is performed inside the function. This is possible


.
because C++ allows the math operators (+ ,-,x ,/. .) being
C++ is a very popular and efficient OOP language. overloaded, called operator overloading. With the operators
Some of important C++ features will be briefly discussed in properly overloaded, user-defined data types in C++ could
this section. .
be used as if they were compiler build-in data types (int .. ).
2.1 Template 2.4 Inline Functions
One of the most important improvements of OOP ap- One of the criticisms that is often addressed to OOP lan-
proaches over non-OOP approaches is the flexibility of reus- guages is that they are much less efficient than the traditional
ing existing code. Beginning with the AT&T 3.0 Standard, non-OOP languages. This is unquestionably true for some
C++ offers a feature, called template, that extends code re- OOP languages. The load flow program implemented in
use even further. Let us use the following simple example to Objective-C is about 2-3 times slower than a Fortran imple-
show the usefulness of the template feature. The Ohm's law mentation[l]. But this is far less apparent in the case of
in power system analysis can be expressed as follows: C++.In fact, efficiency is one of the goals stated by the in-
V=ZxI (1) ventor of C++[6]. For example, one of the properties that
can make an OOP program slower than a non-OOP program
where, 2 is the impedance of a device, I the current through is the heavy use of data access functions, which is a direct
the device and V the voltage drop. For dc power distribution consequence of the application of the information-hiding
system analysis, V, I, 2 are real numbers. For ac system principle. C++ lets you make inline substitutions of func-
analysis, V, 2, I are complex numbers. If it is for 3-phase tions, which means that every function call is actually re-
unbalance situation analysis by using the abc coordinates[9], placed at compiling by the function's executable code to
V, I would be 3x1 complex vectors and 2 3x3 complex ma- avoid the overhead due to the actual calling of the function.
trix. With the introduction of template, it is possible to write
a generic function to cover all possible Ohm's law applica- 3. A Network Container
tions, as folfows:
template<class Tz, class Tvi> Before the introduction of computers to power system
Tvi voltage( Tz z, Tvi i ) simulation, the analysis was usually done on an ac network
{ return z*i; }
analyzer in a power lab. A power lab is conceptually a place
The template statement basically tells C++ compiler that T z (a house) where there are positions that can be defined as
and Tvi represent any data types. The compiler will generate buses. Branch elements (lines, transformers) can be con-
code for as many different functions as it needs to satisfy the nected to the buses to form a power network. A power lab is
calls made to the voltage function. designed and built to be generic so that different kinds of
experiments (load flow, short circuit, ...) can be performed.
2.2 User-defined Data Types To emulate this concept, a network container will be de-
For the analysis of small disturbances (changes) around a signed in this section. The design objective is that the con-
steady-state operating point, eqn(1) in complex form would tainer should be generic, flexible and reusable for different
become: kinds of applications.

For identification purpose, a unique name or id needs to


be assigned to each element in a network. To serve this pur-
C++ allows the users to define data types that are most suit- pose the following data type is defined.
able for their own applications. To represent the relationship
class NameTag (
of eqn(2) the following two data types are defined: char* id; / / name id
class Vect-xy { int nosort; / / number for sorting
Double x, y; ... \
... 1;
1; The nosort is a number for element sorting purpose.
class Matr-xy {
double xx, xy, yx, yy;
... 3.1 Bus Class
1; In a power lab, a bus is a position where a branch or
After the data types vect-xy, Matr-xy are properly de- branches can be connected to. To emulate this idea, the fol-
fined and implemented, the voltage function can be called lowing data type is defined as a base bus class.
to compute the voltage vector in eqn(2). class Bus : public NameTag {
LiStOfPtr<NameTag> branchconnected;
2.3 Operator Overloading ...
When the voltage function is called to calculate eqn(2), 1;
a multiplication of a 2x2 matrix (Matr-xy) and a 2x 1 vector
208

Bus is a subclass of NameTag, inheriting all its features. Network<Bus, Branch> myNet;
Bus myBus1, myBus2;
Bus has an i d for identification purpose, a number nosort Branch myBranch;
for sorting purpose and a list of pointers, pointing to the ...
branches connected to the bus. Any number of branches can myNet .addBus ( ' bus1 I , myBusl ) ;
be connected to a bus object (an instance of Bus) by adding rnyNet.addBus( 'bus2', myBus2 ) ;
myNet.addBranch('busl', 'bus2', rnyBranch);
pointers to the branches into the branchconnected list. ...
Bus& aBus=myNet.getBus('busl');
3.2 Branch Class Branch& aLine=myNet.getBranch('busl','busZr);
A branch is a device with two terminals (from t e d ...
myNet. resortBus (By-id) ;
and to terminal) which can be connected between two buses myNet.arrangeBusno(Tinney2);
(from-bus and to-bus). The following data type is defined as
a base branch class: The Bus Class, the Branch Class and the Network
container so far are very simple and cannot do any real
template<class TBus> / / TBus: bus template
class Branch : public NameTag { simulation work, just like an empty power lab. They have a
TBus* ptrFromBus; / / ptr to from bus few key fmtures common to, and will serve as core code for,
TBus* ptrToBus; / / ptr to to bus all power network simulations. They can be easily main-
... tain
ed because of the simplicity. We will see in later sections
1: how these simple modules can be combined with other
Branch has two pointers: one points to the from-bus and moddes to solve load flow problems. This is the evolution-
the other points to the to-bus. TBus is a template for the bus ary way of the OQP approach.
objects, to which the branch objects (instances of Branch)
will be connected. 4. Sparse Equation Solution

3.3 A Network Container At the center of power network solution is the solution of
A network container for the simulation purpose should the following sparse matrix equation:
be designed as if it is a place where buses can be defined,
and branches can be connected between the defined buses to (3)
form a network. The following data type is defined as a base where, [A] is a nonsingular sparse matrix, [B] is a given
network class, a generic network container. vector and [XI is an unknown vector to be found. Sparse ma-
template<class TBus,class TBra> trix method[7] are now used for solving almost all large
class Network : public NameTag { power network problems. Although the data types of eqn(3)
LinkedList<TBus> buslist; for different applications may be different, the logic of LU
LinkedList<TBra> branchlist; factorization of [A], the forward and backward substitution
public:
void addBus( ... ) ; processes of solving eqn(3) are independent of its data types.
TBus& getBus ( . . . ) ; The following is a generic class for solving sparse equations
void addBranch( . . ) ; . in term of two templates TAi] , TBi.
I TBra& getBranch( . ) ; .. template<class TAij,class TBil
void resortBus( ... ) ;
void resortBranch( . . . ) ; class SparseEqn {
void arrangeBusno( . _ .) : SortedList<A_Elem<TAi]>> Amatrix;
... public:
void setBvector ( . . . ) ;
1: void addAmatrix( . ) ; ..
At the center of the container there are two linked lists, one int solveEquation( . . . ) ;
for storing bus objects and the other for branch objects. The ...
1;
L%nkedList<T>, a linked list class of data type T[13],
knows how to manage memory dynamically. With the help Only non-zero elements of [A] are stored in the list
of the templates TBus, TBra, any kinds of bus and branch Amatrix. The SortedList<T> is a sorted hked list class
,objects can be stored into the container. Network utility of data type T[13].The sorting is according to element rela-
functions ( arrangeBusno ( ) , resortBus ( ) , . . . f are tive positions in [A]. Also the LU factors are stored in the
implemented in the container which will be available list, overriding the [A] matrix to reduce memory re-
through inheritance to all network application programs. quirements. With the help of templates TAij , TBi, Spar-
The network can arrange bus number of the buses in the seEqn can be used to solve sparse matrix equations of any
container according to one of the rules: Tinneyl, T h e y 2 or data types. The following is a simple example:
Tinney3[7].
2.5 0.5 0 0

The following is a simple example of storing information


into and then retrieving from the container.
209

If the [A] is treated as a 4x4 matrix of real numbers and The mismatch is computed based on bus Y-matrix and bus
[B] a 4x 1vector, the problem can be solved as follows: voltage.
SparseEqn<double,double>
myEqnl(4 ,Nonsymmetric) ; So far, a Bus class, a Branch class and a Network con-
myEqnl. setBvector ( ... ) ; tainer have been implemented. Also there is a SparseEqn
...
myEqnl. addAmatrix (
...
... );
class for sparse matrix equation solutions. In this section
these modules will be combined together with some new
myEqnl. solveEquation ( 1. e-30 ) ; modules to solve load flow problems.
Also the [A] can be partitioned into a 2x2 matrix (of 2x2
5.1 Load Flow Base Classes
elements) and [B] into a 2x1 vector. By using the data types For different load flow applications (dc load flow, ac
Matr-xy, Vect-xy defined in Section-2, the problem of
load flow ...) the details of implementations, especially the
eqn(4) can be alternatively solved as follows:
data structures, might be quite different. But all load flows
SparseEqn<Matr-xy,Vect-xy> share some common features. These common features are
myEqn2 ( 2, Symmetric ) ;
... extracted and implemented in the following three load flow
base classes: LFBus, LFBranch, LFNet.
myEqn2. solveEquation ( 1. e-30 ) ;
template<class T>
One would assume that the second 2x2 matrix approach class LFBus : public Bus {
might be slower than the first 4x4 matrix approach because T voltage; / / bus voltage
the user defined data types (OOPfeature) are involved in the public:
2x2 approach. The following is the CPU time used in solv- virtual T yii( void ) = 0;
virtual T mismatch( void ) = 0;
ing eqn(4) by the two approaches for 1000 times on a ...
486DX/33Mz PC: 1;
4x4 approach: 0.55 sec. 2x2 approach: 0.44 sec. LFBus is a subclass of Bus, inheriting all its features. The
The performance tests indicate that the 2x2 approach is even voltage is for bus voltage. The voltage data type is de-
faster than the 4x4 approach. The main reason is that all fined in terms of a template T so that it can be used for dif-
member functions of Matr-xy, Vect-xy are declared as ferent applications. The yii ( ) function is for finding the
diagonal element yii of Y-matrix corresponding to the bus.
inline functions. This makes them as efficient as the com-
The mismatch ( is for bus mismatch calculation.
piler build-in data types.
ternplate<class T,class Thus>
class LFBranch : public Branch<TBus> {
The key points of SparseEqn are modularity and flex- public:
ibility. Sparse matrix equations of any data types can be virtual T yij( void ) = 0;
solved by using the module. It is a self-contained module, ...
managing its memory dynamically. To the user it is a "black 1;
box" with the sparse matrix solution capability. The sparse LFBranch is a subclass of Branch. The yi j ( ) function is
matrix method is now under intensive investigation[lO, 121. for finding the off-diagonal elements yij corresponding to the
If any future modifications or improvements are needed the branch. TBus is the template for the buses to which the
modifications can be contained to SparseEqn itself and branch will be connected.
would not propagate to the outside. template<class TV, class TM,
class Tmis, class Tbus, class TBra>
5. Load Flow Applications / / TM,TV: for sparse equation
/ / TMis : for mismatch information
class LFNet: public Network<TBus,TBra> {
Load flow is one of the most commonly use power sys- public:
tem analyses. From computation point of view, the problem virtual TMis maxMismatch(void) = 0;
can be simply stated as follows: virtual void formJmatrix(
SparseEqn<TM,TV>& eqn) = 0;
For specified voltage (V,8 and/or generation (Pg, Qg) int loadFlow( void ) ;
at generator buses and specified load (P1,Ql) at load ...
buses, find a set of bus voltage by iteration such that 1;
the mismatch between specified quantities and calcu- LFNet is a subclass of Network. Therefore LFNet iS alS0 a
lated quantities is within a required tolerance. network container. Bus objects, branch objects and their
connection configuration as a network can be put into the
The convergence of a load flow study is tested by the container. In addition, the L F N e t container has load flow
following equation: application features. The maxMismatch ( ) is for finding the
I I
max mismatch at bus # i I tolerance
Kiln (5)
maximum bus mismatch and the location where the maxi-
mum occurs. The formJmatrix ( ) is for forming Jacobian
210

matrix. The J-matrix is stored into the sparse matrix equation LFBus are of type complex. The yii ( ) , mismatch()
object eqn. The data types of J-matrix are specified with functions defined in LFBus are pure virtual functions. The
two templates TM, TV because they might be different for actual complex version of these functions has to be imple-
different load flow applications. mented inside the subclass ACLFBus.
class ACLFBra : public
LFBus, LFBranch, LFNet contain pure virtual func- LFBranch<complex,ACLFBus> ( ... );
tions (indicated by virtual. . .=0)[13]. These functions are ACLFBra is a subclass of LFBranch with complex substi-
purely virtual in that they do not define any code but act as a tuting the template T for branch data type and ACLFBus
pattern of interface for all subclasses. For example, substituting TBus, so that ac load flow branch objects will
formJmatrix ( ) of LFNet class is a pure virtual function. be connected to ac load flow bus objects.
It tells the subclass of LFNet that, although the details of
class ACLFNet : public
actual implementation of formJamtrix ( ) might be dif- LFNet< Vect-xy, Matr-xy, AC-misstruct,
ferent for different applications, the interface of the actual ACLFBus, ACLFBra > {
functions must be the same as the pure virtual function so void formJmatrix(
that the actual functions can be properly plugged into the SparseEqn<Matr_xy,Vect-xy>& eqn);
system to perform load flow computation. ...
};

In the LFNet class a generic Newton-Raphson load flow ACLFNet is a subclass of LFNet. The substitutions of the
function loadFlow ( ) is implemented. The main part is as templates indicate that ac load flow bus objets and branch
follows: objects are to be put into the ac load flow network container
SparseEqn<TM,TV> lfEqn ( get-noBus ( ) ) ; ACLFNet. For ac load flow using the Newton-Raphson
for (int cnt=O;cnt<=maxIteration;cnt++) ( method in the rectangular coordinates, the Jacobian matrix
if ( maxMismatch() <= tolerance ) { elements are 2x2 matrices and voltage increments [AV,, A
return CONVERGED; V ] are 2x1 vectors[9]. The data structure is similar to that
} else {
formJmatrix ( lfEqn ) ; oJqn(2). Therefore the 2x2 matrix data type Matr-xy, and
forEachBusInNet(bus) 2x1 vector data type Vect-xy defined in Section-2 are used
{ . _ ./ / set B vector ) for the sparse matrix equation data types.
lfEqn.solveEquation( 1.0e-20 ) ;
forEachBusInNet(bus)
{ ...
/ / update bus voltage ) With the ac load flow classes properly implemented, load
1 flow analysis of an ac power system is quite simple, as fol-
1 lows:
return NOT-CONVERGED;
ACLFNet myACLFNet;
The loadFlow() function is generic, only includes those cin >> myACLFNet;
steps common to all load flow applications. The function is myACLFNet.arrangeBusno( Tinney2 ) ;
if ( myACLFNet .loadFlow ( ) == CONVERGED )
implemented in terms of bus, branch, mismatch, Jacobian cout << myACLFNet;
matrix element templates and the pure virtual functions that
define the function interface. Any class that contains one or Where, an ac load flow network object (container)
more pure virtual functions is called an abstract base myACLFNet is first defined. By the overloaded I/O operator
class[l3]. It can be only used as a base class for other >>, data of a study case is input into the container. Depend-
classes. No objects of an abstract class can be created. ing on how the operator is overloaded, the data might come
LFBus, LFBranch, LFNet are abstract base classes for from a text file, a binary file, from other simulation process
load flow applications. or directly from the screen of a graphic editor. Then the bus
number is rearranged by using the arrangeBusno ( ) inher-
5.2 AC Load Flow ited from the Network class. Load flow is calculated by
Ac load flow has been the most commonly used load calling the loadFlow ( ) inherited from the LFNet class. If
flow analysis program. In ac load flow analysis bus voltage, the load flow converges, the U 0 operator << will direct the
generation, load, and branch impedance are complex num- results to somewhere depending on how the.operator << is
bers in nature. Based on the load flow base classes LFBus, overloaded.
LFBranch, LFNet, the following three subclasses are de-
rived for ac load flow analysis. 5.3 DC Load Flow
class ACLFBus : public Direct current (dc) power distribution systems have been
LFBus<complex> ( ... ) ; extensively used in nuclear power plants and underground
transit systems. To find voltage and voltage drop at load
ACLFBus is a subclass of LFBus with complex substituting
buses of a dc distribution system dc load flow studies are
the template T for bus data type. Therefore the voltage,
needed[l4]. For dc system analysis all quantities involved
yii ( 1 , mismatch ( ) which ACLFBus inherits from
are real numbers. Based on the load flow base classes
211
LFBus, LFBranch, LFNet, the following three subclasses D a m s

are derived for dc load flow analysis. Bus -


...
class DCLFBus : public
LFBus<double> { 1; ... DaPBra

class DCLFBra : public LFBranch


LFBranch<double,DCLFBus> [ }; ... ...
class DCLFNet : public Damet
LFNet<double ,double ,DC-mi sStruct , Network -
DCLFBus, DCLFBra > { I ...
void formJmatrix (
SparseEqn<double,double>& eqn) ;
... Fig. 1 The class hierarchy
1;
For dc load flow using the Newton-Raphson method, the Ja-
Table-1 Performance tests, CPU time in seconds
cobian matrix elements and voltage increments AV are real
numbers. Therefore double is used for the sparse matrix Cases Fortran Pascal C++
equation data types. With the dc load flow classes properly
implemented, load flow analysis of a dc power system is as ac 35-bus (6 iter.) 1.53 - 0.66
follows: ac 69-bus (6 iter.) 5.26 - 1.65
DCLFNet myDCLFNet; dc 100-bus (4 iter.) 0.33 0.48(0.38)
cin >> myDCLFNet;
myDCLFNet.arrangeBusno( Tinney2 ) ; ac 69-bus (100 iter.) 51.15 - 27.97
.
if ( myDCLFNet loadFlow ( ) == CONVERGED ) ac 35-bus (100 iter.) 15.33 - 11.70
cout << myDCLFNet; dc 100-bus (100 iter.) - 10.55 13.30(11.12)
Inheritance is one of the most powerful tools available in
OOP. It allows you to abstract common behavior between
similar objects into a base class and define derived sub-
classes, not from scratch, but in terms of the base class with- Two ac power systems (35-bus and 69-bus) and a 100-
out having to rewrite the similar parts every time. The class bus dc system are used to measure the performance. The load
hierarchy of load flow applications is shown in fig. 1. There flow tests were performed on a 486DX/33Mz PC. The For-
are four layers in the hierarchy. The first layer is the tran compiler used is the Lahey Fortran-77 (v3.00), the Pas-
NameTag class. The second layer consists of Bus, Branch cal compiler: Turbo Pascal (v6.00) and the C++ compiler:
and Network, and handles the common features of power Borland C++ (v3.1). The load flows converge in 6 iterations
networks. The third layer consists of LFBus, LFBranch for the two ac systems and in 4 iterations for the dc system.
and LFNet, and adds the common features of load flow The CPU time used by different programs is shown in Table-
studies to the hierarchy. The fourth layer deals with the de- 1. To measure the "true" numerical performance of the pro-
tails of different load flow applications. Fast decoupled load grams the tolerance for convergence was set to 0.0 to make
flow method and 3-phase unbalanced load flow are also im- the load flow computation impossible to converge and the
plemented. Their discussion has been omitted due to the maximum iteration was set to 100 so that the computation
space limitation. stops at the 100th iteration.

6. Performance Test Results The CPU time test results in the table indicate that the
C++ implementation is slower than the Pascal version and
It is desirable to design a flexible software project that is faster than the Fortran version. The reason for the C++ ver-
easy to build and easy to maintain, but it also needs to be sion slower than the Pascal version is that in the Pascal im-
concerned that the software must be efficient. For power plementation the J-matrix and its LU factors are stored in
system simulation software the top priority is their perform- two separate fixed arrays, while in the C++ implementation
ance. It is very hard to justify to sacrifice efficiency for the J-matrix and its LU factors are stored in a sorted list with
flexibilityr81. C++ itself is a very efficient programming memory dynamically allocated (see Sec.4). The improvement
language. The performance of a C++ application is mainly in memory efficiency results in slower in speed. If the same
dependent on the way by which one programs (speaks) the fixed array storage scheme is used, C++ implementation of
language. An example in Sec.4 indicates that adding OOP the dc load flow is as faster as the Pascal version. The CPU
features to a routine does not necessary mean slow in speed. time is shown in the brackets in Table-1. The reason why the
In the following the performance of a C++ implementation Fortran implementation of the ac load flow is slower than the
of the ac load flow (Sec.5.2) is compared with a Fortran load C++ version is not clear. It may be because the Fortran
flow program, and a C++ implementation of the dc load compiler used is an old version (1988), which may not be
flow (Sec.5.3) with a Pascal version. able to take full advantages of a 486 machine.
212
Memory requirement is also important when the effi- near future as an alternative way to program power system
ciency is concerned. There are mainly three chunks of data: simulation software.
bus data, branch data and LU factor table in the load flow
applications. They are stored in the network container and 8. References
the SparseEqn class in three linked lists instead of three
fixed arrays. The linked list classes used are from the Bor- [l] A.F. Neyer, F.F. Wu and K. Imhof, "Objected-Oriented
land C++ library[l3], that knows how to allocate and free Programming For Flexible Software: Example of a Load
memory dynamically. With the fixed array approach, a Flow", IEEE Tran. on Power Systems, Vol.5, No.3, Aug.
statement would always come with a load flow program, for 1990, pp 689-696.
example, this is a 2000-bus version. With the linked list ap- [2] A.M. Sasson, "Open systems procurement: a migration
proach, a program only uses an amount of memory necessary strategy", IEEE/PES 1992 Winter Meeting (92WM158-6),
to simulation a particular power network. If the program is New York, New York, Jan. 1992
running under Windows or Dos protected mode[l3] one [3] J.L. Scheidt, M.E. Robertson, "The Problem of Upgrad-
could practically simulate power networks of any size. ing Energy Management Systems", IEEE Tran. on Power
Systems, Vo1.3, No.1, Feb. 1988. pp118-126
7. Conclusions and Comments [4] D.G. Flinn, R.C. Dugan, "A Database for Diverse
Power System Simulation Applications" , IEEE Tran. on
Application of OOP concepts and the C++ programming Power Systems, Vo1.7, No.2, May 1992, pp784-790.
language to power system simulation has been thoroughly [5] M. Foley, A. Bose, W. Mitchell and A. Faustni, "An
explored. An efficient platform for power system simulation Object Based Graphical User Interface for Power Sys-
applications has been proposed. It is found that the OOP ap- tems", IEEE/PES 1992 Winter Meeting, New York, New
proaches and C++ are very flexible and highly efficient, as York, Jan. 1992
efficient as non-OOP programming languages if properly [6] B. Stroustrup, R e C++ Programming Language, 2nd
implemented. edition, Reading, MA, Addison-Wesley.
[7] W.F. Tinney, I.W. Walker, "Direct Solutions of Sparse
The most difficult part of power system simulation pro- Network Equations by Optimally Ordered Triangular
gramming is to deal with the network relationship. By emu- Factorization", Proc. of the IEEE, vo1.55, Nov. 1967, pp
lating a physical power lab, a generic power network con- 1801-1809.
tainer has been build. Any types of bus objects can be put [SI D. Kirschen, G. Irisarri, Discussion to [l]
into and retrieved from the container, and any kinds of [9] J. Arrillaga, C.P. Arnold, Computer Analysis of Power
branch objects with two terminals can be connected between Systems, John Wiley & Sons, 1990.
the buses in the container. The network container can be [lo] M.K. E m , W.F. Tinney, F.L.Alvarada, "Sparse Ma-
used as the base class for all power network simulation ap- trix Inverse Factors", IEEE Tran. on Power Systems,
plications. Vo1.5, No.2, May. 1990.
[111 R. Podmore, "Criteria for Evaluating Open Energy
A module for sparse matrix equation solution has been Management Systems", IEEE Tran. on Power Systems,
implemented. The module is very flexible. Sparse equations Vo1.8, No.2, May. 1993.
of any data type can be solved by the module. It is a self- [12] W.F. Tinney, V.Brandwajn, S.M. Chan, "Sparse Vec-
contained module, managing its memory requirement dy- tor Method", IEEE Tran. on PAS, Vol.104, No.2, Feb.
namically by itself. 1985, pp295-301.
[131 Borland International, Burland C++ Programmer's
Two load flow applications: a dc load flow and an ac Guide,version 3.1, 1992.
load flow have been discussed. The implementation of the [14] E. Zhou, A. Nalse, "Simulation of DC Power Distribu-
load flow algorithms takes full advantage of inheritance. The tion Systems", 1994 IEEE I&CPS Tech. Conf., Imine,
C++ implementation of the load flow algorithms has been CA, May 1994, pp 191-195.
compared with non-OOP load flow programs for perform-
ance evaluations. It is found that the C++ implementation is Erzhuan Zhou (IEEE member 1990 ) received his B.Sc. de-
as efficient as the non-OOP counterparts. gree in EE from Hunan University, Hunan, China in 1982;
his M.Sc and his Ph.D. degrees in EE from Tsinghua Uni-
Author's experience with OOP and C++ has been very versity, Beijing, China, in 1984 and 1987 respectively.
positive. The key advantage of using C++ is not so much From 1990 to 1992 he was an assistant professor with the
that it can do things that the non-OOP languages can not do, department of EE, the University of Saskatchewan. He is
but rather that it can help you think and approach your now the vice president of EDSA Micro Corp., Bloomfield
problems in ways that otherwise might not be possible or Hills, Michigan. Dr. Zhou's current research interests are
considered. The author predicts that OOP and C++ will power system simulation, OOP applications, oscillations in
compete with the non-OOP programming languages in the power systems and application of PC to power engineering.
213

Discussion Branch models tend to be too simplisticto be used in other applications. More complex
modelsare required for applications that require three-phase models with both gmuaded and
ungrounded neutrals, for example.
N. Cuven and G. SCWU'I (Middle East TechnicalUniv., Ankara, Turkey) :
The author is to be commended for presenting an illustrative paper which discusses the C+t
implementation issues in the simulation of typical power system problems. The paper :hows that C t t Load, generation, aud, sometimes, var productionbecome bus properties. This presents a
UT a language doea not have to be inefficient, conversely, it h u many kturca that couvemtiwd problem for applications where load,generation, and capacitorsat a bus must be disaggregated
languageslack, whicb enable to optimize usage of resources in a user-friendly manner. In this way, the into an arbitrarynumber of Eomponents. I hold that each ought to be a separate entity
defiiienck of object-oriented (00)approach may be avoided. We would appreciate the author's
comments ou the following poiuts: Buses are given a type property such as slack bus, PV bus, or PQ bus. This is a direct
(i) Programmiugplatforms: consequence of a patticular formulationof the laad flow problem and is meaningless for nearly
Knowing that 10 energy management system (EMS)is a very compliuted environment, any other application. The load flow application should take. responsibility for assigning these
application of 00 programming is C N C ~as~ always pointed out. The nced for effideae). will atways properties from the dehitioo of the generators.
itruggle with the right applicaliou of 00 philosophy. In such a complicated edmnment, d e s i or
pur- of librarica (known UT software componeuts) is unavoidahk. A!i h the uge of container impedances are often represented in per unit This is one or two levels removed fmn the base
deues,why not IW M efficient mathematical library, that handles all the complex, float, int, matrix impedance quantities for element and often causes problems for other applicatim. I would
operations, even solve the a p m equatious? argue that you should be able to dctcmune M object's unpodancc m aaualohms from the
(ii) F l e x i i i of the ryatemmod& objecl itself mthout any howledge of where it is in the system.
Pmving that C* is UT &cient UT a conventional language in perfornunee for 8 speciiic
appliution is nut iuffideot hy itself. Applicatlon of 00 programming methoddogy to the ayatem Thcse arc just of few of the issues that d to be resolved before we can d e on commonobject
modd should .Is0 be justifkd. For MY other simulatiou rppliutioo in an EMS ehromnmt, a definitions for the power induJtry
diffcrent power syatem madel may be required. Design of a general power system mode4 is a much
more sophigiuted problem,hut is a necessary process for the right applicationof 00 pmgmnnhg in
EMS. Furthermore, in the case of keeping the system modd m M 00 database auolgement .yrtem, Manuscript received March 1. 1995.
editing a model and running any other simulation over this modd will wady influence the
implementrtiou issufs and k c e the efficiency. As far UT the EMS ia concerned, design isMla like
opemess, interoperrbi, undentaodibility, etc. emerge. Illen, 00 design trido ni0. dominate and
abstraction, message passing, inheritance will be more important t h tu~ning eflideney. However,
parb of the system where eficiency is crucial may be treated in a nun-00 rmoaer if that part is
atOllliC.
E.Z. Zhou. The author would like to thank the discussers for
(iii ctt ruturn: their interests and discussion of the paper. As the subject is
The implementatiou tricks you suggest e.(i,. iniimiug and templatea) are nice &turn of C t t
d will give satisfadory results when applied correctly aud at the rigbt place. For example: totally new, I do not have answers to all the questions. My
-Malting a kngthy method inline may blow up the executable program size if it is erlkd from lots of
modules,but rpeeas up the program execution.
comments will be based on my experiences and some of my
-Usage of templatea +W
I a better analysis of algorithms to extract general behavior, whik enl.rging on-going OOP activities.
the executable program size.
HIMthe author experienced and/or evaluated the drawbacks of these featured?
The code given in the paper shows excessive usage of template classes. 'IW is advmt.geous
for code rruse, however, it makes the inheritance hierarchy complicated. 'I%e pure virtoll methods
(1) First my answer to Mr. Dugan's question "Does a
$0 and mismatch0of dass LFBus have no ~portnnce,since there an?two (or more) abstract d.ascs transformer need to know its location in a power system?" is
LFBusuompIeS- and LFBusqlouble, which have single snbclasses. Did you try to solvethe p r o b h
with ri;O and mismatch0 returning objects, instead of compiletime determined @pea? somewhat Merent. 1 would say "Yes" for power system
simulation if we want to achieve high level of modularity. A
Manuscript received March 15, 1995. transformer object has to know its location before it can
calculate by itself, for example, its current and its terminal
bus voltages.
ROGER C. DUGAN, Electrotek Concepts, Inc., Knoxville, TN: This is a significantpaper in that Most, if not all, power network simulation algorithms are,
it is one of the first to explain an object-oricntcdrepresentation of the power system in such detail
and I would l i e to express my appreciation to the author for his efforts. For several yean, I have formulated based on the node admittance matrix equation, as
been working through the IEEE to exploit object-orientedprogrammingto establish standard
components for power system simulation. Recently, we have been soliciting proposals for such follows:
standards. This paper essentiallymakes such a proposal by describing the details of a working
system. It is good to have this paper as a referenceso that we can build upon it.
[I1 = M [Vl
Objectaiented programming reduces the number of choices for software realizations of a
problem, particularly if you &kt the objects to representing mostly physical objects. However,
there are still choices to be made and two people will rarely define even the physical objects The decomposition scheme proposed in the paper is aimed at
identically. I would now like to discuss some of the different choices I would have made and solicit
the author's response. formulating the above equation as general as possible.
I like the gened decomposition of the problem into three main classes: Bus, Branch, and Network.
Elements in M are treated as data objects when formulating
However, I would have distributed the propelties difFerently. I prefer to see all connectivity eqn(1). y, represents a node i and y,, a branch i->j in a
information moved 6am the Bus and Branch classes and placed solely in the Network class. My
d g for this is based on maldog each object definition as independeotas possiblefrom any
network. Node i may physically be a PQ bus in a load flow
other. Does a transformerhow,or need to how,where it is in a system? I would answer "no." I study. Branch i->j may be a transformer in a transient
would argue that this should be handled by an object with bigher level control capability and it
scems that the N m r k clau: is the logicalplace. A transformerhas certainphysical stability study. In formulating eqn(l), the emphasis is on the
characteristics regardless of u k r e it is in the w o r k and that should be all that a transformer relationship between the data objects. The physical attributes
delinition should consistof. consider what is involved in removing a branch from the system in
the author's dexmpositim: Referencer to it must be removed by objects ofall three classes. If the of the objects are not important. This is the main reason that
connectioninformationwere contained solely in the Network class, only the reference there would in the proposed decomposition scheme, on the top level, the
havetobenmoved.
Bus and Branch classes have only connectivity or relationship
Another aspect of the designwhere I would differ is the derivationof different subclassesfor
different applications. I would prefer to have the de6nitions of tbe bus and branch classes be fully information and no physical attributes.
indepeOaem ofthe applicationand raMinthe same across severaJ applications. The interpretation
may change h m a load flow to a transient stability application, but I don%understand why the
classes describw the power system must change. I can appreciatethata polymorphicview of an Since the network connectivity information is put at bus
object for different applications might be usefut, but it would seun that new subclasseswould and branch level, bus and branch objects know their locations
makemain~morndiliicult. '
in a network. A bus object therefore knows how to do all its
Like many OtherJ in this field, the author has chasm a load flow applicationto demonstrate the
decomposition. W e the load flow may be the most used applicationin the power in dust^^, it is own business, for example, to calculate its y", bus injection
also a bit of an oddball. I have found that using a load flow to guide the decompositiontends to current I, and so on. A branch object knows how to calculate
lead to design choices that make it more diflicultto integrate the model with other applications.
Althongb it takes a lot more etrort, I am of the opinion that a beaer decompositionis generally branch current I,,. For instance, after a load flow simulation
obtained ifone were to look tirst at the modeling requirements for more general applicationssuch we would like to see screen display of a branch current as
as harmonics and transients studies, or, at least, multi-phase power flow applications. Four
examples of the consequencesof using the conventional load flow formulation to guide choices are: foIIows:
214

I.. V. Mr. Dugan’s discussion is more from the database point


vi ‘J
of view. When a transformer is put into a power system
J- database the emphasis would be on its physical attributes
(nameplate voltages, KVA, Z%, XA2). Location information
Fig. 1 is not important. When it is put into a simulation module the
emphasis would be on simulation algorithms and how to find
By using the proposed scheme, a branch object knows how to the results, for example, the current through and its terminal
calculate its current, as follows: bus voltages. The proposed approach put more emphasis on
complex ACLFBra::Current( void ) the simulation algorithm, trying to highlight simulation
( procedures and to hide component data structure as much as
return (GetFromBus( ) .Voltage ( ) - possible in order to make algorithm implementation as
GetToBus ( ) .Voltage ( ) ) /GetZ ( ) :
general as possible. The following figure illustrates author’s
1
view on the relationship between database and simulation
To do the display job the following code may be used. module.

ACLFNet net: / / net, a Network object


...
Hi LF module, do you
/ / branchID: ID of the branch want to h o w my details
ACLFBra& branch = net.GetBranch(branchID): With ODBC,OLE, I can
branch.DisplayCurrentOn( GRAPHICSCREEN ) ;

The branch object can display itself because it knows its


location and, therefore, knows how to calculate all branch
quantities. ( Database flow module)

If the connectivity information is placed solely in the


network level, as suggested by Mr. Dugan, the following code
would be used to do the display job. Fig. 2

ACLFNet net:
... (3) I do agree with Mr. Dugan that a load flow application is
ACLFBra& branch = net.GetBranch(branchID); quite simple and not enough to fully demonstrate the
ACLFBus& busi = net.GetFromBus(branchID); capability of a simulation platform. In addition to the load
ACLFBus& busj = net.GetToBus(branch1D): flows reported in this paper, we have implemented harmonic
/ / calculate branch current analysis and three-phase unbalanced load flow based on the
complex current = (busi.Voltage()- proposed platform. We are in the process of implementing
busj.Voltage())/branch.GetZo; short circuit, transient stability. The following are some brief
summery of our harmonic analysis and three-phase
/ / display branch current
DisplayBranchOn( GRAPHIC-SCREEN, current, unbalanced load flow implementation.
busi, bus j , branch )
Harmonic Analysis
The author believes that the first approach is more 00, which For harmonic analysis, in addition to load flow and short
means greater modularity, maintainability and reusability. circuit information, harmonic source and harmonic filter
information are needed. Harmonic sources and filters are
(2) The author does not agree that for power system attached to bus objects. The following shows how harmonic
simulation a network class should be multi-functional. bus, source and filter classes are defined.
Different applications should be handled by different network
classes. For example, load flow only deals with positive class HarmBus : public Bus { ... )
sequence network. Short circuit has to consider positive,
negative and zero sequence networks. If a network class knew class HarmSource
how to do both load flow and short circuit, the load flow I
HarmBus* pHarmBus;
implementation would be inefficient, because it had to carry ... / / source data
unnecessary negative and zero sequence information. Also a 1
big multi-functional network class would be more difficult to
maintain. Imaging having a supper network module which class HarmFilter
(
knew how to do load flow, short circuit, harmonic analysis, HarmBus* pHarmBus:
transient stability and more, a supper man who knew all these ... / / filter data
subjects would be needed to maintain the network module. I
215
Three-phaseUnbalanced Load Flow a way that it can be easily replaced by other linear equation
The main difference between normal AC load flow and solution library/class. As for the network container, I have yet
three-phase unbalanced load flow is the data structure. In to find an efficientcontainer library which is geared to power
three-phase unbalanced load flow, bus voltage is a 3x1 system simulation.
complex vector [Va,Vb,V,]. Line impedance is also a 3x1
complex vector [zo,z1,z2].To represent the data structure, the The author’s view on power system simulation is that a
following data type is defined. general power system model for simulation is more
theoretical than practical. Load flow should be performed by a
c l a s s vect-3p (
union { complex a; load flow network object, short circuit by a short circuit
complex -0; }; network object. When I was doing my PhD work at Tsinghua
union { complex b; University, Beijing, China, the university has a physical
complex -1; I ; power lab. You can have as many as 9 machines to perform a
union ( complex c;
complex -2; 1; power system experiment. When you want to do an
... experiment, for example, a load flow study, you have to
I configure the lab system by yourself. You have to take
necessary equipment from a warehouse to build a network for
Then a bus class for three-phase unbalanced load flow can be your study. There is no general lab setup which you can use to
defined based on the load flow base class LFl3us as follows: do any kind of experiment. Based on the experience, I would
class LF3PBus : public LFBus<vect-3p> say no one can build a true general power system simulation
4 . e - I model. Of course a power system 00 database for general
simulation purpose is possible.
The proposed platform is very flexible. At the top level
(base class level), only relationship or connectivity between The author would not call inline functions, templates
bus objects and branch objects in a network is defined. “tricks”. They are standard features of today’s C++. The
Through inheritance/subclass mechanism one can attach any author agrees that it takes some time and exercises before one
amount of data and methods to a bus or branch class. The can become used to the features. The author does not think
platform from the beginning is aimed at solving a variety of that Mr. Guven and Mr. Senyurt fully understand the
simulation problems: load flow, short circuit, harmonic importance of the virtual methods yii() and mismatch(). They
analysis, transient stability and so on. In fact the author are absolutely necessary because of the general purposed load
believes that any power network simulation problem flow method loadflow() implemented at the LFNet class level,
formulated based on eqn( 1) can be decomposed according the where the data structure of and how to calculate y,, the
proposed approach. mismatch are not available.

4) Regarding to Mr. Guven and Mr. Senyurt’s comments: Manuscript received April 17, 1995.
OOP facilitates using commercial software components and
libraries. The sparse matrix solution class is designed in such

You might also like