Modeling, Simulation, And Development Of Cyber- Physical Systems With .

Transcription

Modeling, Simulation, and Development of CyberPhysical Systems with OpenModelica and FMIPresentation at the USAModelica ConferenceOctober 10, 2018Adrian Popadrian.pop@liu.seTechnical Coordinator at the Open SourceModelica ConsortiumAdjunct Associate Professor at LinköpingUniversity

Main Goals for the OpenModelica Effort A comprehensive Open Source Modelica and FMImodeling, compilation, simulation and optimizationenvironment based on free software distributed inbinary and source code form for research, teaching,and industrial usage Support model-based development of cyberphysical systems, from requirements, to models, tosimulation and production code2

Industrial Challenges for Complex Cyber-PhysicalSystem Products of both Software and Hardware Increased Software Fraction Shorter Time-to-Market Higher demands on effectivestrategic decision making Cyber-Physical (CPS) – Cyber (software)Physical (hardware) products3

The OpenModelica Environmentwww.openmodelica.org

OpenModelica – Free Open Source ToolDeveloped by the Open Source Modelica Consortium (OSMC)5 Graphical editor Model compilerand simulator Debugger Performanceanalyzer Dynamic optimizer Symbolic modeling Parallelization ElectronicNotebook andOMWebbookfor teaching Spokentutorial forteachingEngineV6 11116equation model

OpenModelica Graphical Editor and Plotting6

Graphical Modeling with OpenModelica Environment7

The OpenModelica Open Source Environmentwww.openmodelica.org Advanced Interactive Modelica compiler (OMC) Supports most of the Modelica LanguageModelica and Python scripting Basic environment for creating models 8OMShell – an interactive command handlerOMNotebook – a literate programming notebookMDT – an advanced textual environment in Eclipsenew OMEdit graphic Editor OMDebugger for equations OMOptim optimization tool OM Dynamic optimizer collocation ModelicaML UML Profile MetaModelica extension ParModelica extension OMSimulator – FMI/TLM simulator8

The OpenModelica Tool eractive CompilerServerModelicaMLUML/Modelicaand iptingOMOptimOptimizationOMEdit Graphicand TextualModel EditorMDTEclipse isSimulationExecutionOMSimulatorFMI cripting

OSMC – International Consortium for Open SourceModel-based Development Tools, 53 members Febr 2018Founded Dec 4, 2007Open-source community services Website and Support ForumVersion-controlled source baseBug databaseDevelopment courseswww.openmodelica.orgCode StatisticsIndustrial members ABB AB, Sweden Berger IT-Cosmos, Germany Bosch Rexroth AG, Germany Brainheart Energy AB, Sweden CDAC Centre, Kerala, India Creative Connections, Prague DHI, Aarhus, Denmark Dynamica s.r.l., Cremona, Italy EDF, Paris, France Equa Simulation AB, Sweden Fraunhofer IWES, Bremerhaven INRIA, Rennes, France ISID Dentsu, Tokyo, JapanUniversity members FH Bielefeld, Bielefeld, Germany University of Bolivar, Colombia TU Braunschweig, Germany University of Calabria, Italy Univ California, Berkeley, USA Chalmers Univ, Control,Sweden Chalmers Univ, Machine, Sweden TU Darmstadt, Germany TU Delft, The Netherlands TU Dresden, Germany Université Laval, Canada Georgia Inst of Technology, USA Ghent University, Belgium Halmstad University, Sweden10 Maplesoft, Canada RTE France, Paris, France Saab AB, Linköping, Sweden Scilab Enterprises, France SKF, Göteborg, Sweden TLK Thermo, Germany Siemens Turbo, Sweden Sozhou Tongyuan, China Talent Swarm, Spain VTI, Linköping, Sweden VTT, Finland Wolfram MathCore, Sweden Heidelberg University, Germany TU Hamburg/Harburg Germany IIT Bombay, Mumbai, India KTH, Stockholm, Sweden Linköping University, Sweden Univ of Maryland, Syst Eng USA Univ of Maryland, CEEE, USA Politecnico di Milano, Italy Ecoles des Mines, CEP, France Mälardalen University, Sweden Univ Pisa, Italy Univ College SouthEast Norway Tsinghua Univ, Beijing, China Vanderbilt Univ, USA

Spoken-Tutorial step-by-step OpenModelica and ModelicaTutorial Using OMEdit. Link from www.openmodelica.orgNumber of students/teachers trained in their 0142,0152,016

OMNotebook Interactive Electronic NotebookHere Used for Teaching Control Theory12

OpenModelica MDT Eclipse Plug-in:Code Outline and Hovering InfoIdentifier Info onHoveringCode Outline for14easy navigation withinModelica files14

