Tuesday, October 8, 2024

Modelling With Modelica In OpenModelica

- Advertisement -

You are trying to rig up a simple circuit. A signal source, power supply and a few passive components are all you need. I am sure you would prefer simulating it first, to test and make sure you do not burn out the circuit. How about doing the same in an open source software environment? Let’s talk about OpenModelica (OM), a modelling and simulation environment intended for industrial and academic usage.

Based on GNU general-public licence version 3, OM offers a platform for modelling, compiling and simulating Modelica based models. Graphical editing is similar to MATLAB Simulink. OM is supported by the non-profit organisation Open Source Modelica Consortium.

The website for OM can be found at www.openmodelica.org. It offers support to Windows, MAC and Linux operating systems (OSes). If your OS has no pre-built binaries, or if you are unable to install the latest release, version 1.9.3, on your system, OM provides facilities to install the tool on a virtual machine (VM). Their website even provides a pre-built VM that contains all libraries and clients that come with OpenModelica. However, a virtualisation engine like VirtualBox will be needed to run the VM.

- Advertisement -
fig 1
Fig. 1: Modelling an RLC circuit

Simulate faster on multi-core systems
With the norm today being quad-core and octa-core, using the multi-core property of OM enables faster simulation of your model. When the feature is enabled, OM partitions the system of equations and assigns one core for every part, thus simultaneously processing using shared memory. While simulating, you can even turn various flags on or off to deliver results in a specific manner.

Re-simulating is also possible for manipulating variables in the model. By compiling to efficient Java Script, OM can also simulate in a Web browser on a client computer.An interactive shell to work with Modelica

‘The shell called OM Shell parses and interprets commands and expressions, and displays the results of the various processes performed. The environment allows you to load classes and even execute commands. You can also find simple history facilities, completion of file names and certain identifiers in commands, in the session handler.

Elements to help you create better models
There is a model widget for each class, keeping pace with the apps trend. With a status bar and a view area, navigation and display are hassle free. Components can be dragged and dropped into the icon view on the widget from the library. A system library, a standard library and a user library come to your aid. After enabling the connect mode, components can be linked to one another to create a complete model.

box 1

As you work with your model, there is always a need to cross-check or revisit certain sections of documentation or design. To help you with easy access to these, there are browsers for library, documentation, variables that can be used in your code and messages displayed, especially the ones citing errors.

Also, Welcome Perspective shows a list of recent files and latest news to help you create better models; you create your model in Modelling Perspective and you can view the results of simulation in Plotting Perspective tabs.

Edit your graphical models with ease
OM graphic connection editor called OMEdit makes the process of creating, browsing, editing and simulating models smooth. Usage of pre-defined models from standard libraries for creating your own user-defined models for use and component interfaces to interconnect components makes the design process simple.

Further, sub-systems for specifying simulation parameters like time, values and more, and a plotting interface to create plots from simulated models add glitter.

Generate outputs in varied formats
OM supports generation of output files in formats like mat, plt, csv and empty. The kind of output you require can be decided based on the type of data required, speed of simulation and size of the file. When using external scripts or tools like GNU plot to generate plots or process data, csv and plt formats come handy.

fig 2
Fig. 2: Parametric plot of Van der Pol simulation

Generating outputs in mat format will allow you to post-process the same in MATLAB or OCTAVE. You can even specify the variables that should be passed onto the output file.

Using commands, you can also obtain a mathematical representation of a model using an Extensible Markup Language (XML) representation or a MATLAB representation.

As always, graphs can be generated for quick and clear analysis, and these can be time or parametric plots. There is also a 3D visualisation library called Modelica3D.

Make the most of your Python skills
Calling external functions from C comes automatically with OM. Calling external Python Code from the same, and vice versa, is an added advantage. OM also provides a scripting interface for Python, called OMPython, and PySimulator, a Python package that provides simulation and post processing/analysis.

Analyse, debug and optimise
If the model being simulated has non-linear equation systems, it is useful to enable performance analysis while simulating, as the tool would then take into account execution times of user-defined functions as well as linear, non-linear and mixed-equation systems. A profiling test also comes in handy for analysis.

Fault-tolerance levels can be studied using Figaro extensions, to get a grip of static or dynamic reliability analysis. Debugging involves going through the transformations made and the algorithms processed.

To optimise the model under scrutiny, OM offers a few facilities. Built-in dynamic optimisation is provided using OM and IpOpt. CasADi framework can also be used for the same. For the case of a static optimisation, the classical Parameter Sweep Optimisation using OMOptim is recommended.

OM finds its way to IIT Bombay
As mathematical modelling and simulation is indispensable for progress in all engineering areas, it is no surprise that OM has found users at IIT Bombay. Prof. Kannan Moudgalya from the institution says that the open source electronics design automation software eSim, developed by FOSSEE group at IIT Bombay, is dependent on OMOptim for optimisation. Using this, one can solve problems such as finding the value of the resistor that will make the rise time less than 0.3 seconds.

box 2

A complete set of self-learning instructional material will be launched soon through the award-winning Spoken Tutorial methodology developed at IIT Bombay. Keep watching www.spoken-tutorial.org.

Peter Fritzson, director of Open Source Modelica Consortium, adds that the chemical engineering department at IIT Bombay is using OM for modelling and simulation. It is in the process of making chemical engineering building blocks and CAPE-OPEN thermodynamics available in the environment.

Learn as you model
OM has an electronic notebook sub-system, DrModelica tutoring sub-system and DrControl for teaching about control systems, together with Modelica. You can also import and export works between different Modelica tools or between certain non-Modelica tools.


Priya Ravindran is a technical journalist at EFY

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics