Create a Hybrid Model with Time-Based and Event-Based Components - MATLAB & Simulink (original) (raw)

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

Tank filling model with 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.

Tank filling model with a Selection Gate subsystem.

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

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

Entity Generator | Entity Queue | Entity Server

Topics