# CoSimulating Communication Networks and Electrical System for Performance Evaluation in Smart Grid
## 3 OOCoSim Design and Implementation
### OOCoSim Design
If further actions are required to handle the event, it calculates the state variables according to the predefined policy and goes into \"message communication\" state. In the \"message communication\" state, the network simulation is invoked to measure the communication delay and its accuracy. When a response message is received, the cosimulation steps into \"power system analysis\" state. In this state, the resulting values of the state variables are applied to the power system simulator and the relevant impacts are simulated. It is worth noting that the power simulation employing OpenDSS results in the time-driven signal and the network simulation employing OPNET results in the event-driven signal during cosimulation. The gap between the types of simulation results should be tightly engaged to guarantee the correctness of cosimulation. OOCoSim resolves this problem by casting the time-driven signal to the event signal  
Figure 2: The finite state machine of the cosimulation. form, exploiting the mechanism of the smart grid system and its application model. After the power system simulation in \"power system analysis\" state, OOCoSim analyzes the change of state variables provided by OpenDSS and extracts the specific events that the application model should regard, such as the completion time of a certain electrical vehicle. The events are registered as a set of timer signals to the cosimulation and the cosimulation is invoked by those signals in \"idle\" state with the information the application model needs. However, the casting strategy takes effect on the assumption that the time table of OpenDSS and OPNET simulation should be synchronized, since the FSM manages the events driven by both simulations. There are three types of the synchronization schemes widely used for cosimulation: master-slave, time-stepped, and global event-driven synchronization methods [27]. The master-slave method selects one simulator as the master simulator, so the function of the application module can be limited. The time-stepped method can cause accumulated errors so the fidelity of the simulation can be hampered [27]. To deal with these limitations, OOCoSim employs a global scheduler and a global/local time management scheme for synchronization. Before addressing our time synchronization design, it is worth considering the relationship between OOCoSim components in time manner. OPNET performs the network simulation which directly affects the control of the smart grid simulation. Most of the network events are invoked at the unpredictable (stochastically distributed) time during the simulation, and most of them should be alerted to the application model or OpenDSS to determine their action. On the other hand, OpenDSS outputs the simulation result until it is in a steady-state. OpenDSS results in the scheduling of the time of the application model, consequently the scheduling of the time of the OPNET. However, it is notable that the OpenDSS simulation operates in continuous manner, while its trigger state is defined discretely in smart grid environments. Thus, time management module must satisfy these requirements:  
1. The OPNET must advance its time after all of the OpenDSS events that could occur in that time are probed. 2. The OpenDSS results must be registered before OPNET advances its time. OOCoSim achieves these objectives by its novel time management module. Firstly, every event of the application model and the pre-defined simulation scenario are scheduled in the global scheduler. For instance, output diversity of renewable energy generators and charging schedule of electric vehicle are scheduled in the global scheduler. Then, the application model transmits these schedules to the OpenDSS and operates Solve command to simulate in the current schedule status. The simulation results from OpenDSS are reported to the application model, and those are registered in the application model timeline. Then, the global scheduler grants the time advance of the OPNET by the specific amount of time, which is previously set as constant by user.