## 3 Modelling and Implementation of the Simulation Prototype
### Model Implementation Using Modelica
#### 3.3.1 Logistic Flow Simulation  
The logistic flow simulation (LFS) package contains the necessary classes to simulate the flow of materials and production orders throughout the stages (assembly and inspection). In a synthesized way, the developed classes for the simulation system have to support different tasks: the initial parameters' establishment (Simulation_Scenario class) and their behavior modelling (Scenario_Dynamics class); the assembly process construction and DEVS formalism through the different stages (Assembly_Station and Inspection_Station classes); data transformation due to the process or control actions (Monitor&Control class), etc. These main classes are described briefly below:  
* Simulation_Scenario. This Modelica class contains the initial parameters that define the simulation scenario and corresponds to the Simulation_Scenario block of the SysML model. The main parameters are grouped into the following groups:
* Assembly_Plan: parameters to collect the sequence of assembly and/or inspection stages. For each stage, the following are indicated: the station in which it is carried out, the subassembly and built-in part, as well as the parameters to model the process time through a normal distribution (mean and a standard deviation). * Assembly_Identification: parameters that identify each of the types of subassemblies used in the various stages, indicating the types of part included. * Other parameters to model assembly orders' arrival, part arrival, setup time, failure rate, storage capacity, etc. * Scenario_Dynamics. Some initial parameters defined in Simulation_Scenario can be modelled with continuous functions or discrete changes, introducing a temporal variation. The Scenario_Dynamics class is used to model this dynamic behavior, for example, to consider a gradual increase in the processing time caused by the continuous degradation of the assembly station due to its use, or a punctual (sudden) change in the distribution of the arrival time of the parts due to a change of supplier. * Assembly_Station and Inspection_Station classes correspond to the WorkstationProcess block from the SysML model and represent an assembly and inspection workstation, respectively. Figure 7: OpenModelica screenshot. On the left side: logistic flow simulation (LFS) and variation flow simulation (VFS) libraries, and some VFS internal classes (connectors, models, and functions). On the right side: a diagram view of an instantiated model for the study case. As described in the SysML model, these complex blocks with a coupled DEVS behavior, in turn, are composed of single blocks which have a discrete behavior definition using an atomic DEVS formalism. All these single blocks use data from Simulation_Scenario and Scenario_Dynamics. In Figure 8, the internal structure of these Modelica classes is shown, mainly composed of the classes described below:  
* Part_Generator and Assembly_Generator. These models define the process of generating the arrival of parts and assembly orders, respectively. These Modelica models correspond to PartArrivalProcess and AssemblyArrivalProcess blocks in the SysML model. Part_Generator is represented by a blue box in Figure 8.  
* Monitor&Control. This Modelica class collects data from each WorkstationProcess, allowing it to execute a statistical analysis to estimate the productivity performance parameters. In addition, this is the basic class that can be specialized to carry out control actions, e.g., a change of the assembly processing order using a dispatching rule. Additionally, three types of connectors are defined in Modelica to support different data flows between blocks. These connectors are:  
* Assembly_connection. This type of connection contains the data related to the assemblies' flow. These data include the assembly order, the parts contained, and the types of these parts. Additionally, these connectors include Boolean variables to indicate the discrete external events linking the blocks that participate in the assemblies' flow.