PC Implementation of a Real-Time Simulator Using ATP Foreign Models and a Sound Card

: This work reports the personal computer implementation of a real-time simulator based on the widely used Electromagnetic Transients Program, version Alternative Transients Program (EMTP-ATP) software for testing protection and control devices. The proposed simulator was implemented on a conventional PC with a GNU/Linux operative system including a real-time kernel. Using foreign models programmed in C, ATP was recompiled with the PortAudio (sound card I/O library) with tools for writing and reading the parallel port. In this way, the sound card was used as a digital-to-analog converter to generate voltage waveform outputs at each simulation time step of the ATP, and the parallel port was used for digital inputs and outputs, resulting in a real-time simulator that can interact with protection and control devices by means of hardware-in-the-loop tests. This work uses the minimum possible hardware requirements to try to implement a real-time simulator. Due to the limitation of two channels, this simulator was used mainly to demonstrate the implementation methodology concept at this stage; this concept could potentially be expanded with more powerful hardware to improve its performance. The performance of the implemented simulator was analyzed through interactions with a real intelligent electronic device (IED). Furthermore, a comparison with the results obtained by means of the well-known real-time digital simulator (RTDS) was presented and discussed.


Introduction
Since its beginning in the 1950s, the time-domain digital simulation of electromagnetic transients in power systems [1] has evolved to the present-day real-time simulators that can interact with real equipment through hardware-in-the-loop (HiL) digital real-time simulation (DRTS) [2]. This has become possible because simulators can resolve the differential equation system that represents the power system dynamics in a shorter time than the duration of the physical phenomenon [3]. More importantly, such simulators have input and output interfaces that enable the externalization of computed variable values and the reception of signals from real devices. DRTS represents the computation and reproduction of a phenomenon that is likely to occur if a field test is performed [4]. Prior to the development of existing fully digital real-time simulators, such as real-time digital simulators (RTDSs) [5] and OPAL-RT [6], analog and hybrid simulators [7] were used until computers achieved speeds that enabled the simulation of electromagnetic transient phenomena in real time.
These real-time simulators require a high processing capacity, and, thus, they were initially implemented using several processors working in parallel and were distributed in racks, which were able to test relays [8]. Today, these systems are called intelligent electronic devices (IEDs). The Electromagnetic Transients Program, version Alternative Transients Program (EMTP-ATP), simply referred to in this paper as ATP, is a non-commercial digital simulation program for electromagnetic transients that is used particularly in electrical power systems based on royalty-free development of EMTP. In general, the ATP software is royalty-free, but it is not freeware [9]. ATP enables the simulation of electromagnetic transient phenomena on the basis of sophisticated models of transmission lines, transformers, electric machinery, etc., as well as the components of circuits and elements that control the switches and triggers of thyristors [10,11]. Studies conducted in the 1990s that continued until 2010 [12][13][14] reported the development of real-time simulators based on EMTP [15,16].
ATP provides the option to program new electrical and control components through MODELS, which is the ATP language for programming time-varying systems using routines called models. MODELS interacts with ATP by receiving ATP-generated data as inputs and generating variables that ATP receives for use in MODELS-controlled components as outputs. The models can be programmed in non-ATP languages (called foreign models), such as Fortran, C or any other language where the compiler generates files that are compatible with the ATP object files. Foreign models can be developed for a specific use according to the user's needs [17] and integrated to create a new version of ATP. Foreign models that implement protection functions are presented in [18,19].
The authors of [20] reported the development of an ATP-based real-time simulator that uses the sampled values and generic object oriented substation event (GOOSE) IEC-61850 protocols to exchange simulated data via a network card interface using a Windows operating system (OS). The present work uses similar principles to implement a real-time simulator programmed via foreign models in ATP that can generate electrical waveforms (using a sound card interface) to conduct HiL tests on IEDs. This simulator is called Alternative Transients Program-Real Time (ATP-RT) in the rest of this paper. The simulator is developed on a conventional personal computer (PC) with the GNU/Linux OS with a real-time kernel. The digital-to-analog converter (DAC) of the sound card is used to generate electrical signals that represent variables of the simulated system, and the parallel ports are used as a digital input-output (I/O) interface. The main objective of this prototype is to demonstrate the viability of constructing a real-time system based on ATP. In this case, the minimum possible hardware requirements were used, but it is possible to improve the performance of the developed simulator using more powerful hardware.
The remainder of this paper is structured as follows. Section 2 demonstrates the implementation of the real-time simulator. Section 3 presents the laboratory hardware and the power system used to analyze the performance of the ATP-RT developed via HiL-DRTS. Section 4 analyzes a particular simulated case to verify the signals registered by the IED, presents the results of several simulations performed with the test system and discusses these results, including a comparison with the best-known RTDS. Section 5 describes some potential applications of this simulator in addition to possible future developments. Finally, Section 6 presents the conclusions of this study.

