Main Content

Model Synchronous Subsystems by Using Parallel Decomposition

To implement operating modes that run concurrently, use parallel states in your Stateflow® chart. For example, as part of a complex system design, you can employ parallel states to model independent components or subsystems that are active simultaneously.

State Decomposition

The decomposition type of a chart or state specifies whether the chart or state contains exclusive states or parallel states:

  • Exclusive states represent mutually exclusive modes of operation. No two exclusive states at the same hierarchical level can be active or execute at the same time. Stateflow charts represent each exclusive state by a solid rectangle.

  • Parallel states represent independent modes of operation. Two or more parallel states can be active at the same time, although they execute in a serial fashion. Stateflow charts represent each parallel state by a dashed rectangle with a number that indicate the execution order.

You can combine exclusive and parallel states in your Stateflow chart by setting the state decomposition at different levels of your state hierarchy. The default state decomposition type is Exclusive (OR). To change the decomposition type to AND (Parallel), right-click the parent state and select Decomposition > AND (Parallel).

Model an Air Temperature Controller

This example uses parallel decomposition to model an air controller that maintains air temperature at 120 degrees in a physical plant.

At the top level, the air controller chart has two exclusive states, PowerOff and PowerOn. The chart uses exclusive (OR) decomposition because controller cannot be on and off at the same time.

The controller operates two fans. The first fan turns on when the air temperature rises above 120 degrees. The second fan provides additional cooling when the air temperature rises above 150 degrees. The chart models these fans as parallel substates, FAN1 and FAN2, of the top-level state PowerOn. Because the fans operate as independent components that turn on or off depending on how much cooling is required, PowerOn uses parallel (AND) decomposition to ensure that both substates are active when the controller is turned on.

Except for the operating thresholds, the fans are modeled by states with an identical configuration of substates and transitions that reflects the two modes of fan operation, On and Off. Because neither fan can be on and off at the same time, FAN1 and FAN2 have exclusive (OR) decomposition.

In PowerOn, a third parallel state called SpeedValue represents an independent subsystem that calculates the number of fans that have cycled on at each time step. The Boolean expression in(FAN1.On) has a value of 1 when the On state of FAN1 is active. Otherwise, in(FAN1.On) equals 0. Similarly, the value of in(FAN2.On) represents whether FAN2 has cycled on or off. The sum of these expressions indicates the number of fans that are turned on during each time step.

Specify Order of Execution for Parallel States

Although FAN1, FAN2, and SpeedValue are active concurrently, these states execute in serial fashion during simulation. The numbers in the upper-right corners of the states specify the order of execution. The rationale for this order of execution is:

  • FAN1 executes first because it cycles on at a lower temperature than FAN2. It can turn on regardless of whether FAN2 is on or off.

  • FAN2 executes second because it cycles on at a higher temperature than FAN1. It can turn on only if FAN1 is already on.

  • SpeedValue executes last so it can observe the most up-to-date status of FAN1 and FAN2.

By default, Stateflow assigns the execution order of parallel states based on the order you add them to the chart. To change the execution order of a parallel state, right-click the state and select a value from the Execution Order drop-down list.

Explore the Example

This example contains a Stateflow chart called Air Controller and a Simulink® subsystem called Physical Plant.

Based on the air temperature of the physical plant, the chart turns on the fans and outputs the number of running fans, airflow, to the subsystem. This value determines the cooling activity factor, $k_{\mathrm Cool}$, according to these rules:

  • airflow = 0 — No fans are running. The air temperature does not decrease because $k_{\mathrm{Cool}} = 0$.

  • airflow = 1 — One fan is running. The air temperature decreases according to the cooling activity factor $k_{\mathrm{Cool}} = 0.05$.

  • airflow = 2 — Two fans are running. The air temperature decreases according to the cooling activity factor $k_{\mathrm{Cool}} = 0.1$.

The Physical Plant subsystem updates the air temperature, $temp$, inside the plant based on the equations

$$temp(0) = T_{\mathrm{Initial}}$$

$$temp'(t) = (T_{\mathrm{Ambient}}-temp(t)) \cdot (k_{\mathrm{Heat}}-k_{\mathrm{Cool}}),$$


  • $T_{\mathrm{Initial}}$ is the initial temperature. The default value is 70°.

  • $T_{\mathrm{Ambient}}$ is the ambient temperature. The default value is 160°.

  • $k_{\mathrm{Heat}}$ is the heat transfer factor for the plant. The default value is 0.01.

  • $k_{\mathrm{Cool}}$ is the cooling activity factor that corresponds to airflow.

The new temperature determines the amount of cooling at the next time step of the simulation.

Related Topics