A Fortran-95 Implementation of EMTP Algorithms
Total Page:16
File Type:pdf, Size:1020Kb
A Fortran-95 implementation of EMTP algorithms Jean Mahseredjian1 , Benoît Bressac2, Alain Xémard2, Luc Gérin-Lajoie3, Pierre-Jean Lagacé4 (1)IREQ / Hydro-Québec (2)Électricité de France (3) TransÉnergie, (4)École de Technologie 1800 Lionel-Boulet Direction des Études et Hydro-Québec, Complexe Supérieure Varennes, Québec, Recherches Desjardins, 1100 Notre Dame Ouest Canada, J3X 1S1 1 ave. du Général de Gaulle CP 10000, Montréal, Montréal, 92141 Clamart Cedex Canada, H5B 1H7 Canada, H3C 1K3 numerical and historical reasons Fortran is still considered Abstract - This paper presents a complete Fortran-95 based as the language of computational science and kept on implementation of EMTP type algorithms. It demonstrates surviving in the midst of new and modern languages. software engineering advantages and proposes formulations Although several modern language concepts and and programming designs most suitable for transient constructs can be imitated in Fortran-77, it remains a analysis computations in Fortran-95. Computing strongly handicapped language in several aspects and more performance is compared against Fortran-77 usage. The fundamentally in dynamic data allocation, parallelism and coding experience presented in this paper demonstrates that programming safety. Fortran-77 is not an object -oriented Fortran -95 is not just a logical upgrade from Fortran-77, it language, it is behind C and C++ for data abstraction and it is a modern and powerful language and should be even lacks recursion and data structures. considered as the preferred language choice for large scale It requires a major investment and strong justifications transient analysis application development. to rewrite an existing large scale Fotran -77 application with a modern and significantly different computer language, Keywords: Software engineering, EMTP, Fortran such as C/C++. Automatic translators are unable to maintain the original conceptual thinking and usually create code maintenance problems. Experience has shown that I. INTRODUCTION manual conversion of Fortran legacy code into C/C++ is a This paper presents an experience in software extensive task, there are also concerns about reported poor engineering for programming EMTP (Electromagnetic performance. Transients Program) [1] type algorithms. Although the Although some of Fortran-77 features are becoming presented material is related to transients, offered ideas and obsolescent and may completely disappear in a fut ure experiments are applicable to other power system analysis language revision cycle, the new Fortran-95 [3][4] applications. standard stays fully backward compatible with Fortran-77. There are several software engineering considerations Fortran-95 is also a modernized language most suitable for in recoding or writing from scratch a large scale power numerically intensive applications. These are the main system application. The most important consideration is the reasons why a natural and cost effective transition from choice of the programming language. The programming Fortran-77 is Fortran-95. Nevertheless, the coding language plays a predominant role in the software experience presented in this paper demonstrates that engineering cycle. An advanced language can provide Fortran-95 is not just a logical upgrade, it is a modern and means for fast translation of mathematical formulations powerful language and should be even considered as the into actual code. The ultimate combination is very high- preferred language choice for power system transient level programming resulting in extremely efficient code. analysis application development. Additionally, there is Although interpreter based languages (such as [2]) or visual also a migration path to parallel computers, since High design environments can become very powerful, they are Performance Fortran is also based on Fortran-95. still unable to achieve the computational speed provided by compiler based languages. Automatic compiler based code II. FORTRAN-95 ADVANTAGES generation from high-level languages, lacks specialization and has difficulties replicating conceptual thinking for the The most useful new features of Fortran-95 for EMTP most efficient coding path. algorithms are grouped into “array building and Increasing problem complexity requires more powerful manipulation” and “data abstraction”. The first group constructs and syntax in a computer language. In the past includes dynamic memory allocation, data parallelism, twenty years, computer science has progressed dramatically array sections and array operations. The second group and spurred interest on the use of new programming includes derived data types, programming with modules languages such as PASCAL, ADA and most notably (hiding, scope and encapsulation), interface definition and C/C++ and now Java. operator or function overloading. Large scale transient analysis applications have been For the rest of this paper, the Fotran-95 version of traditionally coded and maintained using almost EMTP will be referred to as EMTP-F95. exclusively the Fortran-77 language. Fortran-77 has been standardized in 1978. Its dominance in all fields of numerical computations has kept increasing as new and highly optimizing compilers became available. For 1/6 A. Modularity using derived data types, those that have been exploited in EMTP-F95 are code readability, simplified access to data There are several programming language features that and memory management. are useful in the programming and maintenance of large The following lines of code, extracted from the Zinc codes. Modularity is among the most important features. Oxide (Z O) arrester model, are presented to illustrate some The code that modifies data for a component, must be n of the above concepts. localized and confined to a related location in the program, MODULE zno_branch and not spread throughout the entire code. This is what is USE input_data meant by encapsulation. It goes beyond the definition of USE plot_memory !to transmit outputs function or subroutine by allowing all related operations USE service (methods) to be grouped around a defined data type. It shall USE sparse_main_mat, & ONLY: put, putnonl, fill, & be allowed to hide data and methods. Fotran-95 allows Vaug, Vaug_c, n_Ynonlin, Inonlin encapsulation and information hiding. Fortran-95 has the USE all_purpose, ONLY : int2str,angle notion of scope. Scope means that an internal function INCLUDE 'default_header.f90' TYPE, PRIVATE:: zno_str (FUNCTION or SUBROUTINE ) is within its host's scope REAL(krealhp) :: Rss ! steady-state R and therefore has access to all the host's entities with the REAL(krealhp) :: Vref ! reference voltage REAL(krealhp) :: Vflash ! flashover voltage ability to call other internally defined functions. External INTEGER :: loc ! locator in char functions can be called from anywhere and contain internal INTEGER :: knode ! left node vector procedures. INTEGER :: mnode ! right node vector REAL(krealhp) :: Iq=zero !Norton current source Fortran-95 has introduced the module unit. It is used for REAL(krealhp) :: G=zero !Norion admittance data encapsulation and global data. The generic form of a REAL(krealhp) :: i !element current module is MODULE module-name REAL(kreal hp) :: vkm=zero !voltage [specification construct] INTEGER :: state=0 !flashover state [ CONTAINS ] INTEGER :: segnow=0 !operating segment at t [subprogram] INTEGER :: lastseg=0 !operating segment at t-Dt END [MODULE [module-name] ] REAL(krealhp) :: tol=1e-6_krealhp; Language keywords are in bold (in this paper) characters to END TYPE zno_str enhance visualization. A module can be accessed by another program unit using TYPE, PRIVATE:: zno_char REAL(krealhp ), POINTER,DIMENSION(:) :: p !ZnO p USE module-name REAL(krealhp), POINTER,DIMENSION(:) :: q !Zno q Modules permit specifying private and public attributes for REAL(krealhp), POINTER,DIMENSION(:) :: V !min data and functions. An interface block can be used to REAL(krealhp), POINTER,DIMENSION(:) :: vpast provide an explicit interface to module procedures. END TYPE zno_char ………………………………… Functions placed in a module are automatically checked for TYPE(zno_str), & the number of arguments and for argument types by the DIME NSION (:), ALLOCATABLE, PRIVATE :: Zno compiler. It is a very important safety feature in Fortran-95. TYPE(zno_char), & DIMENSION (:), ALLOCATABLE, PRIVATE :: Znoch To be more specific, all EMTP components can be ………………………………… contained in separate and completely detachable modules. CONTAINS The list of components includes network element models SUBROUTINE znomod(ido) and program procedures for network solutions and INTEGER :: k,i,j,jj CHARACTER(LEN=*) ido input/output operations. REAL(krealhp) :: vnew,iguess,vguess Module usage dictates the design of EMTP-F95 code. A ………………………………… completely modular architecture is created by using a core todocall : SELECT CASE (ido) code capable of handling all the required solution methods CASE('initialize') !* initialization procs ………………………………… and interacting with network components (models) only CASE('put_nodes_in_Yaug') !*symbolic data through a specific set of communication protocols, called ………………………………… request signals. Components react by sending back CASE DEFAULT participation data. Each component module is completely RETURN END SELECT todocall encapsulated and based on “case” selectors. Each case RETURN being a response section for the received request. END SUBROUTINE znomod Modules are also very useful in the development project END MODULE zno_branch of a large scale application;