Implementation
A conventional PC with a stereo audio sound card and a parallel port interface was used in the development of the ATP-RT. ATP foreign models were used to integrate I/O interfaces, and in each simulation step, the numerical values of the circuit variables were written on the DAC of the sound card, while digital variables were written and read on the parallel port card. This process was used to develop a real-time simulator for closed-loop testing of IEDs at the signal level. The ATP-RT runs on a 32-bit GNU/Linux OS with a real-time kernel (PREEMPT-RT), which enables the assignment of priorities to tasks and has preemption characteristics. A PC with an Intel-i5 processor, 4 GB RAM and 32-bit OS is used because the ATP version for GNU/Linux is compiled for 32 bits.

Input and Output Interfaces
The stereo sound card of the PC, which generates electrical signals in levels from −1.5 to 1.5 V with a 24-bit resolution, is used to provide two analog outputs that externalize the numerical values computed by ATP via its DAC. PortAudio is a free, cross-platform, open-source, audio I/O library that can be used to write simple audio programs in C or C++ that will compile and run on many platforms, including Windows, Macintosh OS X, and Unix (OSS/ALSA). PortAudio is intended to promote the exchange of audio software between developers on different platforms. Many applications use PortAudio for audio I/O [21]. In this application, PortAudio is used to externalize the values computed by ATP, and it exhibits good performance for real-time tasks when running on GNU/Linux.
The parallel port interface, which operates at 0 V for non-active bits and 5 V for active bits, is used to supply digital I/O. The parallel port has three registers that can be used as separate digital I/O interfaces.

ATP Foreign Models
A foreign model is a control or circuit component implemented in a non-MODELS language, for example, standard C or Fortran, which can be called in the MODELS section of the ATP input file. This user-defined component is embedded in a new ATP file that is generated after the recompilation process, as illustrated in Figure 1. The ATP source files are only available to ATP developers. The ATP object file is available to users, and a method is provided to link it with user files generated after compiling foreign models. Thus, ATP provides a way to develop complex components in a flexible and standard language, such as C, thereby enabling the creation of new components to use in the ATP environment and the use of any library in the C programming language when developing a foreign model, which can even interact with the hardware because C allows low-level access.  A foreign model was developed to interact with the real world (equipment) according to Figure 1. This component receives the voltage and current values computed by ATP in each simulation step and then converts them into electrical voltage signals through the sound card DAC, whose programming interface in C is provided by the PortAudio library. The sampling rate was set to 10,000 samples per second, which means that ATP must be configured to work with a simulation step of 100 µs. The PortAudio library works with the GNU/Linux sound card driver called ALSA, an acronym representing Advanced Linux Sound Architecture, which is suitable for real-time tasks and displays an overrun message when the value of the variable to be computed is not ready to be externalized to the sound card or when the externalization process is time-consuming and the sampling rate is consequently exceeded. Therefore, it is possible to determine whether a given simulation has run in real time in all simulation time steps. Likewise, the circuit breaker (CB) status is externalized by writing to a parallel port register. A 5 V signal appears in a parallel port pin if the CB is closed; otherwise, the signal is 0 V. This signal is used by the IED auto-reclosing logic. Another register in the parallel port is read in this component, where the relay trip signal is received. This trip signal acts as a control of a switch controlled by MODELS, which simulates the CB.

