Pdemodelica a High-Level Language for Modeling with Partial Differential Equations
Total Page:16
File Type:pdf, Size:1020Kb
Linköping Studies in Science and Technology Dissertation No. 1016 PDEModelica A High-Level Language for Modeling with Partial Differential Equations by Levon Saldamli Department of Computer and Information Science Linköpings universitet SE-581 83 Linköping, Sweden Linköping 2006 “...toboldlygowhere no man has gone before.” James T. Kirk Abstract This thesis describes work on a new high-level mathematical modeling language and framework called PDEModelica for modeling with partial differential equa- tions. It is an extension to the current Modelica modeling language for object- oriented, equation-based modeling based on differential and algebraic equations. The language extensions and the framework presented in this thesis are consistent with the concepts of Modelica while adding support for partial differential equa- tions and space-distributed variables called fields. The specification of a partial differential equation problem consists of three parts: 1) the description of the definition domain, i.e., the geometric region where the equations are defined, 2) the initial and boundary conditions, and 3) the ac- tual equations. The known and unknown distributed variables in the equation are represented by field variables in PDEModelica. Domains are defined by a geo- metric description of their boundaries. Equations may use the Modelica derivative operator extended with support for partial derivatives, or vector differential opera- tors such as divergence and gradient, which can be defined for general curvilinear coordinates based on coordinate system definitions. The PDEModelica system also allows the partial differential equation models to be defined using a coefficient-based approach, where PDE models from a library are instantiated with different parameter values. Such a library contains both con- tinuous and discrete representations of the PDE model. The user can instantiate the continuous parts and define the parameters, and the discrete parts containing the equations are automatically instantiated and used to solve the PDE problem numerically. Compared to most earlier work in the area of mathematical modeling languages supporting PDEs, this work provides a modern object-oriented component-based approach to modeling with PDEs, including general support for hierarchical mod- eling, and for general, complex geometries. It is possible to separate the geometry definition from the model definition, which allows geometries to be defined sep- arately, collected into libraries, and reused in new models. It is also possible to separate the analytical continuous model description from the chosen discretization and numerical solution methods. This allows the model description to be reused, independent of different numerical solution approaches. The PDEModelica field concept allows general declaration of spatially distributed v variables. Compared to most other approaches, the field concept described in this work affords a clearer abstraction and defines a new type of variable. Arrays of such field variables can be defined in the same way as arrays of regular, scalar variables. The PDEModelica language supports a clear, mathematical syntax that can be used both for equations referring to fields and explicit domain specifica- tions, used for example to specify boundary conditions. Hierarchical modeling and decomposition is integrated with a general connection concept, which allows connections between ODE/DAE and PDE based models. The implementation of a Modelica library needed for PDEModelica and a pro- totype implementation of field variables are also described in the thesis. The PDEModelica library contains internal and external solver implementations, and uses external software for mesh generation, requisite for numerical solution of the PDEs. Finally, some examples modeled with PDEModelica and solved using these implementations are presented. vi Acknowledgments First of all, I would like to thank my supervisor Peter Fritzson, for the inspiration and the motivation I needed to finish this thesis, and for commenting both my work and my language. I would also like to thank my co-supervisor Bernhard Bach- mann, for help with parts of the implementation in this work, and for his valuable comments on the contents of this thesis. Thanks also to Hansjürg Wiesmann for help with the implementation and for interesting discussions. Other colleagues at PELAB I would like to thank, who have contributed to the OpenModelica platform, where I could experiment with language extensions, are Peter Aronsson, Kaj Nyström, Adrian Pop, Peter Bunus, Håkan Lundvall, and David Broman. Thanks to the rest of the PELAB members for interesting dis- cussions about both work and other more or less relevant subjects, especially to Jens Gustavsson, Andreas Borg, and John Wilander for our very interesting work together on research methodology and computer science. Special thanks to An- drzej Bednarski for being both a colleague and a friend. Many thanks to Bodil Mattsson-Kihlström for her support in many ways, and to Lillemor Wallgren for her administrative help. Finally, I would like to thank my parents for enhancing my motivation, and my friends, for their company and support that helped me finish this work. This work has been supported by the Swedish Foundation for Strategic Research in the ECSEL graduate school and the VISIMOD project, the European Commis- sion in the RealSim project, and by Vinnova in the VISP project. vii viii Contents 1 Introduction 1 1.1PDE-basedModelExample..................... 2 1.1.1 ConnectiontoODE/DAEmodels............. 4 1.2ResearchMethod.......................... 6 1.3Contributions............................ 8 1.4OverviewoftheThesis....................... 9 2 Background 11 2.1Modelica.............................. 11 2.1.1 Classes........................... 12 2.1.2 VariableDeclarations.................... 12 2.1.3 SubtypingandInheritance................. 13 2.1.4 Modifications........................ 15 2.1.5 EquationsandAlgorithms................. 16 2.1.6 Replaceable Elements . .................. 16 2.2DifferentialEquations........................ 18 2.2.1 Fields............................ 18 2.2.2 Ordinary Differential Equations and Differential and Alge- braicEquations....................... 18 2.2.3 PartialDifferentialEquations................ 19 2.2.4 Boundary Conditions . .................. 20 2.2.5 Initial Conditions . .................. 21 2.2.6 Classification........................ 21 2.3 Numerical Solution Methods . .................. 22 2.3.1 Finite Difference Methods . .............. 22 2.3.2 Finite Element Methods .................. 23 2.3.3 MethodofLines...................... 25 3 A Modelica Library for PDE-based Modeling 27 3.1 Introduction ............................. 27 3.1.1 Separation into Continuous and Discrete Parts . 28 3.2 Continuous Part Design . .................. 28 ix Contents 3.2.1 Standard Boundaries . ................. 30 3.3ThePackageDesign........................ 31 3.4 Continuous Part . ........................ 34 3.4.1 Boundary Definition . ................. 34 3.4.2 Domain Definition . ................. 34 3.4.3 Fields............................ 35 3.4.4 Included Boundaries . ................. 36 3.4.5 EquationModels...................... 42 3.4.6 Boundary Conditions . ................. 44 3.5DiscretePartDesign........................ 45 3.5.1 DomainDiscretization................... 46 3.5.2 ModelDiscretization.................... 49 3.6TheFEMpackage.......................... 53 3.6.1 DiscreteDomain...................... 54 3.6.2 DiscreteField........................ 55 3.6.3 ThePoissonEquation................... 56 3.6.4 TheDiffusionEquation................... 56 3.6.5 PDELibraryInterface................... 56 3.7RheolefFiniteElementSolver................... 57 3.7.1 Forms............................ 57 3.7.2 Boundary Conditions . ................. 58 3.8TheFEMFormspackage...................... 59 3.8.1 DiscreteField........................ 59 3.8.2 Form............................ 60 3.8.3 ThePoissonEquation................... 61 3.8.4 TheDiffusionEquation................... 61 3.8.5 PDELibraryInterface................... 61 3.9Example............................... 62 3.10Discussion.............................. 67 4 Language Elements for Space-distributed Models 69 4.1 Introduction . ............................ 69 4.2Fields................................ 70 4.2.1 FieldVariables....................... 70 4.2.2 FieldConstructor...................... 71 4.2.3 FieldTypeinExpressions................. 71 4.2.4 AccessingFieldValues................... 73 4.3 Future Language Extensions . ................. 74 4.3.1 Domain Geometry Definition . ............. 74 4.3.2 DifferentialOperators................... 78 4.3.3 DomainSpecifierinEquations............... 81 4.3.4 FieldReduction....................... 82 x Contents 4.3.5 Discussion......................... 83 5 Implementation 85 5.1ModelicaCompiler......................... 85 5.1.1 ModelicaParser...................... 86 5.1.2 ModelicaTranslator.................... 88 5.2ThePDELibrary.......................... 94 5.2.1 TheFiniteElementPackage................ 95 5.3PDEModelicaSolverEnvironment................. 99 5.3.1 SpatialDiscretizationofEquations............. 99 6 Examples 105 6.1StationaryHeatTransfer...................... 105 6.1.1 Neumann and Robin Boundary Conditions . 107 6.2Time-dependentHeatTransfer................... 108 6.2.1 HeatTransferwithController............... 109 6.3Discussion.............................. 110 7 Previous Approaches With Examples