AmesimKnowledge

Advanced Modelica language topics

Programming events

Event sources

In Modelica, an event corresponds to a perceptible change in a discrete quantity triggered by the evolution of a non-discrete real signal. This means that discrete expressions involving non-discrete sub-expressions in a model will result in events being triggered during the simulation of the model when the values of the continuous sub-expressions vary sufficiently to change the result of the evaluation of at least one of the discrete expressions1.

For instance, an expression such as time >= 5.0 is an event generating expression as it is a discrete Boolean expression that can change when the non-discrete signal time changes. In other words, an event will be triggered when the value of the expression time – 5.0 crosses zero, which is why event generating expressions are also called zero-crossing expressions zero-crossing expressions . It is important to note that a numerical hysteresis effect is added automatically by Simcenter Amesim when evaluating zero-crossing expressions to reduce "chattering" effects in a model. Besides, the value of an event generating discrete expression changes right after an event associated with it has been processed. That means that zero-crossing expressions introduce delays in a model.

Running a model that triggers events does not require any particular intervention from the user. The Modelica compiler automatically handles event-triggering expressions by generating the appropriate code to detect events and process them.

Event iteration

When an event occurs, changes in discrete signals can occur right after the event has been processed, i.e., without increasing the value of time. This means that there can be several distinct ordered "instants" for the same value of time during the simulation of a Modelica model. Those instants will be referred to as logical events in this document. A logical event can either be triggered by a zero-crossing or by the future change of a discrete quantity through the use of the "pre" value of a variable corresponding to its value at the last logical event. All logical events have to be processed before time can increase again. This process is known as event iteration in Modelica.

Continuous state re-initializations

state events

Modelica provides the necessary constructs to declare state changes using when clauses when clauses and the reinit operator reinit operator .

Figure 45: Definition of a model class containing continuous state reinitialization

To illustrate continuous state reinitialization, we will build a model class using a slightly modified version of the Inductor model called LimitedCurrentInductor (see the figure above). Below, we show an example of use of our modified version of inductor model class.

Figure 46: Definition of a model class using a submodel class that triggers events

The evolution of the current flowing in the inductor (for time in the [0, 0.1] range) of the model defined in the figure above is shown in the figure below.

When re-initializing a variable in a "reinit" equation, the old value of that variable may be necessary to compute the new value. This is possible in Modelica as a "reinit" equation is only applied after the associated event occurs, such that a model like the one shown in the figure Figure 48 does not involve an algebraic loop.

The figure Figure 49 shows an example of electrical circuit (a simple RC with a voltage source) using the new model class. The voltage of the capacitor is reinitialized with respect to the value before initialization.

Figure 47: Evolution of the current of an inductor with re-initialization of its state variable such that the value lies between -0.2 and 0.2

Figure 48: Definition of a model class involving the reinitialization of a continuous state variable using its past value

Figure 49: Evolution of the current of a capacitor within the time frame [0, 10] with re-initialization of its state variable at t = 5 s (the voltage drop is computed with respect to the old value of the voltage)

1

It should be noted that any sub-expression embedded in a

noEvent

expression is considered non-discrete.

Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Modelica_Platform/xid1179684 · retrieved 2026-07-17