TUTORIAL - COURSE Introduction To Object-Oriented . - OpenModelica

Transcription

TUTORIAL – COURSEIntroduction to Object-OrientedModeling and Simulation with ModelicaUsing OpenModelicaPeter FritzsonCopyright (c) Open Source Modelica ConsortiumVersion 2012

AbstractObject-Oriented modeling is a fast-growing area of modeling and simulation that provides a structured,computer-supported way of doing mathematical and equation-based modeling. Modelica is today the mostpromising modeling and simulation language in that it effectively unifies and generalizes previous objectoriented modeling languages and provides a sound basis for the basic concepts.The Modelica modeling language and technology is being warmly received by the world community inmodeling and simulation with major applications in virtual prototyping. It is bringing about a revolution inthis area, based on its ease of use, visual design of models with combination of lego-like predefined modelbuilding blocks, its ability to define model libraries with reusable components, its support for modelingand simulation of complex applications involving parts from several application domains, and many moreuseful facilities. To draw an analogy, Modelica is currently in a similar phase as Java early on, before thelanguage became well known, but for virtual prototyping instead of Internet programming.The tutorial presents an object-oriented component-based approach to computer supportedmathematical modeling and simulation through the powerful Modelica language and its associatedtechnology. Modelica can be viewed as an almost universal approach to high level computationalmodeling and simulation, by being able to represent a range of application areas and providing generalnotation as well as powerful abstractions and efficient implementations.The tutorial gives an introduction to the Modelica language to people who are familiar with basicprogramming concepts. It gives a basic introduction to the concepts of modeling and simulation, as well asthe basics of object-oriented component-based modeling for the novice, and an overview of modeling andsimulation in a number of application areas.The tutorial has several goals: Being easily accessible for people who do not previously have a background in modeling,simulation.Introducing the concepts of physical modeling, object-oriented modeling and component-basedmodeling and simulation.Giving an introduction to the Modelica language.Demonstrating modeling examples from several application areas.Giving a possibility for hands-on exercises.

Presenter’s dataPeter Fritzson is Professor and research director of the Programming Environment Laboratory, atLinköping University. He is also director of the Open Source Modelica Consortium, director of theMODPROD center for model-based product development, and vice chairman of the Modelica Association,organizations he helped to establish. During 1999-2007 he served as chairman of the ScandinavianSimulation Society, and secretary of the European simulation organization, EuroSim. Prof. Fritzson'scurrent research interests are in software technology, especially programming languages, tools andenvironments; parallel and multi-core computing; compilers and compiler generators, high levelspecification and modeling languages with special emphasis on tools for object-oriented modeling andsimulation where he is one of the main contributors and founders of the Modelica language. ProfessorFritzson has authored or co-authored more than 250 technical publications, including 17books/proceedings.1. Useful Web LinksThe Modelica Association Web Pagehttp://www.modelica .orgModelica htmlThe OpenModelica open source project with download of the free OpenModelica modeling and simulationenvironmenthttp://www.openmodelica.org

Principles of Object-OrientedModeling and Simulationwith ModelicaPeter FritzsonLinköping University, peter.fritzson@liu.seSlidesBased on book and lecture notes by Peter FritzsonContributions 2004-2005 by Emma Larsdotter, Peter Bunus, Peter FContributions 2007-2008 by Adrian Pop, Peter FritzsonContributions 2009 by David Broman, Jan Brugård, MohsenTorabzadeh-Tari, Peter FritzsonContributions 2010 by Mohsen Torabzadeh-Tari, Peter FritzsonContributions 2012 by Olena Rogovchenko, Peter Fritzson2012-10-24 CourseTutorial Based on Book, 2004Download OpenModelica SoftwarePeter FritzsonPrinciples of Object OrientedModeling and Simulation withModelica 2.1Wiley-IEEE Press, 2004,940 pages OpenModelica www.openmodelica.org Modelica Association www.modelica.org2Peter FritzsonCopyright Open Source Modelica Consortiumpelab1