Test Case
This section details the electrical system studied and the hardware required to conduct HiL tests to analyze the ATP-RT performance. The IED settings and the ATP input file are also presented.

Test System
The electrical system in this study corresponds to a 230 kV transmission system based on [22] that is 180 km in length and has two buses that are represented by their equivalents (sending and receiving sources and their Thevenin equivalent impedances), as shown in Figure 2a. There is a CB between Bus 1, and the beginning of the transmission line is point s.    Table 1 shows the SEL-421 settings. The phase overcurrent function was used because only two channels of analog output are available in the ATP-RT. The dead time for the three-phase auto-reclosing function was adjusted to 20 cycles.  Figure 3 shows the ATP input file; line 3 indicates that a simulation time step of 100 µs and a final simulation time of 0.9 s were implemented. Additionally, the component for I/O is called in the MODELS section. Then, the voltage v a and current i a signals are generated, the CB status is externalized, and the trip signal from the IED, which acts as the control signal for a switch controlled by MODELS, is read. In the rest of the file, the circuit is described using sections BRANCH, SWITCH, SOURCE, etc., as is conventionally done in ATP. The distributed parameters model was used to represent the transmission line.    The ATP-RT (tpbig_rt) runs as superuser using high priority when executing the program by means of the "chrt" command as follows:

ATP Case
# chrt −r 99 tpbig_rt SYSTEM230.ATP When running, voltage signals are generated and received by the I/O interfaces, and the ATP output file is generated. Figure 4 shows the oscillography corresponding to the test case. The simulated signals and the oscillography registred by the relay are plotted separately because they do not have the same time reference. The only reference between the two plots is the trip instant. Figure 4a shows the waveforms and some of the variables obtained in the output file (.pl4) after running the ATP-RT, where a single-phase-to-ground (AG) fault with a duration of 100 ms was simulated with R f = 1 Ω located 30 km from Bus 1, including the auto-reclosing function of the IED. The voltages and currents are displayed at Bus 1, the fault point and Bus 2. Furthermore, digital signals, including the fault insertion (FAULT), IED trip (TRIP), CB status (STATUS), and IED auto-reclosing function (RECLOSE), are shown. The IED operates after the fault, and the simulator receives a trip signal to perform a three-pole opening of the CB. Finally, at the time set for auto-reclosing, the ATP-RT receives the reclosing signal from the IED, and the CB status immediately changes from open to closed. A real-time closed-loop simulation is achieved, thereby enabling an analysis of the IED performance. The simulation is consistent with the IED settings.      Figure 4b shows the signals recorded by the IED in COMTRADE format [24] for this case, namely, the voltage v a , current i a , and digital variables (i.e., CB status, trip signal, and reclosing signal). The IED were configured to save 1 s for an event, 10% corresponding to the pre-fault condition. A latency time is observed until the bits of the IED (TRIP and RECLOSE) reach the ATP-RT simulation because these signals are externalized by means of contactors. These signals should reach the parallel port of the PC and be read by the ATP-RT. All real-time simulators have some latency due to the nature of the phenomenon and hardware limitations.

Results
Finally, multiple cases were simulated with different resistances and fault locations; a Python script was written for this purpose. The script generates the specific ATP input file, calls the ATP file (tpbig_rt), analyzes the output file, and saves the operating times of the digital variables for each case. The same cases were simulated with the well-known RTDS, and the operation times were also analyzed. Figure 5 was generated using an automated reporting software for this type of test that includes the asserted bits and their operation times for a set of tests. The upper part shows the results of simulations obtained with the developed ATP-RT, and the lower part shows the results obtained with the RTDS. Circles represent TRIP bits, and squares represent RECLOSE bits. The time (in milliseconds) of the bit operation after the fault start is contained within the symbols. The both cases were considered in the relay setting: auto-reclosing disabled and auto-reclosing enabled. The IED performs similarly when tested by the ATP-RT and RTDS; the little difference between them is due to the fact that the signals coming from the IED reach the RTDS faster than they reach the ATP-RT. These cases are not exactly identical because the fault insertion angle was not considered. However, the RTDS receives the signal faster due to the parallel port acquisition speed. The average difference is 12 ms. Moreover, it is important to quantify the latency of the ATP-RT versus widely accepted real-time simulators.
This latency is evident in Figure 4b. RTDS receives the signal first because it has a dedicated interface for this purpose. However, the developed ATP-RT can perform valid tests in real IEDs as it can generate electrical signals at the simulation time step and presents only a 12 ms latency for receiving the trip and reclosing signals. This is not a serious problem, as real CBs take a few dozen milliseconds to open, which can be included in the simulation by considering the 10 ms latency when reading the digital signals.

