Switches between the first and third input port.
The Switch Block
Parameters:
Description:
The Switch block can be thought to direct either the first or the
third input port to its output port. The second input port takes
the decision which of the input ports is actually propagated: if
the value of the second input port is bigger than a given level,
the Switch propagates the first input port, otherwise the third
one.
Contrary to PowerDEVS, where this block is an atomic model,
ModelicaDEVS makes use of the fact that the DEVS formalism allows
for hierarchical models: by putting a multi-component model into
one of the predefined block hull templates it can be used as a
normal block for further models. The interior life of the Switch
block looks as shown in the following figure:
Let us have a look at the purpose of each of the internal blocks.
- The Constant block represents the level to which the second
port is compared. Note that since the level is set by the user by
means of a parameter (parameter Real level=0 "Switching level.";),
this value has to be passed to the Constant block which yields the
following declaration: Sources.Constant Constant1(v=level).
- The two Comparator blocks evaluate if the value of the second
input port is above or below the specified level. To this end, the
upper comparator emits an output value of 1 if the value of the
second port is bigger than the level and 0 otherwise. The lower
Comparator emits an output value of 1 if the value of the second
port is smaller or equal than the level and 0 otherwise. In other
terms, the Comparators declare which of the two switch input
signals (port 1 or port 3) to propagate to the output port: if for
instance, the upper comparator emits 0, the lower one by definition
emits 1 and vice-versa.
Note the settings of the output values of the Comparators:
Comparator1.vU = 1, Comparator1.vL = 0, Comparator2.vU = 0,
Comparator2.vL = 1.
- The Multiplier blocks receive the input of the first and the
third port, respectively, and a value of the Comparators that
determines whether the particular input signal has to be multiplied
by 0 or 1. If, for instance, the input of the second Switch port is
smaller or equal than the specified level, the upper Comparator
emits 0 and the lower one emits 1. Hence, the signal of the third
port would be forwarded since its value is multiplied by 1 whereas
the upper one is zeroed-out by multiplying its value by 0.
- The Add block merges the two outputs coming from the Multiplier
blocks (one of which is always zero and the other one carries the
value from one of the input ports of the Switch block).
The two pictures below illustrate the behaviour of a Switch
block.
The first picture shows the trajectory of the second input port (a
sine signal plotted in blue) and the switching level (red) given by
the parameter level. The crossing instants of the sine signal with
the switching level determines the time instants when the Switch
has to flip, thereby changing the source (port 1 or port 3) for its
output port.
The second picture shows the first input port (blue) that is simply
a constant value at v=3 and the third input port that is a sine
signal that starts only at time t=0.8. The output of the Switch
block is then plotted in red. It can be easily seen that when the
sine signal in the first picture is bigger than the switching
level, the output is constant at the value 3, and when the sine
signal drops below the switching level, the Switch output equals
the trajectory of the sine signal of the third input port.
Generated at 2026-04-14T18:18:34Z by OpenModelicaOpenModelica 1.26.3 using
GenerateDoc.mos