Models of physical systems with state logic and time based discontinuities can often produce events in Dymola. These events can have a significant impact on your simulation performance, so it is important that we understand where these events are coming from in the model. In this blog post I’m going to tell you about the tool available in Dymola to help investigate the events in our models.
What are Events?
Events are used to deal with discontinuous variables. Discontinuities may be introduced by the conditions in if and when statements, or by inbuilt functions like ceil, floor, div, mod, rem and integer.
There are two kinds of events; time and state. For a time event, like that generated by the condition y = time > 1, the exact instant the event occurs is known in advance. For state events, like that generated by y = u>0.5, Dymola follows an iteration process to determine the exact value that triggers the event and when this happens. The iteration process for state events can make your model slow to simulate. This reduction of simulation performance is particularly critical if your model needs to run in real-time, for a driver or hardware-in-the-loop application for instance.
This makes it important that we can investigate what events are present in our models and which expressions are generating the events. The Dymola 2018 FD01 release introduced enhanced event logging features that make it easy to see the events occurring in our models.
Enabling Event Logging
Event logging in Dymola is enabled in the Simulation Setup debugging options, as highlighted in Figure 1. Open this window from Simulation > Setup… in the Dymola menus.
Figure 1 – Event logging options in the Dymola Simulation Setup
To illustrate event logging, I will use the Coupled Clutches demo from the Modelica Standard library (File > Demos > Coupled Clutches). As Figure 2 shows, this model includes clutch components which introduce state events because of the if statement used to define their frictional torque behaviour.
Figure 2 – Coupled Clutches demo
When event logging is enabled, you can see the event log generated by right-clicking on the simulation results in the Variable Browser and selecting Analyze Numerics. This opens the Simulation Analysis window, which includes the Event Log tab shown in Figure 3.
Figure 3 – Event Log for the Coupled Clutches demo
Because I enabled event logging during initialisation, the first entry in the Event Log contains events occurring at initialisation of the model. The events during the simulation are then listed in time order. Multiple events may occur at the same time point, as one event may trigger others.
Selecting the Plot Event Overview button opens a graphical representation of the Event Log, like that seen in Figure 4 below. It shows the number of events at each event iteration plotted against time, with the marker shape identifying the type of event that triggered the event iteration.
Figure 4 – Event Overview plot for the Coupled Clutches demo
Investigating Individual Events
You can expand each time point of the Event Log to see the individual events related to that event iteration. This shows the conditional expressions that triggered the event and its values after the event. The Event Log of the Coupled Clutches models is shown in Figure 5, with the event iterations at 0.4s and 0.831167s expanded. The most frequent events are highlighted in red.
Figure 5 – Individual event shown in the expanded Events Log for the Coupled Clutches demo
There are a number of ways to search the Event Log:
- Double clicking an individual event will highlight all the occurrences of that conditional expression in yellow.
- Alternatively, selecting the Expand Event button will highlight all occurrences of the selected conditional expression in yellow and expand all the event iterations where it is present.
- You can also highlight an event by typing the conditional expression into the filter field at the top of the Event Log.
Highlighting is shown in both the Event Log window and any event plots open. To remove the highlighting, the filter must be cleared using the cross button on the right of the filter field.
Right-clicking on an individual event brings up a context menu with more options. You can plot the expression values or iteration numbers when its value changed for all instances of the selected event in the active plot window. Figure 6 is the plot of the values and iteration numbers against time of the conditional expression clutch2.locked.
Figure 6 – Context menu for an individual event used to plot the event values and iteration numbers against time
So the next time you are struggling with a model producing events, try out these event logging features in Dymola to identify what exactly is causing the events.
Written by: Hannah Hammond-Scott – Senior Engineer
Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion.