Prev Next

Humidifier Example

For this example we walk through the creation of a SysPhS model of a room humidifier to illustrate the use of signal flows and StateMachines. The signals in this example reflect physical quantities, but differ from the physical interaction in the sense of physical substances with flow rates and potentials.

The complete humidifier example is a complex set of SysML models, but it contains a section that requires the use of MATLAB's Stateflow for simulation. We will use this section of the example to work through the use of the SysML StateMachine and view how this is configured and run in MATLAB using Stateflow, as well as in Modelica.


Running this simulation requires either:

  • OpenModelica or
  • MATLAB's Simulink and StateFlow


The complete simulation example is available in the WebEA model. See the links under Learn More at the end of this topic.

The SysML StateMachine diagram is:

For MATLAB the Stateflow diagram generated consists of:

For Modelica the generated diagram looks like this:

Create SysML StateMachine Model

This table shows how we can build the SysML StateMachine model to represent the switching states.

Note: The full SysML StateMachine features are only partially supported in MATLAB's Stateflow and Modelica. Therefore, in order to create State diagrams for simulation in these products, it is necessary for the connector-types and object-types used in Enterprise Architect's StateMachine model to only contain the corresponding features supported in Stateflow and Modelica.




In SysML, using SysPhS, the core humidifier components are represented by Blocks. For this example, where we are creating a StateMachine simulation, the focus is on the 'Control' Block. The Block Definition diagram (BDD) called 'Humidifier Components', which includes the 'Control' Block, is only one in a list of BDDs defining the humidifier.

The 'Control' Block has the StateMachine 'ControlStateMachine' as a Composite diagram under it; this is illustrated in the first diagram in the Overview section at the start of this topic.

The 'Control' Block is where Ports and a PhS constant for the humidifier control are defined. The Ports are of type RealInSignal, which are signal flows.

Common Types

As a starter for all SysPhS models, you need to ensure that the SysPhS common types are loaded in the repository, and referenced in the new model using the Package 'Import' connector. For more information see the Referencing SysPhS Libraries Help topic.

Phs Ports

The Value Types used for the Ports are pre-defined in the SysPhS Simulation Libraries. The key type used is the RealInSignal ValueType (RealInSignalElement). This can be dragged onto the Block as a Port and then renamed.

As an example of setting a Port on the Block, in this case the fanPowerOut Port, you drag a RealInSignalElement onto the Block and define it as a Port.


  • These Ports can be set to both Modelica and Simulink by adding the stereotype for the other Port-type

Creating the StateMachine

To define a StateMachine as a Composite child-diagram to the Block:

  • Select 'New Child Diagram > StateMachine' from the context menu on the Block, then
  • Select 'New Child Diagram > Select Composite' from the context menu on the Block, and then select the diagram just created

Creating the States and Transitions

In the child StateMachine diagram, you add the Initial element, four States and a Final element. Then name these appropriately.

Note: By pressing the Spacebar when the diagram is selected, you can select an Initial object from the context menu, and then use the Quicklinker to add the remaining objects.

Transition Guards

The Transitions between the States contain conditions in their Guards. These conditions are defined in the Properties window 'Constraints' tab.

The variables used are the 'Control' Block's Phs constant and Ports. See the image in the earlier Blocks row.


Each State contains a script defining the mode and status of the fan. These scripts are set in the 'Entry' operation.

To edit the script for this, select the root StateMachine and pressing Alt+7.

Configure Simulation Behavior

This table shows the detailed steps in the configuration of SysMLSim.



Create a SysMLSimConfiguration Artifact

  • Open the Block Definition diagram
  • Click on the open space in the diagram
  • Press the Spacebar
  • From the 'Artifacts' sub-menu, select 'SysMLSim Configuration'
    This creates a new SysMLSim Configuration Artifact

Set the Package

  • Double-click on the SysMLSim Configuration Artifact
    This opens the Configure SysML Simulation window
  • In the 'Package' field, click on the [...] button and select the Package containing the SysML diagram

Set Modelica or Simulink

In the top drop-down, select which simulation tool to use:

  • Modelica
  • Simulink

For more details on these settings, see the Configure SysML Simulation Help topic.

Set the Block to Simulate

  • In the left-hand list, under 'Block' in the 'Name' column, find 'HumidifierSystem'
  • In the 'Value' column, click on the drop-down arrow and select 'SysMLSimModel'

Select Properties to Plot

You can now select the properties to be plotted:

  • In the right-hand pane, select the Ports to plot

Run Simulation

In the 'Simulation' page, click on the Solve button. This shows an example of the plot generated in:



Note: The output in Simulink looks different due to the default precision for Simulink models not being sufficient for this specific example. Simulink settings can be modified by opening the generated file directly in Simulink.

View the Model in Modelica or Simulink

To view the generated model in the external applications, Modelica or Simulink, see the View the Model in Modelica or Simulink Help topic, which includes tips for debugging any issues in the generated code.

Learn More