Main Content

Create a Hybrid Model with Time-Based and Event-Based Components

The example Modeling Hybrid Systems - Tank Filling shows tanks queuing up to be filled. In the example, SimEvents® component models event-based behavior while the Simulink® component models time-based dynamics.

Tank filling model with SimEvents and Simulink components

Communication between SimEvents and Simulink components

Without the Selection Gate block and Simulink Function blocks, the flow of tanks in Discrete-Event Process follows their generation, queuing, service, and termination. For more information about building the SimEvents component of the model, see Create a Discrete-Event Model. To learn more about writing event actions for the same model, see Manage Entities Using Event Actions.

Tank filling model displayed as two simple queue-server models

The Pump -Tank model is the Simulink component that represents the time-driven tank filling process. When a tank is full, it generates a SimEvents message through the Hit Crossing block and the message follows a similar flow of generation, queuing, service, and termination. The badge Right arrow symbol pointing to capital letter E denotes the transition between time-based and event-based behavior.

The arrival of a tank at the Entity Server block triggers the filling process in Pump-Tank model. When a tank is full, Hit Crossing block labeled Tank Full generates a message. Arrival of this message at the Processor in Interface component triggers the Simulink Function block to release the Selection Gate for the full tank's departure.

Next, SimEvents and Simulink components of the model are presented in detail.

SimEvents Part of Model

The SimEvents part models the flow of tanks.

  • The Entity Generator block generates the tanks.

  • The Entity Queue block queues each tank in first-in-first-out (FIFO) mode.

  • The Entity Server block calls the startFilling Simulink function to fill each tank. Several tanks can be served at the same time.

  • The Entity Server block in the Interface processes the SimEvents message generated by the Hit Crossing block and calls the Simulink function to enable the Selection Gate subsystem for a specific tank. The block also calls the Simulink function to reinitialize the Integrator block for the next fill.

Tank filling model with a Selection Gate subsystem.

Simulink Part of Model

The Simulink part models the time-driven process of filling tanks.

  • This component contains the logic to fill the tanks.

  • Each tank has a Capacity attribute. The continuous time part models the process of filling up a tank, modeled by the Integrator block. When a tank is filled to its capacity, the Selection Gate subsystem releases the tank and the tank departs.

  • This component also contains the Simulink function startFilling.

  • The Hit Crossing block detects the completion of the tank filling process and sends a SimEvents message regarding this event. This message is processed in the Interface, which triggers the release of the tank by the Selection Gate and the reinitialization of the Integrator block for the next fill.

Pump-Tank model section if the tank-filling model which includes a Simulink Function block, an integrator and a sensor

Simulate the Hybrid Model

Run the Modeling Hybrid Systems - Tank Filling example. In the first scope, observe the fill process for each pump.

Scope block that displays the filling process for each pump.

In the second scope, observe the number of trucks leaving after being filled. The plot displays that there are 15 trucks leaving the facility after their gas tanks were filled.

Scope block that displays the trucks departing the facility after their tanks are full

Event-Based and Time-Based Dynamics in the Simulation

In the Modeling Hybrid Systems - Tank Filling example, the time-based dynamics of the tank fill coexist with the event-based dynamics of the tank flow system. When you run the simulation, the solver and the event calendar both play a role. Upon major time steps of the solver, the simulation solves the ordinary differential equations that represent the dynamics of the tank fill system. Solving the event-based dynamics entails scheduling and processing events, such as service completion and entity generation, on the SimEvents event calendar. Because the model uses a variable-step solver, when events occur in the discrete-event system, the solver has a major time step.

To learn more about solvers, see Solvers for Discrete-Event Systems. To learn more about creating event-based and time-based models, see Working with SimEvents and Simulink.

See Also

| |

Related Topics