New IntroductoryModelica BookSeptember 2011232 pagesWileyIEEE PressFor IntroductoryShort Courses onObject OrientedMathematicalModeling3Peter FritzsonCopyright Open Source Modelica ConsortiumpelabOutline Day 1Part IIntroduction to Modelica and ademo examplePart IIIModelica language conceptsand textual modeling4Peter FritzsonCopyright Open Source Modelica ConsortiumPart IIModelica environmentsPart IVGraphical modeling and theModelica standard librarypelab2

Acknowledgements, Usage, Copyrights If you want to use the Powerpoint version of these slidesin your own course, send an email to:peter.fritzson@ida.liu.se Thanks to Emma Larsdotter Nilsson, Peter Bunus, DavidBroman, Jan Brugård, Mohsen-Torabzadeh-Tari, AdeelAsghar for contributions to these slides. Most examples and figures in this tutorial are adaptedwith permission from Peter Fritzson’s book ”Principlesof Object Oriented Modeling and Simulation withModelica 2.1”, copyright Wiley-IEEE Press Some examples and figures reproduced with permissionfrom Modelica Association, Martin Otter, HildingElmqvist, and MathCore Modelica Association: www.modelica.org OpenModelica: www.openmodelica.org5Peter FritzsonCopyright Open Source Modelica ConsortiumpelabSoftware Installation - Windows Start the software installation Install OpenModelica-1.9.0beta2.exe from theUSB Stick6Peter FritzsonCopyright Open Source Modelica Consortiumpelab3

Software Installation – Linux (requires internet connection) Go load-linux and follow the instructions.7Peter FritzsonCopyright Open Source Modelica ConsortiumpelabSoftware Installation – MAC (requires internet connection) Go load-mac and follow the instructions or followthe instructions written below. The installation uses MacPorts. After setting upa MacPorts installation, run the followingcommands on the terminal (as root): echo rsync://build.openmodelica.org/macports/ /opt/local/etc/macports/sources.conf # assuming you installed into/opt/local port selfupdate port install openmodelica-devel8Peter FritzsonCopyright Open Source Modelica Consortiumpelab4

Outline Introduction to Modeling and Simulation Modelica - The next generation modeling andSimulation Language Modeling and Simulation Environments andOpenModelica Classes Components, Connectors and Connections Equations Discrete Events and Hybrid Systems Algorithms and Functions Demonstrations9Peter FritzsonCopyright Open Source Modelica ConsortiumpelabWhy Modeling & Simulation ? Increase understanding of complex systemsDesign and optimizationVirtual prototypingVerificationBuild more complex systems10Peter FritzsonCopyright Open Source Modelica Consortiumpelab5

What is a system? A system is an object or collection ofobjects whose properties we want to study Natural and artificial systems Reasons to study: curiosity, to build itCollectorHot waterStorage tankHeaterElectricityCold water11Peter FritzsonCopyright Open Source Modelica ConsortiumPumppelabExamples of Complex Systems sPower plantsHardware-in-the-loop,real-time simulationPeter FritzsonCopyright Open Source Modelica Consortiumpelab6

ExperimentsAn experiment is the process of extracting informationfrom a system by exercising its inputsProblems Experiment might be too expensive Experiment might be too dangerous System needed for the experiment might not yet exist13Peter FritzsonCopyright Open Source Modelica ConsortiumpelabModel conceptA model of a system is anything an experiment can beapplied to in order to answer questions about that systemKinds of models: Mental model – statement like “a person is reliable”Verbal model – model expressed in wordsPhysical model – a physical object that mimics the systemMathematical model – a description of a system wherethe relationships are expressed in mathematical form – avirtual prototype Physical modeling – also used for mathematical modelsbuilt/structured in the same way as physical models14Peter FritzsonCopyright Open Source Modelica Consortiumpelab7

SimulationA simulation is an experiment performed on a modelExamples of simulations: Industrial process – such as steel or pulpmanufacturing, study the behaviour under differentoperating conditions in order to improve the process Vehicle behaviour – e.g. of a car or an airplane, foroperator training Packet switched computer network – study behaviourunder different loads to improve performance15Peter FritzsonCopyright Open Source Modelica ConsortiumpelabReasons for Simulation Suppression of second-order effects Experiments are too expensive, too dangerous, orthe system to be investigated does not yet exist The time scale is not compatible with experimenter(Universe, million years, ) Variables may be inaccessible. Easy manipulation of models Suppression of disturbances16Peter FritzsonCopyright Open Source Modelica Consortiumpelab8

