# CoSimulating Communication Networks and Electrical System for Performance Evaluation in Smart Grid
## 3 OOCoSim Design and Implementation
### OOCoSim Design  
In the smart grid, the operation of the power system can be represented by a set of state variables where each variable represents an operation state of power system elements. For example, in the distribution automation system, the operation of circuit breakers can be abstracted with boolean state variables. Therefore, the goal of smart grid applications can be defined as managing state variables of the power system to make the system stable and efficient. To achieve the goal, diverse functions and policies are defined in each application. The policies and functions usually receive current states of the power system and control event signals, and they generate output state. Therefore, we can explain the smart grid application through the following equation:  
\[\mathbf{S}^{power}=\mathbf{S}^{power}+f(\mathbf{S}^{power},\mathbf{E}), \tag{1}\]  
where \(\mathbf{S}^{power}\) is a vector of state variables of power system, \(\mathbf{E}\) is a vector of event and/or control variable, and \(f(\cdot)\) is an application policy or function. However, in the smart grid, applications try to change the state variables of power system through the network system. Therefore, the output state variables of the applications cannot be applied to the power system immediately. In the worst case, the desired state variable cannot be delivered due to a transmission failure, so the application function can yield inaccurate results. It could be meaningless to consider the network delay in the smart grid application since the network delay has milliseconds unit in well-designed (typically wired) communication infrastructure while the smart grid application has the dynamics in the order of seconds (for example, energy dispatching from the storage unit in [15] and fault detection in [11]). However, it is very difficult to design the communication infrastructure in which every entity has milliseconds-level response time and zero packet error rate. If we consider wireless-based infrastructure, it becomes more unrealistic. In wireless infrastructure, the delivery of the control message can be longer than order of milliseconds and frequent packet error can occur. Moreover, if we consider an application which requires multiple message communication to solve any problem in power system, considering the communication delay and packet error in application model become more important. Therefore, the smart grid application can be redefined by following equation:  
\[S_{i}^{power}(t+d_{i}(t))=S_{i}^{power}(t)+p\cdot f(S_{i}^{power}(t),\mathbf{E}) \tag{2}\]  
where \(d_{i}(t)\) is the communication delay of a control message sent to the \(i\)th IED (Intelligent Electronic Device) at time \(t\), and \(p\) is used to represent a failure in the network system (\(p=0\), if packet error). To simulate the behavior of the smart grid application defined in (2), capability of power system simulation, network simulation, and application model should be converged into one simulation model. Basically, the application model defines actions which receive state variables and event signals as input arguments, processes the arguments, and generates output state variables and decisions for the event. The network simulation performs message communication of reporting and controlling power system state variables, and \(d_{i}(t)\) and \(p\) of (2) are retrieved. Then, the resulting state variables of the application model are applied to the power system simulator to retrieve power system-side simulation results which are relevant to the stability and the efficiency of the smart grid. Through this procedure, cosimulation in the smart grid can be successfully performed. To implement the cosimulation, OOCoSim mechanism is described by a FSM with four states: idle, event received, message communication, and power system analysis, as shown in Figure 2. When an event signal or a timer signal is delivered to the cosimulation, it steps into \"event received\" state. In each state, the application model processes the signal and decides the state transition.