# CoSimulating Communication Networks and Electrical System for Performance Evaluation in Smart Grid
## 3 OOCoSim Design and Implementation
### OOCoSim Design
The global scheduler adds the events which occur in that time to the OPNET. If there were no meaningful events that occurred in the OPNET simulation, the global scheduler simply continues the time advance of OPNET. Otherwise, if an event that requires a simulation in OpenDSS occurs during OPNET simulation, OPNET pauses the simulation and reports to the application model. Since the OPNET event refers to the request of the operation of smart grid system, OpenDSS simulation should be recalculated from the time where the event occurs. For example, if the information message containing the price of the electricity arrives at a certain node in OPNET, future events of DR application and a load adjustment event of OpenDSS may be reassigned to the global scheduler. The application model invokes the Solve command of the OpenDSS, and reflects the renewed schedules received from OpenDSS and continues the time advance of the OPNET. Figure 3 shows the example of the time schedule in OOCoSim. \(s_{0},s_{2}\) are the time of pre-defined schedules of a specific scenario, and \(s_{1},s_{3},s_{4}\) are the time reported by OpenDSS initial simulation. The events \(s_{0},s_{1}\) and \(s_{2}\) are transmitted to the OPNET, respectively, when the application model grants the time advance by \(T\). OPNET simulates network event which occurs at the simulation time \(e_{0}\), and the OPNET pauses its simulation at \(e_{0}\) since this event might cause the change of future plans. After re-simulating the OpenDSS from \(e_{0}\), its simulation results are reported to the application model  
and renews the adjusted schedules \(s_{3},s_{4}\) to \(s^{\prime}_{3},s^{\prime}_{4}\). OPNET receives the adjusted schedules and continues simulation during \(T\) or until the other event occur. To verify our time management scheme guarantees the time synchronism between the OPNET and the OpenDSS, it should be proved that the renewal operation of OpenDSS does not violate the time advancing status of OPNET (i.e., \(s^{\prime}_{3}>e_{0}\) and \(s^{\prime}_{4}>e_{0}\)). Let \(\mathbf{E}(t)\) be the vector of control variable at time \(t\), then \(f(\mathbf{S}^{power}(t),\mathbf{E}(t))\) results in a set of vectors \(\mathrm{S}(t)=\{\mathbf{S}^{power}(t+n\Delta t)\}\), where \(\Delta t\) is an intrinsic time step parameter used in OpenDSS. In our example, \(f(\mathbf{S}^{power}(e_{0}),\mathbf{E}(e_{0}))\) results in the events at \(e_{0}+n\Delta t\), which satisfies \(s^{\prime}_{3}>e_{0}\) and \(s^{\prime}_{4}>e_{0}\). The analysis proves that the renewed schedule does not violate the time synchronism of OOCoSim timeline. The proposed solution seems to be similar with the existing time-stepped methods because of the existence of \(T\). However, \(T\) does not indicates the _granularity_ of the time management, since the event handling mechanism and the adjustment of the OOCoSim schedules fully covers the time synchronism. Due to the event-driven feature of OPNET, co-simulation related events can be instantly handled independent on the variance of \(T\).