Dangers of SimulationFalling in love with a modelThe Pygmalion effect (forgetting that model is not the realworld, e.g. introduction of foxes to hunt rabbits in Australia)Forcing reality into the constraints of a modelThe Procrustes effect (e.g. economic theories)Forgetting the model’s level of accuracySimplifying assumptions17Peter FritzsonCopyright Open Source Modelica ConsortiumpelabBuilding Models Based on KnowledgeSystem knowledge The collected general experience in relevant domains The system itselfSpecific or generic knowledge E.g. software engineering knowledge18Peter FritzsonCopyright Open Source Modelica Consortiumpelab9

Kinds of Mathematical Models Dynamic vs. Static models Continuous-time vs. Discrete-time dynamic models Quantitative vs. Qualitative models19Peter FritzsonpelabCopyright Open Source Modelica ConsortiumDynamic vs. Static ModelsA dynamic model includes time in the modelA static model can be defined without involving timeResistor voltage – static systemInput currentpulseCapacitor voltage - dynamictime20Peter FritzsonCopyright Open Source Modelica Consortiumpelab10

Continuous-Time vs.Discrete-Time Dynamic ModelsContinuous-time models may evolve their variable valuescontinuously during a time periodDiscrete-time variables change values a finite number of timesduring a time periodContinuousDiscretetime21Peter FritzsonpelabCopyright Open Source Modelica ConsortiumQuantitative vs. Qualitative ModelsResults in qualitative dataVariable values cannot be represented numericallyMediocre 1, Good 2, Tasty 3, Superb 4SuperbTastyGoodMediocretimeQuality of food in a restaurant accordingto inspections at irregular points in time22Peter FritzsonCopyright Open Source Modelica Consortiumpelab11

Using Modeling and Simulationwithin the Product Design-VLevel of AbstractionExperience ecificationProduct verification anddeploymentPreliminary feature designDesignIntegrationArchitectural design andsystem functional designDesignRefinementSubsystem level integration andverificationVerificationDetailed feature design andimplementationSubsystem level integration testcalibration and verificationComponent verificationRealizationDocumentation, Version and Configuration Management23Peter FritzsonpelabCopyright Open Source Modelica ConsortiumPrinciples of Graphical Equation-Based Modeling Each icon represents a physical componenti.e. Resistor, mechanical Gear Box, Pump Composition lines represent the actualphysical connections i.e. electrical line,mechanical connection, heat flow Variables at the interfaces describeinteraction with other componentComponent 1 Physical behavior of a component isdescribed by equationsComponent 3Component 2Connection Hierarchical decomposition of components24Peter FritzsonCopyright Open Source Modelica Consortiumpelab12

Application Example – Industry Robotk2iqddRefqdRefqRef11SSk1axis6cut el0.03Jmotor JpSum-Kv0.3sumw Sum 1 1-rate2rate3b(s)340.8a(s)Sjoint 0axis4SiRefgear ifric Rv0qRefspring C 0.004*D/w mRd1 100Rp1 200Rd2 100Ri 10-- diff pow erOpIRa 250 La (250/(2*D*w m))Rp2 50qdaxis1VsRd4 100emfyxinertialRd3 100Srel n*transpose(n) (identity(3)- n*transpose(n))*cos(q)skew(n)*sin(q);g3wrela n*qd;g1zrela n*qdd;Sb Sa*transpose(Srel);r0b r0a;hall1vb Srel*va;wb Srel*(wa wrela);g4ab Srel*aa;qdg2zb Srel*(za zrela cross(wa, wrela));hall2wrqCourtesy of Martin Otter25Peter FritzsonCopyright Open Source Modelica ConsortiumpelabMulti-Domain (Electro-Mechanical) Modelica Model A DC motor can be thought of as an electrical circuit whichalso contains an electromechanical componentmodel DCMotorResistor R(R 100);Inductor L(L 100);VsourceDC DC(f 10);Ground G;ElectroMechanicalElement EM(k 10,J 10, b 2);Inertia DCconnect(L.p, EM.n);connect(EM.p, nge);Gend DCMotor26Peter FritzsonCopyright Open Source Modelica ConsortiumEMloadpelab13

