Input File Viennaipd Application
Total Page:16
File Type:pdf, Size:1020Kb
ViennaIPD - An Input Control Language for Scientific Computing Josef Weinbub Karl Rupp Siegfried Selberherr Institute for Microelectronics, Technische Universit¨atWien Gußhausstraße 27-29 / E360 A-1040 Vienna, Austria E-mail: {weinbub|rupp|selberherr}@iue.tuwien.ac.at ABSTRACT #include "ipdP.h" A powerful control language, named ViennaIPD, has int main(int argc, char** argv) { been developed. The library based software is capable ipdChar *s; // Read a ViennaIPD input file of reading complex input datasets which can be accessed ipdReadInputDeck(argv[1]); 1. // Access data from C/C++ applications by a programming interface. 3. ipdGetStringByName("~a", &s); ViennaIPD supports a convenient C-like input file lan- printf("Value of ~a: %s\n", s); // Manipulate data 4. guage, object oriented structuring of datasets, powerful ipdSetIntegerByName("~SecA.a", 2); a inheritance mechanisms and a unit system. The input printf("Value of ~SecA.a set to: %d\n", 2); return 0; b file language as well as the programming interface is dis- } cussed in detail. Application SecA a d INTRODUCTION SecB a Applications for scientific computing require a power- 2. d a = "A short text"; ful control language to satisfy the need of control pa- SubSecC c b = 2.2; rameters, e.g. material properties, models to take into SecA { account, model parameters, process definitions, simu- ext a = 1; d = 2 * a; lation modes, iteration schemes, and numerical behav- } ViennaIPD ior [1, 2, 3, 4]. As a result, control files grow in size, SecB : SecA { which results in decreased maintainability. Therefore a d = 3 * a; SubSecC powerful control language has been developed as part of { c = 1; } the MINIMOS-NT simulation software package [5, 6]. } To enlarge the field of application the control language has been extracted, revisited, and packaged to be dis- Input File tributable as a standalone control language named Vi- ennaIPD. ViennaIPD offers a powerful inheritance con- Figure 1: ViennaIPD workflow. The application passes the cept, unit conversion capabilities and the ability to di- filename of the input file to ViennaIPD (1.). The input file rectly access existing input files. The latter is especially is used to populate the tree based datastructure (2.). The of interest for reasons of post-processing simulation re- data can be accessed (3.) and manipulated (4.) by the sults. Figure 1 depicts a comprehensible overview how application. ViennaIPD is used. ViennaIPD provides a powerful input file language which aims to deal with the manifold parameter de- mands of simulation software. The library itself is writ- Therefore any kind of data set hierarchy can be built. ten in C, however, applications can be based on either In this context, inheritance of sections is supported to C or C++. The most fundamental element is a vari- enable, for example, reusability of section elements. Fi- able. To describe dependencies to other variables, a nally a large set of functions is provided to enable math- variable contains an expression, that is evaluated at run- ematical computations within the input files. time. Different variable types are supported as well as The paper is organized as follows: The first section pro- accessibility control. Furthermore, a section provides vides an overview of the ViennaIPD control language, a means of structuring variables to enable associative whereas the second section outlines the programming variable definitions. A section holds an arbitrary set of interface. Furthermore, the third section depicts a use variables and subsections. case example. Finally, the fourth section compares Vi- ennaIPD to various other input control approaches. 34 INPUT FILE SPECIFICATION However, this variable type can be used to temporarily The input file specification is based on a comprehensible store data, for example the result of a computation. language. The usage is similar to common programming Sections languages, e.g. C. Additionally, object oriented features ViennaIPD supports structures of variables, so called are provided to enable structuring of large data sets, sections, to manage large input files. A section is defined i.e. inheritance mechanisms. Furthermore, a powerful with unit system is provided which supports the validity of computations based on quantities. 1 <section name> { ... } Variables The following snippet depicts a section named Solve An arbitrary number of variables can be defined. The with a read-only keyword variable. general definition of a variable is 1 Solve { maxStepSize = 1e30; } 1 <type> <variable name > = <e x p r e s s i o n >; Sections can be nested to arbitrary depth <type> must be a valid variable type. The available variable types are listed in Table 1. Note that if no 1 BaseSection { 2 SubSection { <type> is mentioned, the default key type is used. 3 SubSubSection {} <variable name> can be of any length, can contain 4 } capital and small letters, an underscore, and numbers. 5 } <type> Description ViennaIPD enables also inheritance of sections. ext external variable - read- and writeable 1 BaseSection { x1 = −3; } key keyword variable - read-only (default) 2 DerivedSection : BaseSection; aux auxiliary variable - hidden DerivedSection is inherited from BaseSection. Con- Table 1: Types of Variables sequently, DerivedSection contains all elements (vari- ables and subsections) of BaseSection. However, the name must not begin with a number. An Note, that the variables of BaseSection transparently expression can be assigned to a variable by using the exist in DerivedSection. Hence, if a variable in assignment operator = and a valid data-type (Table 2). BaseSection changes, it changes in DerivedSection too. Type Example Furthermore, multiple inheritance is supported. Boolean a = true; 1 BaseSection1 { a = 1 ; } Integer a = 3; 2 BaseSection2 { b = 3 ; } Real a = 3.1415; 3 DerivedSection : BaseSection1 , BaseSection2; Complex a = 4.3 + 3.1 j; DerivedSection a b Quantity a = 3.1415 "m/s"; consists of two variables and in- BaseSection1 BaseSection2 String a = "This is a string"; herited from and , respec- Array a = [1, "pi", 3 A]; tively. Additionally, conditional inheritance enables to inherit Table 2: Types of Data from sections based on specific conditions. 1 Section : BaseSection1 ? expression1 , The following snippet depicts a few examples which 2 BaseSection1 ? expression2 , make use of the available variable types. 3 ... {} 1 s o m e f l o a t = 3 . 3 ; Conditional inheritance is an extension to multiple in- 2 key some text = ”some Text”; heritance. Several base sections can be specified for in- 3 ext x = 3 2 ; 4 ext y = 4 ; heritance, an expression can be assigned to each one. 5 aux a = s q r t ( x ∗ x + y ∗ y ) ; The following snippet depicts the usage. 6 ex = x / a ; 1 7 ey = y / a ; Switch = 0 ; 2 D e r ivedSection : BaseSection1 , 3 > Lines 1,2,6,7 depict keyword variables. Hence, the as- BaseSection2 ? (Switch −1) , 4 BaseSection3 ? (Switch < 1) signed data can be accessed only, not altered. Lines 3,4 5 {} depict external variables, for which data can be accessed and altered. Line 5 outlines an application case for the DerivedSection is always inherited from auxiliary variable. This variable cannot be accessed by BaseSection1. As Switch is 0, the conditions for the programming interface, it is hidden. BaseSection2 and BaseSection3 both hold. 35 Therefore, DerivedSection is additionally inherited 1 from BaseSection2 and BaseSection3. If Switch Q1 = 3 ”A” ; 2 Q2 = 2 ”m” ; is set to 2, DerivedSection is solely inherited from 3 Q3 = Q1 ∗ Q2 ; //OK BaseSection1 and BaseSection2. 4 Q4 = Q1 + Q2 ; // Error Elements of inherited sections can be locally modified. 1 BaseSection { PROGRAMMING INTERFACE 2 x = 1 ; The ViennaIPD Programming Interface is based on the 3 y = 2 ; 4 } C programming language. It provides an interface to the 5 DerivedSection : BaseSection { y = 4 ; } internal tree-based datastructures of ViennaIPD. Data can be traversed and accessed. DerivedSection consists of the two variables x and y, where the variable x is inherited from BaseSection Interface Setup and the variable y is locally modified. So the vari- To be able to use the interface the ViennaIPD header able DerivedSection.x equals 1 and the variable file has to be included. DerivedSection.y equals 4. 1 #include ”ipd.h” Functions The following code snippet depicts the initialization and ViennaIPD enables the use of functions within input the population of the datastructure from an input file. files. Functions can be used in expressions which are stored in variables. 1 // basic initialization 2 i p d I n i t (NULL, NULL) ; 1 < > < > < > type variable name = function (parameters ); 3 // create a new database 4 ipdCreateBase(”NameOfTheDatabase” , 0); An arbitrary number of parameters is supported. 5 // read the inputfile 6 ipdReadInputDeck(argv [1]); 1 a1 = func1(); // 0 Parameter 2 a2 = func2(1 + 2); // 1 Parameter 3 a3 = func3(”hello”, a1); // 2 Parameter Accessing Data ViennaIPD provides built-in functions, for example Specialized getter and setter functions are provided to a large set of mathematical functions, e.g. sin(), access and alter specific data types. The following code pow(), sqrt(), to list a few of them. The following snippet depicts the reading and writing process based snippet depicts the computation of the sine of a com- on these functions. plex number. 1 // declare a variable of type long 2 1 a = sin(4.42 + j ∗ 5 . 9 ); ipdLong i ; 3 // get the "c" integer value Furthermore support functions are provided, e.g. if() 4 ipdGetIntegerByName(”∼c ” , &i ) ; 5 // set the "c" integer value statement, conversion functions, array sizes, random 6 ipdSetIntegerByName(”∼c ” , 2 ) ; number generator, to name a few. Note the ∼ prefix, which indicates the root level of the Units datastructure hierarchy. Therefore variables can be ac- ViennaIPD provides a powerful unit system. A unit is cessed by absolute path addressing. For example access- used in combination with the quantity datatype (Table ing an integer variable named a within a section named 2) and consists of a valid unit name, of which many are BaseSection would be implemented by the following: provided.