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.
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.
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 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
startFillingSimulink 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.
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
Capacityattribute. 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
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.
Simulate the Hybrid Model
Run the Modeling Hybrid Systems - Tank Filling example. In the first scope, observe the fill 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.
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.
Entity Generator | Entity Queue | Entity Server