Corresponding DCMotor Model EquationsThe following equations are automatically derived from the Modelica model:(load component not included)Automatic transformation to ODE or DAE for simulation:27Peter FritzsonpelabCopyright Open Source Modelica ConsortiumModel Translation Process to HybridDAE to CodeModelicaGraphical EditorModelicaTextual EditorModelicaModelModelica ModelFrontendModelingEnvironmentModelicaSource codeTranslatorFlat model Hybrid DAE"Middle-end"AnalyzerSorted equationsOptimizerBackendOptimized sortedequationsCode generatorC CodeC CompilerExecutableSimulation28Peter FritzsonCopyright Open Source Modelica Consortiumpelab14

GTX Gas Turbine Power Cutoff MechanismHelloCourtesy of Siemens Industrial Turbomachinery AB29Peter FritzsonCopyright Open Source Modelica ConsortiumDevelopedby MathCorefor SiemenspelabModelica in Automotive Industry30Peter FritzsonCopyright Open Source Modelica Consortiumpelab15

Modelica in Avionics31Peter FritzsonCopyright Open Source Modelica ConsortiumpelabModelica in Biomechanics32Peter FritzsonCopyright Open Source Modelica Consortiumpelab16

Application of Modelica in Robotics ModelsReal-time Training Simulator for Flight, Driving Using Modelica modelsgenerating real-timecode Different simulationenvironments (e.g.Flight, Car Driving,Helicopter) Developed at DLRMunich, Germany Dymola Modelica toolCourtesy of Martin Otter, DLR,Oberphaffenhofen, Germany33Peter FritzsonCopyright Open Source Modelica ConsortiumpelabCombined-Cycle Power PlantPlant model – system level GT unit, ST unit, Drumboilers unit and HRSG units,connected by thermo-fluidports and by signal buses Low-temperature parts(condenser, feedwatersystem, LP circuits) arerepresented by trivialboundary conditions. GT model: simple lawrelating the electrical loadrequest with the exhaust gastemperature and flow rate.Courtesy Francesco Casella, Politecnico di Milano – Italyand Francesco Pretolani, CESI SpA - Italy34Peter FritzsonCopyright Open Source Modelica Consortiumpelab17

Combined-Cycle Power PlantSteam turbine unit Detailed model in orderto represent all the startup phasesBypass paths for boththe HP and IP turbinesallow to start up theboilers with idle turbines,dumping the steam tothe condenserHP and IP steamturbines are modelled,including inertia,electrical generator, andconnection to the gridCourtesy Francesco Casella, Politecnico diMilano – Italyand Francesco Pretolani, CESI SpA - Italy35Peter FritzsonCopyright Open Source Modelica ConsortiumpelabModelica Spacecraft Dynamics LibraryFormation flying on elliptical orbitsControl the relative motion of two or morespacecraftAttitude control for satellitesusing magnetic coils as actuatorsTorque generation mechanism:interaction between coils andgeomagnetic fieldCourtesy of Francesco Casella, Politecnico di Milano, Italy36Peter FritzsonCopyright Open Source Modelica Consortiumpelab18

Modelica –The Next GenerationModeling Language37Peter FritzsonCopyright Open Source Modelica ConsortiumpelabStored KnowledgeModel knowledge is stored in books and humanminds which computers cannot access“The change of motion is proportionalto the motive force impressed “– Newton38Peter FritzsonCopyright Open Source Modelica Consortiumpelab19

The Form – Equations Equations were used in the third millennium B.C. Equality sign was introduced by Robert Recorde in 1557Newton still wrote text (Principia, vol. 1, 1686)“The change of motion is proportional to the motive force impressed ”CSSL (1967) introduced a special form of “equation”:variable expressionv INTEG(F)/mProgramming languages usually do not allow equations!39Peter FritzsonCopyright Open Source Modelica ConsortiumpelabWhat is Modelica?A language for modeling of complex physical systems 40RoboticsAutomotiveAircraftsSatellitesPower plantsSystems biologyPeter FritzsonCopyright Open Source Modelica Consortiumpelab20

What is Modelica?A language for modeling of complex physical systemsPrimary designed for simulation, but there are also otherusages of models, e.g. optimization.41Peter FritzsonCopyright Open Source Modelica ConsortiumpelabWhat is Modelica?A language for modeling of complex cyber physical systemsi.e., Modelica is not a toolFree, open languagespecification:There exist several free and commercialtools, for example: OpenModelica from OSMC Dymola from Dassault systems Wolfram System Modeler from Wolfram SimulationX from ITI MapleSim from MapleSoft AMESIM from LMS Jmodelica.org from ModelonAvailable at: www.modelica.org MWORKS from Tongyang Sw & Control IDA Simulation Env, from EquaDeveloped and standardized CyDesign Modeling tool, CyDesign Labsby Modelica Association42Peter FritzsonCopyright Open Source Modelica Consortiumpelab21

Modelica – The Next Generation ModelingLanguageDeclarative languageEquations and mathematical functions allow acausal modeling,high level specification, increased correctnessMulti-domain modelingCombine electrical, mechanical, thermodynamic, hydraulic,biological, control, event, real-time, etc.Everything is a classStrongly typed object-oriented language with a general classconcept, Java & MATLAB-like syntaxVisual component programmingHierarchical system architecture capabilitiesEfficient, non-proprietaryEfficiency comparable to C; advanced equation compilation,e.g. 300 000 equations, 150 000 lines on standard PC43Peter FritzsonCopyright Open Source Modelica ConsortiumpelabModelica – The Next Generation ModelingLanguageHigh level languageMATLAB-style array operations; Functional style; iterators,constructors, object orientation, equations, etc.MATLAB similaritiesMATLAB-like array and scalar arithmetic, but strongly typed andefficiency comparable to C.Non-Proprietary Open Language Standard Both Open-Source and Commercial implementationsFlexible and powerful external function facility LAPACK interface effort started44Peter FritzsonCopyright Open Source Modelica Consortiumpelab22

Modelica Language Properties Declarative and Object-Oriented Equation-based; continuous and discrete equations Parallel process modeling of real-time applications,according to synchronous data flow principle Functions with algorithms without global side-effects(but local data updates allowed) Type system inspired by Abadi/Cardelli Everything is a class – Real, Integer, models,functions, packages, parameterized classes.45Peter FritzsonCopyright Open Source Modelica ConsortiumpelabObject OrientedMathematical Modeling with Modelica The static declarative structure of a mathematicalmodel is emphasized OO is primarily used as a structuring concept OO is not viewed as dynamic object creation andsending messages Dynamic model properties are expressed in adeclarative way through equations. Acausal classes supports better reuse of modelingand design knowledge than traditional classes46Peter FritzsonCopyright Open Source Modelica Consortiumpelab23

Modelica – Faster Development, LowerMaintenance than with Traditional ToolsBlock Diagram (e.g. Simulink, .) orProprietary Code (e.g. Ada, Fortran, C,.)vs ModelicaSystemsDefinitionModeling (manual derivation ofinput/output relations)Implementation SimulationProprietaryCodeBlock DiagramModelica47Peter FritzsonpelabCopyright Open Source Modelica ConsortiumModelica vs Simulink Block Oriented ModelingSimple Electrical ModelModelica:Physical model –easy to understandKeeps thephysicalstructureSimulink:Signal-flow model – hard tounderstandRes2ppR2R1 10sum3-11Ind1/Ll21sR2 100sum2pn 1n 1AC 220ppsinlnnsum1 1-1C 0.01Res11/R1Cap1/Cl11sL 0.1nnpG48Peter FritzsonCopyright Open Source Modelica Consortiumpelab24

Brief Modelica History First Modelica design group meeting in fall 1996 International group of people with expert knowledge in both languagedesign and physical modeling Industry and academia Modelica Versions 1.0 released September 19972.0 released March 20022.2 released March 20053.0 released September 20073.1 released May 20093.2 released March 20103.3 released May 2012 Modelica Association established 2000 in Linköping Open, non-profit organization49Peter FritzsonCopyright Open Source Modelica ConsortiumpelabModelica Conferences The 1st International Modelica conference October, 2000 The 2nd International Modelica conference March 18-19, 2002 The 3rd International Modelica conference November 5-6, 2003 inLinköping, Sweden The 4th International Modelica conference March 6-7, 2005 in Hamburg,Germany The 5th International Modelica conference September 4-5, 2006 in Vienna,Austria The 6th International Modelica conference March 3-4, 2008 in Bielefeld,Germany The 7th International Modelica conference Sept 21-22, 2009 in Como, Italy The 8th International Modelica conference March 20-22, 2011 in Dresden,Germany The 9th International Modelica conference Sept 3-5, 2012 in Munich,Germany50Peter FritzsonCopyright Open Source Modelica Consortiumpelab25