General Tool Interoperability & Model ExchangeFunctional Mock-up Interface (FMI)etc.Enginewith ECUGearboxwith ECUThermalsystemsAutomated Chassis components,cargo door roadway, ECU (e.g. ESP)functional mockup interface for model exchange and tool couplingcourtesy Daimler FMI development was started by ITEA2 MODELISAR project. FMI is aModelica Association Project now Version 1.0 FMI for Model Exchange (released Jan 26,2010) FMI for Co-Simulation (released Oct 12,2010) Version 2.0 FMI for Model Exchange and Co-Simulation (released July 25,2014) 100 tools supporting it (https://www.fmi-standard.org/tools)15

OpenModelica Functional Mockup Interface (FMI)16

OMSimulator Composite Model Editor with 3D ViewerCombine External (FMI) Models into New Models Composite model editorwith 3D visualization ofconnected mechanicalmodel components whichcan be FMUs, Modelicamodels, etc., or co-simulatedcomponents 3D animation possible Composite model saved asXML-file17

OMSimulator – Integrated FMI and TLM-basedCosimulator/Simulator in OpenModelicaC-APIinterfaceOMSimulatorIntegrated TLM & FMIlibOMSimulatorOMEditOMCTLM componentFMI componentFMI componentPapyrusADAMS wrapperScripting Beast wrapperSimulink wrapperFMI FMUModelica model18Composite FMIcomponent

OMSens – Sensitivity Analysis Subsystem ? Fill in Under development, prototype available19

OMPython – Python Scripting with OpenModelica 20Interpretation of Modelicacommands and expressionsInteractive Session handlingLibrary / ToolOptimized Parser resultsHelper functionsDeployable, Extensible andDistributable

OMJulia – Julia Scripting with OpenModelica 21Interpretation of Modelicacommands and expressions fromJulia, transfer of dataControl design using Julia controlpackage together withOpenModelicaInteractive Session handlingLibrary / ToolSeparately downloadable. be runwith OpenModelica 1.13.0 nightlybuildWorks with Jupyter notebooksSee separate presentationControl example with OMJulia in Jupyter notebooks

OMMatlab – Matlab Scripting with OpenModelica 22Interpretation of Modelicacommands and expressions fromMatlab, transfer of dataInteractive Session handlingLibrary / ToolSeparately downloadable. be runwith OpenModelica 1.13.0 nightlybuildNow (October 2018) basicversion supporting basicsimulation and plotting

Embedded System Support in OpenModelica Code generation of real-time Controllers from Modelicamodels for small foot-print platforms23

Use Case: SBHS (Single Board Heating System)Single board heating system (IITBombay)24 Use for teaching basic controltheory Usually controlled by serial port(set fan value, read temperature,etc) OpenModelica can generate codetargeting the ATmega16 on theboard (AVR-ISP programmer inthe lower left).Program size is 4090 bytesincluding LCD driver and PIDcontroller (out of 16 kB flashmemory available).Movie Demo!

Example – Code Generation to SHBS25

Code Generator Comparison, Full vs SimpleFull Source-code FMUtargeting 8-bit AVR procSimple code generatortargeting 8-bit AVR procHello World(0 equations)43 kB flash memory23 kB variables (RAM)130 B flash memory0 B variables (RAM)SBHS Board (real-time PIDcontroller, LCD, etc)68 kB flash memory25 kB variables (RAM)4090 B flash memory151 B variables (RAM)The largest 8-bit AVR processor MCUs (Micro Controller Units) have 16 kB SRAM.One of the more (ATmega328p; Arduino Uno) has 2 kB SRAM.The ATmega16 we target has 1 kB SRAM available (stack, heap, and global variables)26

Communication & I/O Devices:M ODELICA D EVICE D RIVERS Library Free library for interfacing hardware drivers Cross-platform (Windows and Linux) UDP, SharedMemory, CAN, Keyboard,Joystick/Gamepad DAQ cards for digital and analog IO (onlyLinux) Developed for interactive realtime simulations27

OMEdit 3D Visualization of Multi-Body Systems Built-in feature of OMEdit toanimate MSL-Multi-Bodyshapes Visualization of simulationresults Animation of geometricprimitives and CAD-FilesSimulatewithAnimationNewAnimationWindow28

OpenModelica 3D Animation Demo29

ProblemsSolved problemsOMOptim – Parameter Sweep Design OptimizationResult plotExport result data .csvHereParetofrontoptimization30

Optimization of Dynamic Trajectories UsingMultiple-Shooting and Collocation Minimize a goal function subject to modelequation constraints, useful e.g. for NMPC Multiple Shooting/Collocation In OpenModelica 1.9.1beta release Jan 2014.Solve sub-problem in each sub-intervalExample speedup, 16 cores:MULTIPLE COLLOCATION16.014.012.010.08.06.04.02.00.012ipopt [scaled]3148jac g [scaled]16

OpenModelica Dynamic Optimization Collocation32

OpenModelica Model ParallelizationFaster Simulation on Multi-CoreAutomated parallelization of modelsParallelizing numeric Jacobiancomputations in simulationSpeedup ScalableTestSuiteN 39 nnz 818Sp 54.543.532.521.510.50123Speedup about 4using 8 threads33468number ofthreads101214

Large-scale ABB OpenModelica ApplicationGenerate code for controlling 7.5 to 10% of German Power ProductionABB OPTIMAX PowerFit Real-time optimizing control of largescale virtual power plant for systemintegration Software including OpenModelica nowused in managing more than 2500renewable plants, total up to 1.5 GWHigh scalability supporting growth 2012: initial delivery (for 50 plants) 2013: SW extension (500 plants) 2014: HW SW extension ( 2000) 2015: HW SW extension,incl. OpenModelica generating optimizingcontroller code in FMI 2.0 formManage 7.5% - 10% of German Power 342015, Aug: OpenModelica Exports FMUsfor real-time optimizing control (seconds)of about 5.000 MW (7.5%) of power inGermany

Need for Debugging ToolsMap Low vs High Abstraction Level A major part of the total cost of software projectsis due to testing and debugging US-Study 2002:Software errors cost the US economy annually 60 Billion Problem: Large Gap in Abstraction Levelfrom Equations to Executable Code Example error message (hard to understand)Error solving nonlinear system 132time 0.002residual[0] 0.288956x[0] 1.105149residual[1] 17.000400x[1] 1.248448.35

Integrated Static-DynamicOpenModelica Equation Model wingequationtransformationsof amodel:Mapping dynamic run-time error to source model position36

Transformations Browser – EngineV6 Overview(11 116 equations in model)37

Performance Profiling(Here: Profiling all equations in MSL 3.2.1 DoublePendulum)38

Equation Model Debugger on Siemens Model(Siemens Evaporator test model, 1100 equations)Pointing out the buggy equationy u1/u2;that gives division by zero39

Performance Profiling for faster Simulation(Here: Profiling equations of Siemens Drum boiler model with evaporator Measuring performance of equation blocks to find bottlenecks Useful as input before model simplification for real-time applicationsIntegrated with the debugger to point out the slow equationsSuitable for real-time profiling (collect less information), or a completeview of all equation blocks and function callsConclusion from the evaluation:“ the profiler makes the processof performance optimizationradically shorter.”40

OpenModelica – ModelicaML UML ProfileBased on Open-Source Papyrus UML and OpenModelica ModelicaML is a UML Profile for SW/HW modeling Applicable to “pure” UML or to other UML profiles, e.g. SysML Standardized Mapping UML/SysML to Modelica Defines transformation/mapping for executable models Being standardized by OMG ModelicaML Defines graphical concrete syntax (graphical notation for diagram) forrepresenting Modelica constructs integrated with UML Includes graphical formalisms (e.g. State Machines, Activities,Requirements) Which do not yet exist in Modelica language (extension work ongoing) Which are translated into executable Modelica code Is defined towards generation of executable Modelica code Current implementation based on the Papyrus UML tool OpenModelica41

Example: Simulation and Requirements EvaluationReq. 001 is instantiated 2 times(there are 2 tanks in the system)tank-height is 0.6mReq. 001 for the tank2 isviolatedReq. 001 for the tank1 isnot violated42

vVDR Method –virtual Verification of Designs vs Monitor ModelsFormalizeRequirementsRMMFormalize fication ModelsCreate Verification*DesignsAlternativeModelsModelsExecute andCreate ReportAnalyze Results43Created ArtifactReportsGoal: Enable on-demandverification of designsagainst requirementsusing automated modelcomposition at any timeduring development.

Outlook:New OpenModelica Frontend for Large-Scale models Soon: New OMCCompiler frontend for fastcompilation and largescale models Been under developmentthe past 2-3 years Now (Oct 05) simulates69% of MSL models,coverage increases about6% per month About 10-200 times fasterthan the old frontend,depending on model44

OpenModelica DAEMode for Large-Scale models Goal – to handle hundreds of thousands to millions ofequations Introduced sparse solvers in the solution chain: KLU for linear algebraic equations, Kinsol for nonlinear algebraic equations, and IDA for sparse differential-algebraic equations. DAEmode: after index reduction, IDA solves the differentialequations and the algebraic loops simultaneously Largest system so far: electro-mechanical power systemmodel with about 600.000 differential-algebraic equations Under development for even larger systems45

Summary and QuestionsMulti-DomainModelingVisual AcausalComponentModelingwww.modelica.org – Language, Standard Librarywww.openmodelica.org – Open Source ToolTypedDeclarativeTextual Language46Thanks for listening!Modelica is a registered trademark of the Modelica AssociationHybridModeling

representing Modelica constructs integrated with UML Includes graphical formalisms (e.g. State Machines, Activities, Requirements) Which do not yet exist in Modelica language (extension work ongoing) Which are translated into executable Modelica code Is defined towards generation of executable Modelica code