Welcome to the first chapter of our Modelica series. Modelica is one of the leading technologies used for System Simulation and provides many benefits in the design, optimization, and operation of products and processes. The purpose of this series is to introduce Modelica to new users and give you an idea of how it can support your innovation processes.

In this first chapter, you'll learn how to use and simulate models from the Modelica Standard Library.

Let's get started!

What is Modelica?

Imagine that you're having lunch with one of your colleagues. While eating, you discuss some issue you're having with one of the products you're developing. To better describe the problem, you start making a rough sketch on the back of a napkin. With the help of this sketch, your colleague soon understands what issue you're facing. But still, you fail to wrap your heads around a solution. What's going on inside your system is simply too hard to understand by just looking at a sketch.

With Modelica, you can bring your napkin sketch to life. Its graphical interface resembles the system layout in the same way as your sketch, making it easy to understand for anyone. And, its inside mimics the dynamic behavior of the system, making it straightforward to replicate issues and find solutions.

The Modelica language is an open, equation-based, and object-oriented modeling language for systems modeling. Its multi-domain capabilities make it possible to capture the dynamic behavior of any physical domain, and its open nature offers great flexibility and scalability. Models are represented both graphically and in code and are easy to adapt to fit specific needs.

Now you know a bit more about the Modelica language. But how is it used?

Getting started

The first thing you need before you can start utilizing the power of Modelica is a Modelica tool. The Modelica tool is where you build your Modelica models, simulate them and analyze their results. There is a large variety of tools available from different vendors, both open source and commercial.

You are more than welcome to contact us if you need our help to find a Modelica tool that fits your specific needs.

The Modelica Standard Library

Once you have a Modelica tool in place, you're ready to start modeling. The Modelica Standard Library is a great starting point for that process. It is freely available and installed by default with most Modelica editors.

The library contains ready-made base components for a wide range of applications. It includes component packages for any physical domain, including Electrical, Magnetics, Mechanics, Fluid, Media, and Thermal.

In addition, you can find StateGraphs, Math functions, utilities, input/output blocks, and a large number of examples in the library. All models in the library are well-proven and ready to be used for your projects.

Now, let's start simulating.

Overview Modelica Standard Library

A first example - Simulating a pendulum

In this first example, we'll consider a simple pendulum model from the Modelica Standard Library: Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum. The model consists of a world component, a revolute joint, a damper, and a body. The system was originally built by dragging and dropping these component models from the Modelica Standard Library. The connections between the components are acausal and describe actual physical couplings. The purpose of the world component is to define the coordinate system and gravity field.

Diagram view of the pendulum model from Modelica Standard Library
Diagram view of the pendulum model from the Modelica Standard Library

Take a look around. You're now, most likely, in the graphical view of your Modelica editor. This view is used for building models graphically. If you switch to the Text view, you'll find the underlying Modelica code of the pendulum model. This view is used when writing equations and algorithms.

Text view of the pendulum model from Modelica Standard Library
Text view of the pendulum model from the Modelica Standard Library

There is also an Icon view in the editor that displays the icon of the component and an Info view that shows its documentation.

Now that you know the environment, you're ready to perform your first simulation. Press the simulation button in your Modelica tool to start the simulation. By default, this pendulum model simulates 5 seconds. You can always change this stop time in the Simulation setup if you wish to simulate a longer or shorter period.

Plot of the swing angle of the pendulum
Plot of the swing angle of the pendulum

You should now see some results. Find and plot the variable "rev.angle" in the results browser to see the swing angle of the pendulum. In addition to the regular plots, the pendulum model also has support for 3D animation. Given that your Modelica tool supports this feature, you can animate and replay the behavior of the pendulum as it swings.

Animation of the pendulum
3D animation of the pendulum as it swings

We can now use this model for parameter studies to see what happens if we change the length or mass of the pendulum. This is easily done by changing these parameter values in the parameter dialog of the body component. You access the parameter dialog from the Diagram view of your tool by double-clicking the component. Note that you may have to duplicate the pendulum model and store it outside of the Modelica Standard Library before you can edit parameter values in some Modelica environments. Change the parameters, re-run the simulation and evaluate the results.

Comparison of a pendulum of length/mass 0,5 m/1 kg and 1 m/2 kg
Swing angle comparison of pendulums with length/mass 0.5m/1kg and 1m/2kg

We've now simulated our very first Modelica model. In the coming chapters of our Modelica series, we'll talk more about Modelica, how it works, interfaces, and applications. Check out the next chapter now!

Please feel free to contact us if you have any questions or if you want to schedule a call or training session. Check out our System Simulation page for more information about what we can offer in System Simulation.

 

to get News and Blog updates!