Exercises Part IHands-on graphical modeling(20 minutes)51Peter FritzsonCopyright Open Source Modelica ConsortiumpelabGraphical Modeling - Using Drag and Drop Composition52Peter FritzsonCopyright Open Source Modelica Consortiumpelab26

Exercises Part I – Basic Graphical Modeling (See instructions on next two pages)Start the OMEdit editor (part of OpenModelica)Draw the RLCircuitSimulateR1LR 10R 100L 1L 0.1ACThe RLCircuitSimulationG53Peter FritzsonCopyright Open Source Modelica ConsortiumpelabExercises Part I – OMEdit Instructions (Part I) Start OMEdit from the Program menu under OpenModelica Go to File menu and choose New, and then select Model. E.g. write RLCircuit as the model name. For more information on how to use OMEdit, go to Help and chooseUser Manual or press F1. Under the Modelica Library: Contains The standard Modelica library components The Modelica files contains the list of models youhave created.54Peter FritzsonCopyright Open Source Modelica Consortiumpelab27

Exercises Part I – OMEdit Instructions (Part II) For the RLCircuit model, browse the Modelica standard library and addthe following component models: Add Ground, Inductor and Resistor component models fromModelica.Electrical.Analog.Basic package. Add SineVolagte component model from Modelica.Electrical.Analog.Sourcespackage. Make the corresponding connections between the component modelsas shown in previous slide on the RLCiruit. Simulate the model Go to Simulation menu and choose simulate or click on the siumulate button in thetoolbar. Plot the instance variables 55Once the simulation is completed, a plot variables list will appear on the right side.Select the variable that you want to plot.Peter FritzsonCopyright Open Source Modelica Consortiumpelab28

Modelica Environments and OpenModelica1Peter FritzsonCopyright Open Source Modelica ConsortiumDymola 2Peter FritzsonDynasim (Dassault Systemes)SwedenFirst Modelica tool on the marketMain focus on automotiveindustrywww.dynasim.comCopyright Open Source Modelica Consortium1

Simulation X3Peter Fritzson ITIGermanyMechatronic systemswww.simulationx.com MaplesoftCanadaRecent Modelica tool on themarketIntegrated with Maplewww.maplesoft.comCopyright Open Source Modelica ConsortiumMapleSim 4Peter FritzsonCopyright Open Source Modelica Consortium2

Wolfram System Modeler – MathCore / Wolfram Research Wolfram ResearchUSA, SwedenGeneral purposeMathematica icaCourtesyWolframResearch5Car model graphical viewPeter FritzsonSimulation andanalysisCopyright Open Source Modelica ConsortiumThe OpenModelica Environmentwww.OpenModelica.org6Peter FritzsonCopyright Open Source Modelica Consortium3

OpenModelica (Part I) OpenModelicaOpen Source ModelicaConsortium (OSMC)Sweden and other countriesOpen sourcewww.openmodelica.org 7Peter FritzsonOMEdit, graphical editorOMOptim, optimization subsystemCopyright Open Source Modelica ConsortiumOpenModelica (Part II) Advanced Interactive Modelica compiler (OMC) Supports most of the Modelica Language Basic environment for creating models 8OMShell – an interactive command handlerOMNotebook – a literate programming notebookMDT – an advanced textual environment in EclipsePeter FritzsonCopyright Open Source Modelica Consortium ModelicaML UML Profile MetaModelica extension ParModelica extension Modelica & Python scripting84

