This paper presents πHyFlow, a modular approach to the process interaction worldview (PI). Traditionally, PI supports a set of interacting processes without enabling modular and hierarchical model definition. πHyFlow basic models define a dynamic set of processes while also enabling a modular interface for supporting model composition. πHyFlow allows an exact representation of continuous signals based on the concepts of dense outputs, and generalized sampling. πHyFlow ability to support accurate models of hybrid systems is presented through a DC-DC converter (DCC) based on a resistor–capacitor (RC) electrical circuit. The DCC output voltage can be modeled by a first-order differential equation that is solved using an exponential time differencing (ETD) integrator. The DCC network model uses a digital on-off controller and an ETD. Simulation results are generated by πHyFlow++, a C++ implementation of the formalism.
The process interaction worldview (PI) provides a simple and expressive framework for modeling complex systems by enabling entities life-cycles to be represented in a single script. In contrast, other approaches, like the event scanning worldview,1 scatter entities life-cycles among events, making it more difficult to model complex systems. Traditionally, PI was developed without support for modular models, since all processes coordinate throughout the access to a global shared state.2,3 Although this approach can support the representation of simple systems, it does not provide the modular and hierarchical constructs required to enable the description of complex systems as a composition of (sub-)systems.
In previous work, we have developed the Hybrid Flow System Specification (HyFlow) formalism to represent hierarchical and modular hybrid systems.4HyFlow uses generalized sampling and dense outputs as first-order constructs for defining continuous systems.5HyFlow base models are limited to represent a single event, requiring multiple events to be represented by a network model. This constraint imposes an additional complexity for models that have a simpler representation based on shared memory coordination like, e.g., Petri nets. Given a system where several servers share a common queue, a modular formalism like HyFlow will require a complex synchronization to move customers from the queue to an idle server. On the contrary, a PI model of this system is simpler and more expressive.6 There seems to be a gap between modular modeling formalisms that promote modularity and PI that enables simpler models but lacks the ability to represent complex systems.
πHyFlow7 is an extension of the original HyFlow formalism aimed to support PI while keeping modularity and the ability to modify model topology at runtime. πHyFlow defines a modular base model that hosts a dynamic set of processes. While process intra-communication is made through a shared state, the communication between models is achieved by modular messages. The modeler gains the ability to choose whether a system will be represented by a network of models, or by a set of interacting processes, and use the most suitable approach.
We illustrate πHyFlow ability to represent hybrid systems by modeling a resistor–capacitor (RC) electrical circuit, and a simplified DC-DC step-down converter (DCC). The DCC circuit is used to transform a DC voltage into a lower value for a range of loads. RC and DCC circuits are represented ordinary differential equations (ODEs) whose exact solutions are computed by an Exponential Time Differenting (ETD) integrator. For the DCC circuit, an “on-off” digital controller is used to keep the output voltage within the desired output range.
The paper is organized as follows. Section 2 describes the πHyFlow formalism base and network models. This section also presents the models of rectangular and trigonometric signal generators. Section 3 presents, the RC electrical circuit and the Exponential Time Differencing (ETD) integrator. This section presents also RC implementation in the πHyFlow++ modeling & simulation environment. Section 4 presents the DCC model. Section 5 compares πHyFlow with other M&S approaches. A discussion of πHyFlow advantages and limitations, and future work are presented in Section 6. Conclusion is presented in Section 7.
2. The πHyFlow formalism
A πHyFlow base model defines a modular entity that encloses a set of processes communicating through a shared p-state , as represented in Figure 1. Each process keeps its own (private) p-state, and it can perform read/write operations on the shared p-state. Processes have suspend/resume semantics but are non-preemptive making them implementable by coroutines, avoiding the synchronization problems associated with (preemptive) threads.8
πHyFlow base model structure.
Base models communicate through modular input and output interfaces. A process represents a sequence of actions where each action requires an amount of time to be executed. Processes are coordinated by the base model that acts as a scheduler. When scheduled, the base model chooses a process that is enabled to execute and resumes it. After execution, the process suspends itself and gives the control back to the base model that selects the next process to run. A process becomes enabled when a given time interval has elapsed, or when the current guard condition is fulfilled.
Processes do not have an input, since after their creation, they are suspended at some point on their flows waiting for being re-activated. Process communication with the external entities can only thus be achieved, indirectly, through the shared p-state , that can be modified by all processes and by the model input function . Processes, however, have a modular output interface. Base model output is computed by function that uses the outputs from all processes. Since πHyFlow base models have a modular interface, they can be composed to form networks. Formalism is described in the next sections. πHyFlow semantics is provided in Barros.9
2.1. πHyFlow base model
In the original HyFlow formalism, a base model can only schedule one event. πHyFlow removes this constraint by enabling a base model to run several processes, each one with the ability to schedule its own event. Moreover, since processes share a common state, their synchronization becomes easier to achieve when compared with the corresponding HyFlow network model. A πHyFlow base model associated with name is defined by:
where is the set of input flow values, with is the set of continuous input flow values, is the set of discrete input flow values, is the set of output flow values, with is the set of continuous output flow values, is the set of discrete output flow values, is the set of partial shared states (p-states), is the set of (valid) initial p-states, is the input function, with , is a set of processes, is the current-processes function, where is the power set, is the ranking function, where is the set of all sequences based on set , constrained to , for all is the output function associated with p-state , with , and .
The base model receives and produces both continuous and discrete flows (events) through the modular interfaces and . The input function is responsible for updating the current p-state when the model receives a value either by sampling or event communication. The set of processes is dynamic, being the current set defined by function π. Given that processes can access the shared p-state only one can be active at any time. The ranking function decides process resume order. The output function maps the outputs of all processes into the output associated with the base model. A formal description of πHyFlow processes is provided in the next section.
2.2. πHyFlow process model
As mentioned before, a process represents a sequence of actions where each action requires an amount of time to be executed. Processes are coordinated by the base model that acts as a scheduler. When in control, the base model chooses a process that is enabled to execute and resumes it. After execution, the process suspends itself and gives the control back to the base model that selects the next process to run. A process becomes enabled when a given time interval has elapsed, or when the current guard condition is fulfilled. Given a base model with a set of processes , the model of a process is defined by:
where is the set of output flow values, is the set of continuous output flows, is the set of discrete output flows, is the set of indexes, is the set of p-states, is the set of (valid) initial p-states, is the index function, for all is the time-to-input function, is the time-to-output function, is the condition function, is the transition function, is the continuous output function, is the partial discrete output function, is the discrete output function defined by:
with , the state set, and , is the time-to-transition function.
For time specification, πHyFlow uses the set of hyper-real numbers , that enables causality to be expressed, by assuming that a transition occurring at time , changes process p-state at time , where is an infinitesimal.4 Time functions and are constrained to the positive hyper-real values .
A process defines only its output , while the input is inferred from base model p-state. A process defines its own p-state , for reducing inter process dependency. A process dynamic behavior is ruled by six structured/segmented functions, being the segments currently active determined by the index function . The active segments associated with p-state are .
The time-to-input-function specifies the interval for sampling (reading) a value. Since each process specifies its own reading interval, sampling is made asynchronously, and it can be made independently by any process. The concept of generalized sampling refers here to the capability of supporting asynchronous and time-varying sampling. The time-to-input-function establishes sampling as a first-order operator, on par with the traditional concept of event. The time-to-output-function specifies the interval to produce a discrete flow. The condition/guard function , checks whether the process has conditions to run given base model and process current p-states. Functions and specify a time interval for process re-activation, while checks if the process can be re-activated at the current time. Function specifies process and base model p-states after process re-activation. Function specifies the process continuous output flow, and specifies the process discrete output flow. The former can be non-null at every time instant, while the latter can only be non-null at a finite number of time instants during a finite time interval. can provide an exact description for an arbitrary continuous signal based on a discrete formalism. This feature is used in section to describe the continuous output flow of the ETD integrator.
2.3. Trigonometric signal generator
As an example of a πHyFlow base model, we describe a continuous trigonometric signal generator model that produces the output . πThe HyFlow base model associated with a generator named “cos” is defined by:
where
To simplify the notation symbol is overloaded and it can represent an empty value, an empty set, an empty sequence, or a null function, depending on the context. The model of process is defined by:
where
The generator produces (line 9) the continuous signal for the some constants , and . The standard part of hyper-real is noted by . The signals are exact, and it can be obtained through sampling at any point in time. We note that this model can be generalized to describe any continuous trajectory.
2.4. Rectangular-wave signal generator
As an additional example of a πHyFlow base model, we describe a piecewise constant signal generator model. The generator produces a periodic piecewise constant signal with amplitude and duration , followed by a constant signal with amplitude and duration . While the continuous flow output is piecewise constant, the discrete flow output is used to signal the discontinuities. The generator defines a process that sets base model dynamic behavior. The πHyFlow base model associated with a generator named is defined by:
where
The model of process is defined by:
where
Generator state diagram is depicted in Figure 2. The generator starts at index (0), and the current piecewise constant segment is set 0. At index 0, the model switches immediately (zero time delay) to index 1, while it sends the discrete flow . The model loops in index (1). After the delay , it produces the discrete flow and updates . The continuous output flow is always present and is given by . The implementation using coroutines is described in Listing 1 that provides a simpler syntax.
Generator output trajectory is depicted in Figure 3. The generator starts at time and it issues the discrete flow . The continuous flow becomes available for sampling during the interval . At time , the generator issues the discrete flow . During this interval, the constant value is produced as the generator continuous output flow. This cycle repeats making the signal periodic. In general, a πHyFlow base model can receive and produce continuous and discrete flows. A base model can also define an arbitrary number of processes. The set of processes is dynamic, and processes can be created and destroyed at runtime.
RWG output trajectory.
2.5. πHyFlow network model
A πHyFlow network is composed by base or other network models. In addition, each network has a special component, named as executive, that is responsible for defining network topology (composition and coupling). A πHyFlow network model associated with name is defined by:
where is the network name, is the set of network input flows, is the set of network output flows, and is the name of the network executive.
The executive is a HyFlow base model extended with topology related operators. The executive model is defined by:
where is the set of network topologies, and is the topology function.
The network topology , corresponding to the p-state , is given by:
where is the set of names associated with the executive p-state , for all : is the sequence of influencers of , is the input function of , is the sequence of executive influencers, is the sequence of network influencers, is the executive input function, and is the network output function, for all , for base models, and , for network models.
Functions , and enable to compose any arbitrary πHyFlow models, since these functions can be used to match arbitrary model interfaces. Variables and functions are subjected to the following constraints for all :
Constraints 1 and 2 impose that the executive cannot remove neither the network nor itself. Constraint 3 enforces causality (section). Constraints 7 and 8 are a characteristic of discrete systems and impose that a non-null discrete flow cannot be created from a sequence composed exclusively of null discrete flows. Network topology is defined by executive function that maps executive p-state into network composition and coupling. Coupling information includes, for each model, a set of influencers and an input function. Changes in executive p-state can be mapped into changes in network topology, enabling the definition of dynamic structure models. Since HyFlow models have a continuous output flow, the sampling operation reads atomically all current outputs from the influencers’ models and applies the input function, providing the influenced model with a single input value. This operation provides thus support for interface matching. The network has an output function for mapping the output values of its influencers into the network output . Likewise the base HyFlow formalism4 networks and base models are kept during simulation, enabling the co-simulation of πHyFlow models. The next section describes an RC electric circuit as a πHyFlow network model.
3. RC circuit
For illustrating the πHyFlow network model defined in the previous section, we consider the RC circuit of Figure 4. The circuit includes capacitor , resistors and , and voltage source , requiring the solution of a first-order ODE.
RC circuit with a time-varying voltage source.
The voltage in the circuit is given by:
We describe next the ETD numerical integrator that is used to solve Equation (1).
3.1. ETD
The ETD enables exact solutions for some systems or the possibility of using large stepsizes, when solving stiff ODEs.10 ETD considers ODEs in the form of:
where is a constant coefficient and represents the non-linear part. The exact solution for is given by:10
Considering the zeroth-order approximation for :
the corresponding approximation for the solution is given by:
yielding the numerical integrator with a fixed sampling interval described by:
Equation (6) can be used for numerical integration. Equation (5) provides the dense output between steps. This equation can be computed in a similar manner to the trigonometric generator of section . If we constraint the input signal to be piecewise constant, Equation (5) becomes exact, and the ETD can be driven by input discontinuities, obviating the use of sampling (stepsize = ).
3.2. RC network model
The RC circuit of Figure 4 can be represented by the πHyFlow network model shown in Figure 5. Besides the executive that defines the (static) network topology, the model has a rectangular-wave signal generator (RWG) component and an ETD component. The πHyFlow network model for the circuit is defined by , where the executive model is given by:
where is the (static) network topology, , with , where , and .
πHyFlow network model of the RC circuit.
Model is defined in section, and model is described in Barros.7 The next section provides simulation results for this model obtained using the πHyFlow++ M&S environment.
3.3. RC circuit simulation results
πHyFlow++ is an implementation of πHyFlow in MSVC++ 20. πHyFlow++ uses C++ support for modules, variants, lambdas, and coroutines. It uses the concept of port to segment continuous and discrete flows. For each input continuous flow port, there is a merge function to enable a port to sample from several components at once. The merge function computes the combination of the several input samples. For each input discrete flow port, πHyFlow++ assigns an input buffer that collects all values directed to that port. Each continuous output port is assigned to a process that defines a function parameterized by the elapsed time since process last transition. Listing 1 provides the πHyFlow++ implementation of the rectangular-wave model described in section .
The RWG defines the continuous flow output port “value,” and the discrete output flow port “event” (lines 3–4). The continuous flow is defined in line 17. Although for an RWG this value is piecewise constant, the elapsed time “e” enables the definition of arbitrary continuous flow outputs. The process loops within lines 19–22. It holds for a time interval and it sends an event (line 20) corresponding to a new constant continuous output value. The rectangular-wave segment is updated in line 21.
The πHyFlow++ RC network is depicted in Figure 6 and defined in Listing 2. The ETD component sets the ODE coefficient (line 7) according to Equation (1). The ETD also has port “k” enabling the coefficient to be modified at runtime.
The merge function of the ETD is defined in lines 10–13, and the input value is set according to Equation (1). By default, links between discrete flow ports (line 14) define an identity function. For simulation, we have used the parameters defined in Table 1. The rectangular-wave generator has parameters (4 V, −2 V, 0.5 s, 0.25 s). Figure 7 shows results for a simulation time of 7 s. Given circuit parameters, the ETD integrator yields exact simulation results.
RC circuit parameters.
0.5
1.0
0.7 mF
Voltage source , and capacitor voltage for the RC circuit.
4. DC voltage converter (DCC)
A DC-DC step-down converter (DCC) transforms an input DC voltage into a lower output voltage . For simplicity, we consider here a simple first-order DCC based on a resister and a capacitor. Second-order converters based on a combination of capacitors and inductors have also been developed.11 The DCC is represented in Figure 8, and it is composed by a voltage source in series with a switch , a resistor , and a capacitor . The load is connected to the capacitor terminals. The switch position is set by an on-off digital controller that samples the voltage and compares it with the reference value. The switch is turned on when and off otherwise. When the switch is turned off, the circuit can be described by Figure 9, and the capacitor acts as a voltage source that feeds current through the load . The switch is operated by a digital controller described in section .
DCC topology when the switch is “on.”
DCC topology when the switch is “off.”
When the switch is “on,” the voltage is given by Equation (1). When is “off,” the voltage is given by:
Equations (1) and (7) are the first-order ODEs that can be solved without error by the ETD integrator described in section .
4.1. πHyFlow++ DCC implementation
The DCC is modeled by the πHyFlow network model depicted in Figure 10 and defined by πHyFlow++ (Listing 3). The network is composed by the executive, the ETD, and the on-off digital controller. As mentioned in section, the executive is responsible to keep network topology (composition and coupling). The executive is also responsible to update ETD coefficient when the switch changes through the output port “switch.” The executive has also port “on-off” to activate/deactivate the digital controller, and port “rate” to set controller sampling interval. To simplify DCC modeling, the controller acts both as a mechanism to turn the switch on/off, and as a voltage source.
The controller has a sampling rate of s (line 10). Lines 12–16 and 20 define the links shown in Figure 10. The merger functions associated with controller continuous input flow port “value” is defined in lines 17–19. The ETD samples the controller, and the value is given by Equation (1), being computed in lines 21–25 where the controller output is given by variable “V.”
The executive runs processes “manager” (line 25) and“driver” (line 26). Process “manager,” defined in Listing 4, is responsible to update ETD coefficient “k.” When a “switch” discrete flow is received, the “manager” process checks the voltage and sends the new coefficient “k” through the output port “switch.” This value is received at ETD input port “k” as shown in Figure 10.
while ( true) { sim_wait until ([&] {return sw.any();}); auto voltage=sw.remove<double>();
7
if (voltage>0.)
8
sim_wait out (“switch”, −(Rs+R) / (C * Rs * R));
9
else
10
sim_wait out (“switch”, −1. / (C * R));
11 12
} sim_end;
13
}
Line 8 corresponds to Equation (1) defining the circuit of Figure 8, and line 10 corresponds to Equation (7) defining the circuit of Figure 9. Process “driver” is defined in the section and defines the experimental conditions for DCC simulation. Next section provides the implementation of the on-off controller model.
4.2. πHyFlow++ on-off digital controller
An off-off digital controller samples its input at some time interval and it produces the output discrete flows and 0, when the input is below or above a reference value, respectively. The sampling interval is commonly fixed, but arbitrary irregular intervals can also be described in πHyFlow++. πHyFlow++ implementation of the on-off controller model is represented in Listing 5. The component has continuous input port “value” where it samples the input voltage. The reference voltage is set when the component is created. This value can also be modified at runtime through the discrete flow port “reference.” The component has discrete input port “event” to activate/deactivate the controller. Port “rate” sets controller sampling interval.
The controller has a continuous output port “value” with the current output value. Changes in the output value are signaled through discrete output port “event.”
The controller has a fixed sampling interval of “stime” (line 24). This interval can be interrupted when there is an event to: stop the controller, change the sampling rate, or change the reference value (line 25). These events are handled in lines 27–33, 34–38, and 39–43, respectively. Controller continuous output value is defined in line 19. This value is 0 when the controller is deactivated or when the most recent sampled value is above the reference. The input value is sampled in line 46. For simulation efficiency, the on-off discrete flow is only sent if it is different from the previous value (lines 48–51). The controller is initially deactivated (line 17). Next section presents simulation results for the DCC model.
4.3. DCC simulation results
DCC simulation was performed using the process “driver” defined in Listing 6. The controller is initially deactivated, and it has a default sampling interval of 50 ms. The controller is activated at time 0.1 s (lines 3–4). After a duration of 3.0 s, controller sampling interval is set to 100 ms (lines 5 and 6). The controller becomes inactive after 2.0 s (lines 7 and 8).
πHyFlow++ DCC “driver” process.
1
sim_void driver ( std :: string name) {
2
sim_start (name);
3
sim_wait duration (.1);
4
sim_wait out (“on−off”, 1);
5
sim_wait duration (3.);
6
sim_wait out (“rate”, 0.1);
7
sim_wait duration (2.);
8
sim_wait out (“on−off”, 0);
9
sim_end;
10
}
Simulation was performed using circuit parameters described in Table 1, , and . As mentioned before, when activated, the controller commands the DCC, producing a piecewise constant signal of 0 V, when the voltage is above the reference value , and 12 V when the voltage is below . Simulation results for controller output , and capacitor voltage are shown in Figure 11.
Capacitor voltage and controller output , for = 6 V.
The controller is turned on at time 0.1 s and the 12 V voltage is applied until time 0.35 s when the output voltage V > . Voltage oscillates around . The amplitude of oscillations increases when the sampling interval is doubled at time 3.1 s. The controller is turned off at time 5.1 s and exponentially decreases after that time. Given that controller output is piecewise constant, the ETD defined by Equation (6) yields an exact solution. The ETD is also very efficient since it is driven entirely by the events that change the ODE parameter of Equation (6), requiring, for this model, no extra samples that would be required, e.g., by polynomial integrators to ensure a bound in solution error.
4.4. DCC with rectangular-wave voltage reference
The DCC described before has a constant reference voltage. This value can be modified, as mentioned in section, through on-off controller port “reference.” We can create a DCC with a variable voltage by composing the controller with a rectangular-wave generator. Figure 12 represents the new DCC with rectangular-wave voltage reference (DCC-RW) model, where RWG port “event” is connected to controller port “reference,” forcing the DCC to follow the RWG output value that is used as a time-varying reference. For simulation, we have used the RC circuit parameters of Table 1, and a rectangular wave with parameters (5 V, 3 V, 4 s, 2 s) used as a time-varying reference. Results are shown in Figure 13 for a simulation time of 50 s.
DCC with a rectangular-wave reference voltage.
Capacitor voltage and reference voltage .
Preliminary performance results are shown in Figure 14 that presents the real simulation time of the DCC-RW circuit for several simulation times. Given the reduced number of processes the simulations can be efficiently performed. However, handling a large number of threads will require optimizations in the event queue, and in process conditional testing as discussed in section.
DCC-RW execution time × simulation time.
5. Related work
The process interaction worldview (PI) was introduced in GPSS12 and SIMULA2 languages, and it enables a representation based on the flow of systems’ entities. Frameworks supporting PI based on C++,13 Python,14 and Java15 have also been developed, but they do not support modular and hierarchical models. The formal specification of PI was introduced in Zeigler.3 This work was limited to non-modular models, based on a static set of processes. A general approach to process conditional waiting was proposed in Cota and Sargent.16 This work, however, did not add any support to model modularity.
PI makes it easier to model complex systems6 when compared to other worldviews, like the event scheduling.1πHyFlow, an extension of HyFlow formalism, enables the representation of hybrid systems using PI while supporting also modular and hierarchical models.
Traditionally, the representation of continuous/hybrid systems involves the composition of models using a facade modular graphical user interface (GUI), being the set of resulting ODEs flattened for numerical integration.17 Although a model can have a modular appearance, its simulation may not be modular. Models are usually translated into a set of ODEs/Differencial Algebraic Equations that are solved with a common type of numerical integrator. The combination of heterogeneous integrators like ETD or geometric solvers is not possible, affecting the fidelity of models. Model flattening poses also problems for supporting changes in model topology.
To the best of our knowledge, generalized sampling was introduced in author work.5,18 Multirate numerical integrators have also been developed.19,20,21 These approaches, however, do not provide a modular representation of ODEs. On the contrary, CFSS support for generalized sampling and continuous outputs enables the definition of modular numerical integrators. In addition, CFSS modular integrators not only can sample at different sampling rates but also can have time-varying sampling rates. CFSS enables the seamless composition of different families of numerical integrators. The concept of elapsed time used in CFSS to produce continuous flows was formalized in DEVS.3
CFSS supports co-simulation since it guarantees modularity of both models and the corresponding simulation. πHyFlow uses CFSS operators to enable an accurate description of continuous signals. The support for multiple clocks was introduced in Esterel22 and Modelica23 languages, but continuous flows are limited to piecewise constant segments. These limitations do not enable the representation of continuous flows required, e.g., to model the ETD integrator described in section. Other representations, like communication sequential processes (CSPs)24 and Khan25 networks, can only provide support for piecewise constant signals.
The representation of continuous signals using polynomials was achieved by G-DEVS.26 In this approach, continuous signals are encoded by the coefficient of approximating polynomials. Since coefficients can only be pushed through discrete events, this solution does not guarantee, in general, that the output of a model is always exact. Another feature of this approach is that it requires the conversion of arbitrary continuous signals into polynomials. Taking, e.g., the ETD of section, an additional conversion layer would be necessary to convert the exponential solution into a series of piecewise polynomials approximations. G-DEVS does not support sampling, requiring model output to be computed by the connecting models, so sampling can be emulated. This solution may introduce, however, additional problems for representing hierarchical and modular models.
The explicit representation of first-order ODE polynomial integrators was developed in QSS.27 QSS, however, does not provide support for the sampling operation. In addition, QSS does not provide a framework for representing geometric integrators that are required to describe second-order energy conservation systems,28 since the concept of quantization breaks the conditions for achieving energy conservation.
Hybrid systems have been described in the graphical Ptolemy framework.29 This approach, however, has several limitations. Ptolemy does not provide a complete semantics of continuous signals making it uncertain if dense outputs and generalized sampling can be represented in this framework.29 In addition, we found no evidence that numerical integrators of different families can be seamlessly composed in Ptolemy.
6. Discussion and future work
To the best of our knowledge, πHyFlow is the first formal description of a hierarchical and modular framework for representing hybrid models based on the combined transaction/network process interaction worldview. πHyFlow enables a process (shared memory) for the representation of simple systems to the network view for representing complex ones. Fluid stochastic Petri nets, e.g., have a very simple representation using πHyFlow,30 while a modular description using HyFlow formalism would become more involved.31πHyFlow enables modelers to choose the most adequate level of abstraction to represent models, avoiding complex solutions imposed by the limitations of modular formalisms that represent just one event in their base models.4
πHyFlow inherits form the original HyFlow formalism the support for generalized sampling, dense outputs—enabling the exact description of continuous signals, and the ability to represent modular and dynamic topology hierarchical models. The πHyFlow formalism introduces support for the modular transaction and network process interaction worldviews. The former worldview is based on the dynamic creation/destruction of processes. The current formalism implementation is based on the MSVC++ 20 language and it uses coroutines for representing simulation processes. Coroutines support cooperative concurrency scheduling themselves without being visible to the operating system. A coroutine executes without preemption until it decides to suspend itself. At this point, the simulation scheduler chooses and resumes another coroutine. Coroutines are also stackless leading to their efficient switch.
Most current C++ and Java implementations of simulation processes are based on threads. A thread is an operating system construct being visible to the real-time scheduler. Threads can be arbitrarily suspended at any point imposing a complex coordination mechanism to guarantee race-free executions.8 Threads are also heavyweight entities when compared to coroutines. Moreover, thread context switch is heavier when compared to coroutines since threads need to swap, e.g., stacks and registers. Since coroutines are not subjected to preemption, the number of coroutine switches can be dramatically reduced when compared with (pre-emptive) threads. These features make coroutines more efficient that threads. While the number of threads needs to be limited to not overload the operating system, coroutines can run in single thread, making their number virtually unbounded.
One of the most performance critical elements of a simulator is the event handler. The current version of πHyFlow++ uses a heap32 to manage events. Future work will address the use of more efficient data structures like the ladder-queue,33 and the comparison with other M&S frameworks. Nevertheless, the superior performance of coroutines over threads for representing simulation processes has been shown.34 One can conjecture that, given native support for stackless coroutines, performance can actually be improved using C++ 20.35 We will also exploit coroutine efficiency, and the ability to handle large numbers of coroutines to develop agent-based simulations using πHyFlow++. Since πHyFlow can faithfully describe continuous signals, we intend to assess πHyFlow++ ability to represent continuous space/time agent-based models.
The current formalism supports explicit numerical integrators. Support for implicit solvers will be considered in future work. In particular, we will exploit rollback to describe implicit solvers.36 Future work is also required for developing a simpler graphical notation to represent complex processes.
In this paper, we have described the model of DCC voltage source. Future work will also address the extension of πHyFlow to be integrated with real-time systems where models and hardware components can be seamlessly swapped, providing also support for digital twins.37
7. Conclusion
πHyFlow extends the HyFlow formalism by introducing support for processes, enabling a simpler framework for expressing complex modular and hierarchical models. In particular, base models support for PI can describe complex interactions using shared states simplifying semantics and avoiding the involved coordination required by an equivalent HyFlow network model. πHyFlow achieves the representation of hybrid models based on continuous flows, generalized sampling, and discrete events. These operators enable the representation of high-fidelity/exact models on digital computers based on non-conventional integrators like ETD. πHyFlow++ is a C++ 20 implementation of the πHyFlow formalisms that uses coroutines for providing, when compared to threads, an efficient implementation of simulation processes.
Footnotes
Funding
This research received no specific grant from any funding agency in the public, commercial, or not-for-profit sectors.
ORCID iD
Fernando J Barros
Author biography
Fernando J Barros is a professor at the University of Coimbra. His research interests include theory of modeling and simulation, hybrid systems, and dynamic topology models. Fernando Barros has published more than 80 papers in modeling and simulation. He is associate editor of SIMULATION and vice-president of the Society for Modeling and Simulation.
References
1.
SchrubenL. Simulation modeling with event graphs. Commun ACM1983; 26: 957–963.
ZeiglerB. Theory of modelling and simulation. Hoboken, NJ: John Wiley & Sons, 1976.
4.
BarrosF. On the representation of time in modeling & simulation. In: Winter simulation conference, Washington, DC, 11–14 December 2016, pp. 1571–1582. New York: IEEE.
5.
BarrosF. Towards a theory of continuous flow models. Int J Gen Syst2002; 31: 29–40.
6.
RusselE. Building simulation models with SIMSCRIPT II.5. La Jolla, CA: CACI, 1999.
7.
BarrosF. High-fidelity modeling & co-simulation with πHyFlow. In: MasciPBernardeschiCGrazianiP, et al. (eds) Software engineering and formal methods: SEFM 2022 collocated workshops, vol. 13765. Cham: Springer, 2023, pp. 269–285.
8.
LeeE. The problem with threads. Computer2006; 39: 33–42.
MarzollaM. libcppsim: a Simula-like, portable process-oriented simulation library in C++. In: 18th European simulation multiconference, Magdeburg, 13–16 June 2004, pp. 222–227.
14.
LiuJ. Simulus: easy breezy simulation in Python. In: Winter simulation conference, Orlando, FL, 14–18 December 2020, pp. 2329–2340. New York: IEEE.
15.
HealyKKilgoreR. Silk: a java-based process simulation language. In: Winter simulation conference, Atlanta, GA, 7–10 December 1997, pp. 475–482. New York: IEEE.
16.
CotaBSargentR. A modification of the process interaction world view. Trans Model Comput Simul1992; 2: 109–129.
17.
FritzsonP. Principles of object-oriented modeling and simulation with modelica 2.1. Hoboken, NJ: John Wiley & Sons, 2003.
18.
BarrosF. A framework for representing numerical multirate integration methods. In: Paper presented at the Proceedings of the 2000 AI, simulation, and planning in high autonomy systems, Tucson, AZ, 6–8 March 2000, pp. 149–154. New York: ACM.
19.
EngstlerCLubichC. Multirate extrapolation methods for differential equations with different time scales. Computing1997; 58: 173–185.
20.
GearC. Multirate methods for ordinary differential equations. Technical report COO-2383-0014; UIUCDCS-F-74-880, 1September1974. Champaign, IL: Department of Computer Science, University of Illinois at Urbana-Champaign.
21.
LuanVChinomonaRReynoldsD. A new class of high-order methods for multirate differential equations. SIAM J Sci Comput2020; 42: A1245–A1268.
22.
BerryGSentovichE. Multiclock Esterel. In: MargariaTMelhamT (eds) Correct Hardware Design and Verification Methods, vol. 2144. Berlin: Springer, 2001, pp. 110–125.
23.
ElmqvistHMattssonSEOtterM. Object-oriented and hybrid modeling in modelica. J Eur Syst Automat2001; 35: 1–22.
KhanG. The semantics of a simple language for parallel programming. In: Proceedings of the IFIP congress 74, Stockholm, August 1974, pp. 471–475.
26.
GiambiasiNEscudeBGhoshS. GDEVS: a generalized discrete event specification for accurate modelling of dynamic systems. Simul Trans SCS2000; 17: 120–134.
27.
MigoniGBortolottoMKofmanE. Linearly implicit quantization-based integration methods for stiff ordinary differential equation. Simul Model Pract Theory2013; 35: 118–136.
28.
BarrosF. Modular representation of asynchronous geometric integrators with support for dynamic topology. Simul Trans SCS2018; 94: 259–274.
29.
PtolemaeusC (ed.). System design, modeling, and simulation: using Ptolemy II. Berkeley, CA: Ptolomy.org, 2014, p. 341.
30.
BarrosF. πHyFlow: a modular process interaction worldview. In: Winter simulation conference, San Antonio, TX, 10–13 December 2023, pp. 1421–1432. New York: ACM.
CormenTLeisersonCRivestR, et al. Introduction to algorithms. Cambridge, MA: MIT Press, 2009.
33.
FurfaroASaccoL. Adaptive ladder-queue: achieving O(1) amortized access time in practice. In: SIGSIM-PADS ’18: Proceedings of the 2018 ACM SIGSIM conference on principles of advanced discrete simulation, Rome, 23–25 May 2018, pp. 101–104. New York: ACM.
34.
WeberDWiesnerPFischerJ. A closer look at process-based simulation with stackless coroutines. Inform Softw Technol2022; 141: 106695.
BarrosF. Rollback support in π HyFlow modular models. In: Winter simulation conference, Orlando, FL, 14–18 December 2020, pp. 1039–1050. New York: IEEE.
37.
CiminoCNegriEFumagalliL. Review of digital twin applications in manufacturing. Comput Ind2019; 113: 103130.