Potential Applications
As mentioned above, this stage corresponds to a demonstration of the proposed concept to show that it is possible to generate waveforms at each time step simulation of the ATP-RT and develop a real-time simulator. The sound card possesses numerous limitations, such as the limitation to two channels, the speed of the DAC, and the low voltage range (from −1.5 to 1.5 V). Furthermore, it introduces a latency that is within the limit for the application to tests of IEDs. However, ATP is used widely around the world; consequently, the possibility for conducting real-time tests on IEDs using relatively cheap hardware is very interesting, as it will increase the number of educational and research institutions as well as companies that can use this technology. Some of the potential applications that can be developed using the concepts described in this paper are listed as follows: • Testing the full fuctions of IEDs by means of the analog waveforms of the voltage and current, including six or twelve analog output channels at standard levels (−10 to 10 V), eight digital inputs, and eight digital outputs. This could be achieved using dedicated PCI/PCIe cards for this job. In conjunction with a more powerfull processor, it would be possible to dramatically reduce the latency and thus be adequate for the testing of IEDs.

•
Testing full digital relays that use IEC-61850 protocols. It is possible to use the network interface to exchange data by means of IEC-61850 protocols such as sampled values and GOOSE. For this purpose, it is possible to include the precision time protocol (PTP) [25].

•
Combined tests, including any combination of the two previous items.

•
Playback of COMTRADE files containing voltage and current analog transient waveforms. This test in an open loop could be applied using recorded waveforms or ATP-generated waveforms, including all of the three previous items.

Conclusions
This study presented the implementation of an ATP-based real-time simulator called the ATP-RT to conduct HiL testing on IEDs or relays. The simulator was implemented using the minimum possible hardware requirements on a conventional PC with a GNU/Linux OS with a real-time kernel by means of ATP foreign models programmed in the standard C language. The sound card and the parallel port of the PC were used as I/O interfaces for the simulator. The sound card DAC was programmed for use as two analog outputs using the PortAudio library, and the parallel port acted as a digital input and output.
This study demonstrated the possibility of conducting real-time HiL tests at the signal level for a commercial IED using the developed ATP-RT simulator. Several tests consisting of generating and receiving signals in real time were conducted with a simulation step size of 100 µs, which is twice the 50 µs interval used in RTDS simulations. Additionally, the ATP-RT had an additional latency of 8 ms compared with the RTDS when receiving the trip and reclosing signals through the parallel port. Even though real CBs take a few dozen milliseconds to open, the total latency could be a problem for this type of application. However, this work shows the viability for developing a real-time simulator based on ATP that is capable of generating voltage signals corresponding to the waveforms of simulated voltage and currents. Since the signals generated by the developed ATP-RT range from −1.5 to 1.5 V, tests can be conducted on IED relays at conventional input levels by means of amplifiers.
The electrical system used in this study was not complex, and a 100 µs simulation step was achieved. The hardware used to develop the simulator was simple and did not require hardware other than a PC. The system enabled real-time simulations with the help of ATP and ATP foreign models using commercial PCs with a GNU/Linux OS and a real-time kernel. Of course, better results could be obtained with a more powerful computer configuration in addition to dedicated DAC cards and dedicated digital I/O cards. Including this hardware, the total cost will be much less than commercial real-time simulators. For the purpose of simulating small systems, the methodology described here using this type of test with a well-known software such as ATP could be made easily accessible. The potential applications were described, from which it is possible to ascertain that complex tests requiring the use of real-time simulators such as auto-reclosing (three-phase and single-phase) can be conducted, while these tests cannot be conducted by means of conventional relay testers.

Conflicts of Interest:
The authors declare no conflicts of interest.