OSMC – Open Source Modelica Consortium45 organizational members October 2012Founded Dec 4, 2007Open-source community services Website and Support ForumVersion-controlled source baseBug databaseDevelopment courseswww.openmodelica.orgCode Statistics9Peter FritzsonCopyright Open Source Modelica ConsortiumOSMC 45 Organizational Members, October 2012(initially 7 members, 2007)Companies and Institutes (24 members) Universities (21 members) 10ABB Corporate Research, SwedenBosch Rexroth AG, GermanySiemens PLM, California, USASiemens Turbo Machinery AB, SwedenCDAC Centre for Advanced Compu, Kerala, IndiaCreative Connections, Prague, Czech RepublicDHI, Aarhus, DenmarkEvonik, Dehli, IndiaEqua Simulation AB, SwedenFraunhofer FIRST, Berlin, GermanyFrontway AB, SwedenGamma Technology Inc, USAIFP, Paris, FranceInterCAX, Atlanta, USAISID Dentsu, Tokyo, JapanITI, Dresden, GermanyMathCore Engineering/ Wolfram, SwedenMaplesoft, CanadaTLK Thermo, GermanySozhou Tongyuan Software and Control, ChinaVI-grade, ItalyVTI, Linköping, SwedenVTT, FinlandXRG Simulation, GermanyPeter Fritzson TU Berlin, Inst. UEBB, GermanyFH Bielefeld, Bielefeld, GermanyTU Braunschweig, GermanyUniversity of Calabria, ItalyTU Dortmund, GermanyTU Dresden, GermanyGeorgia Institute of Technology, USAGhent University, BelgiumGriffith University, AustraliaTU Hamburg/Harburg GermanyKTH, Stockholm, SwedenUniversité Laval, CanadaLinköping University, SwedenUniv of Maryland, Syst Eng USAUniv of Maryland, CEEE, USAPolitecnico di Milano, ItalyEcoles des Mines, CEP, FranceMälardalen University, SwedenUniv Pisa, ItalyTelemark Univ College, NorwayUniversity of Ålesund, NorwlayCopyright Open Source Modelica Consortium5

OMNotebook Electronic Notebook with DrModelica Primarily for teachingInteractive electronic bookPlatform independentCommands: Shift-return (evaluates a cell) File Menu (open, close, etc.) Text Cursor (vertical), Cellcursor (horizontal) Cell types: text cells &executable code cells Copy, paste, group cells Copy, paste, group text Command Completion (shifttab)11Peter FritzsonCopyright Open Source Modelica ConsortiumOMnotebook Interactive Electronic NotebookHere Used for Teaching Control Theory12Peter FritzsonCopyright Open Source Modelica Consortium6

Interactive Session Handler – on dcmotor Example(Session handler called OMShell – OpenModelica Shell) simulate(dcmotor,startTime 0.0,stopTime 10.0) plot({load.w,load.phi})model dcmotorModelica.Electrical.Analog.Basic.Resistor r1(R 10);Modelica.Electrical.Analog.Basic.Inductor i1;Modelica.Electrical.Analog.Basic.EMF emf1;Modelica.Mechanics.Rotational.Inertia load;Modelica.Electrical.Analog.Basic.Ground ge g.p);connect(emf1.flange b,load.flange a);end dcmotor;13Peter FritzsonCopyright Open Source Modelica ConsortiumEvent Handling by OpenModelica – BouncingBall simulate(BouncingBall,stopTime 3.0); plot({h,flying});14Peter Fritzsonmodel BouncingBallparameter Real e 0.7 "coefficient of restitution";parameter Real g 9.81 "gravity acceleration";Real h(start 1) "height of ball";Real v "velocity of ball";Boolean flying(start true) "true, if ball is flying";Boolean impact;Real v new;equationimpact h 0.0;der(v) if flying then -g else 0;der(h) v;when {h 0.0 and v 0.0,impact} thenv new if edge(impact) then -e*pre(v) else 0;flying v new 0;reinit(v, v new);end when;end BouncingBall;Copyright Open Source Modelica Consortium7

Run Scripts in OpenModelica RunScript command interprets a .mos file .mos means MOdelica Script f

The tutorial gives an introduction to the Modelica language to people who are familiar with basic programming concepts. It gives a basic introduction to the concepts of modeling and simulation, as well as the basics of object-oriented component-based modeling for the novice, and an overview of modeling and .