Compiling Modelica About the Separate Translation of Models from Modelica to Ocaml and Its Impact on Variable-Structure Modeling

Compiling Modelica About the Separate Translation of Models from Modelica to Ocaml and Its Impact on Variable-Structure Modeling

Compiling Modelica About the Separate Translation of Models from Modelica to OCaml and its Impact on Variable-Structure Modeling vorgelegt von Dipl. Inform. Christoph Höger von der Fakultät IV - Elektrotechnik und Informatik der Technischen Universität Berlin zur Erlangung des akademischen Grades Doktor der Naturwissenschaften - Dr. rer. nat. - genehmigte Dissertation Promotionsausschuss: Vorsitzender: Prof. Dr. Volker Markl Gutachter: Prof. Dr. Peter Pepper Prof. David Broman, PhD Prof. Dr. Stefan Jähnichen Tag der wissenschaftlichen Aussprache: 07.05.2018 Berlin, 2019 zusammenfassung Die gleichungsbasierte, objektorientierte Modellierungssprache Modelica ist standardisiert und hat viele verschiedene Anwendungsgebiete und Im- plementierungen. Die meisten dieser Implementierungen folgen einem gemeinsamen Schema: Modelle werden erst kombiniert, dann zu einem Gleichungssystem reduziert, analysiert und schließlich in effizienten Si- mulationscode übersetzt. Analyse und Übersetzung sind nicht Teil der Sprachspezifikation. Die Details ihrer Umsetzung sind der Implementie- rung überlassen. Dieser Ablauf hat einen Entscheidenden Einfluss auf die Beziehung zwischen Modellen und ihrer Simulation. Nach der Erzeugung des Simulationscodes kann ein Modell seine Struktur, d.h. seine Gleichun- gen, nicht mehr ändern. Diese Dissertation untersucht einen alternativen Ansatz, in dem je- des Modell getrennt betrachtet wird und so eine intrinsische, kontext- unabhängige Bedeutung hat. Aus dieser Perspektive ist die Simulation kein von der Modellierungssprache unabhängiger Schritt, sondern wird in dieser selbst ausgedrückt. So kann jedes Modell separat in Maschinencode übersetzt werden. Daraus folgt die Möglichkeit, den Simulationsverlauf aus den Modellen heraus zu steuern und eine mächtige Variante strukturdyna- mischer Systeme zu implementieren. Die Übersetzung von Modellen beruht auf einer rigorosen Definition einzelner Aspekte der Semantik von Modelica in Form einer Kernsprache, Mcl. Diese Kernsprache konzentriert sich auf die wesentlichsten Aspekte von Modelica: Die hierarchische Organisation von Modellen und ihre Re- duktion zu Gleichungssystemen. Die Formalisierung der Reduktion erfolgt mit Continuations und ermöglicht so die Implementierung von Struktur- dynamik. Der so implementierte Compiler kann mit vielen Sprachmittel von Modelica umgehen. Darüberhinaus unterstützt er eine unkomplizierte Form zur Modellierung strukturdynamischer Systeme mit vielen Modi. Weil Modelle in Mcl Objekte erster Klasse sind, kann ihre symbolische und numerische Verarbeitung in der Sprache selbst implementiert werden. Eine Kernel Bibliothek stellt die Mittel zur Erzeugung, Transformation und Simulation von kontinuierlichen Gleichungen diskreten Signalen bereit. Dieser Ansatz reduziert die Komplexität der Sprachsemantik erheblich und erleichtert die Änderung oder Erweiterung der Algorithmen die Modelle verarbeiten. abstract The equation-based object-oriented modeling language Modelica is an openly accessible standard with many implementations and applications. Most, if not all, tools that execute a Modelica simulation follow a common scheme: Models are loaded, composed, analyzed, and transformed into a system of equations. This system is then further simplified, translated into efficient code, and simulated. The latter steps are executed bythe tool at hand and not specified by the modeling language’s semantics. This architecture has profound impact on the relationship between models and their simulation. After the simulation code has been generated, a model cannot change its structure, i.e. its equations, during simulation. This thesis investigates an alternative approach: Here, each model is considered separately and has an intrinsic context-independent meaning. In this view, simulation is not a tool-specific step, disconnected from the language semantics but expressed in the modeling language itself and each model can be translated separately into executable code. Consequently, a model can then control the course of the simulation, enabling a powerful variant of variable-structure systems. The translation of models builds upon a partial but rigorous definition of the modeling language’s semantics in the form of a core language, Mcl. The core language focuses on the most important aspects of Modelica: the organization of models in hierarchies and their reduction to systems of equations. The formalization of the reduction in a continuation-passing style permits the definition of variable-structure models. The compiler, although only a prototype, is capable of translating several important fea- tures of Modelica. As an extension to the language, it has a straightforward support for variable-structure systems with many modes. With the help of first-class models it becomes possible to implement the symbolical and numerical treatment of models in Mcl itself. A kernel library provides the means for the description of equations, discrete sig- nals, symbolic manipulation, and simulation. This architecture reduces the complexity of the modeling language to a manageable magnitude and also makes it rather simple to extend or change the features of that library. acknowledgement It took me many years to develop this dissertation, and during this time, I could rely on the support and advice of several people. Without them, I certainly would not have finished this work. First, I want to thank my supervisor, Prof. Dr. Peter Pepper for his expert advice and unconditional support and especially for the friendly and familiar atmosphere that he created in our group. Peter encouraged me to visit many conferences, workshops, and other conventions all around the world. I am deeply grateful for everything I learned there and every contact I made at these meetings. During the years I worked with many colleagues from many different circles, far too many to name them all. I am especially thankful for the cordial reception into the Modelica Association, the stimulating academic discussions in the community around the EOOLT workshop series, and the fascinating interdisciplinary work in the AMSUN project. Everyone who discussed argued or collaborated with me on these occasions: Thank you! There were, of course, some colleagues closer than others, literally and figuratively. Dr. Judith Rohloff and Dr. Florian Lorenzen worked inthe office next door. Both always had an open ear when I stumbled uponthe minor differences between our academic surrounding and the often more pragmatic world of Modelica, and I vividly recall our lengthy and lively discussions. I cannot begin to enumerate the topics where I learned from the two, and I am deeply grateful for the time we collaborated. Writing a dissertation is not just a profession but easily influences ones private life as well. Here, I could rest on the unwavering support of my whole family, especially my parents Wera and Bernhard. They never com- plained when I came to a weekend’s visit just to disappear behind a screen or concentrate on some sheet of paper full of nonsensical symbols. There is the one person that I owe the most. My wife Mareike has not only endured me throughout all the ups and depths, taken the load off me when I needed it the most, and helped me to clear my mind when I was stuck again with some proof. She also was always ready to listen to the tiresome technical details, the tedious problems of specifying a program- ming language, and my convoluted attempts at a solution. Words cannot describe how lucky I am to have found such a perfect partner. I love you! For Lena & Johanna contents 1 Introduction 13 1.1 Differential Algebraic Equations 14 1.2 Modelica 24 1.3 Detailed Research Questions 33 1.4 Contributions and Outline 35 1.5 Research Method 36 1.6 Notational Conventions 37 2 The Model Composition Language 39 2.1 Base Language Definition 39 2.2 Modeling Routines 45 2.3 Classes and Object-Oriented Modeling 52 2.4 Variable-Structure Modeling 66 2.5 Top-Level Entities: Packages and Modules 71 3 Modeling & Simulation as a Library 75 3.1 Outline 75 3.2 Fundamental Data Structures 78 3.3 Quasi-Primitive Operations 79 3.4 Embedding Equations 82 3.5 Elaboration Interface 98 3.6 Example 102 4 From Modelica via Mcl to OCaml 105 4.1 Front End 105 4.2 The Compilation Pipeline 120 4.3 Desugaring Model Routines 132 4.4 Separating Terms and Hierarchy 140 4.5 Evaluating Hierarchical Terms 146 4.6 Resolving References 151 4.7 Correctness of the Second Phase 157 4.8 Back End 159 12 5 Example Applications 165 5.1 Simple Models 166 5.2 Implementing a Library 172 5.3 Parameter Optimization 180 5.4 Reusing Models by Inheritance 183 6 Conclusion 187 6.1 Recapitulation 187 6.2 Related Work 189 6.3 Future Work 196 6.4 Discussion 200 Appendices 216 A Notations 217 B Complete Syntax of Mcl 219 C Extensive Definitions 221 D Sketches of Selected Proofs 233 E Obtaining the Implementation 243 F Kernel Library 247 G Example Sources 271 1 introduction Modeling and simulation have become indispensable tools for modern engineering. Modeling languages convey methods, tools, and techniques from the domain of software development into the world of modeling and engineering and especially into young industries that cannot rely on centuries of experience. In 2010, an engineer who was working on the modeling & simulation of offshore wind farms asked the author of this thesis the seemingly inno- cent question, whether it could be possible to compile Modelica libraries separately on a file-by-file basis. Separate compilation is a common feature of compilers for

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    289 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us