24th International Conference on Electricity Distribution Glasgow, 12-15 June 2017
Paper 1175
A CO-SIMULATION APPROACH USING POWERFACTORY AND
MATLAB/SIMULINK TO ENABLE VALIDATION OF DISTRIBUTED CONTROL
CONCEPTS WITHIN FUTURE POWER SYSTEMS
K. Johnstone, S. M. Blair, M. H. Syed, A. Emhemed & G. M. Burt T. I. Strasser
University of Strathclyde – UK AIT Austrian Institute of Technology – Austria
[Link]@[Link] [Link]@[Link]
ABSTRACT developed and prototyped within MATLAB/Simulink,
their performance is being appraised with test power
In power network analysis it is increasingly desirable to systems modelled within DIgSILENT PowerFactory. Co-
implement controller and power systems models within simulation promises effective means of cooperation
different software environments. This stems from, among between smart grid controller developers and power
other things, an increasing influence of new and systems laboratories conducting validation studies,
distributed control functions within smart grids and a however conventional approaches [7] for co-simulation
growing influence of market operations. The computation have been found to be ineffective due to the complexity
time resulting from use of multiple simulation and abundance of controller models which must be
environments can cause significant delays and constrain integrated. As demonstrated in this paper, this would
the number of scenarios considered. This paper result in unacceptably long simulation run times.
introduces and compares several techniques for Whereas the design and development of advanced control
integrating external control system models into power schemes for future power systems is covered by
systems models for time domain simulations. In ELECTRA IRP, a more formalized and holistic
particular, a new technique is reported in this paper for validation approach covering power systems, control, and
PowerFactory-MATLAB/Simulink co-simulation communications issues are necessary before bringing
interfaces, which offers a significant advantage over such new approaches to the field, the ERIGrid project [8]
alternative methods in terms of the reduction in addresses this need by providing a formalized description
simulation runtimes and flexibility for the end user. of test scenarios as well as corresponding enhanced
validation methods for smart grid systems (including co-
INTRODUCTION simulation, hardware-in-the-loop and laboratory
Realistic, large-scale validation of future power system experiments).
operation is expected to require increased collaboration This paper analyses several methods for PowerFactory-
between specialized researchers and advanced laboratory MATLAB/Simulink integration in terms of the
facilities. The test systems may be complex and control complexity to the user and the impact on simulation run
algorithms increasingly distributed, requiring the time, and presents a new coupling method. This method
contribution from different organizations and the use of allows the engineer to run a compiled version of a
multiple software packages and programming languages controller developed in Simulink from within
during development and testing. In particular, where PowerFactory directly, significantly reducing the
complex controller models are required to be developed computational overhead and therefore the simulation run
and tested, it may be advantageous to implement the time – without adding significant complexity to the user.
power system simulation and controller model in more This provides a mechanism for comprehensive distributed
capable and flexible software packages. However, it is control solutions to be tested and validated for a range of
not always possible for one simulation tool to provide all frequency and voltage disturbances.
the requirements for the validation of complex power TEST CASE AND MOTIVATION
systems with intelligent controls [1], [2]. This increases
the need for co-simulation techniques that provide a more A suitable base case for the development of co-simulation
powerful test environment. It is essential that the techniques was first identified as the example test system
integration and co-simulation of the control and power given within the DIgSILENT PowerFactory technical
systems developed in different packages is efficient, both tutorial. This example integrates a simple voltage control
in terms of reducing the complexity of interfacing the loop into the plant model of a synchronous generator.
packages by the user, and does not adversely affect the While relatively simple, the chosen test model and
simulation accuracy or cause prohibitively long network include representative characteristics of more
simulation run times [3]. complex models, such as multiple inputs and outputs,
The ELECTRA IRP project [4] has developed novel variable parameters, continuous states and multiple
approaches to control the frequency and voltage within a control model instances. The test case consists of two
future conceptual distributed power system architecture, synchronous generators connected through a tie line and a
called the “Web of Cells” (WoC) [5]. While new power single load connected at the same bus as one of the
system control methods [6] are often collaboratively generators, as indicated in Figure 1.
CIRED 2017 1/5
24th International Conference on Electricity Distribution Glasgow, 12-15 June 2017
Paper 1175
This is due to the fact that the conventional
PowerFactory-MATLAB/Simulink method requires that
the MATLAB program first be opened by PowerFactory,
and then a new instance of the Simulink model is opened
and simulated for each timestep of the simulation. This
causes a severe slowing of the process of co-simulating
the test network, rendering it impractical for more
Figure 1: Simple test system for co-simulation method testing.
realistic full scale studies. A method which eliminates
To illustrate the operation of the controller, an event is this bottleneck from the process, whilst not
simulated which causes a step increase of 20% reactive compromising the accuracy of the final results, is
power demand from the load in Figure 1, causing the required. This example deals only with a very simple
generators to increase their reactive power outputs to controller, with few inputs and a single output. Therefore,
compensate and support the network voltage. The voltage it can be expected that with more complex controller
controller which is implemented is a standard “VCO type models and multiple instances, or the parallel integration
16” excitation system, which exists as a black box model of several different controllers, the simulation time
within the PowerFactory software (specifically, a overhead will be rendered infeasible, especially when the
“.ElmVco__16” object). Simulation times noted in this user is required to carry out many simulations and
paper are averaged over five runs. Using a Python script iterations of study cases, for example during sensitivity
to perform the simulation and calculated the run time, a studies.
20 second simulation of the test system takes 0.2214
seconds to run with the “original” voltage controller ALTERNATIVE METHODS AND RESULTS
installed. A Simulink excitation system model (based on
the controller shown in Figure 2) is also available to use A number of alternative methods for co-simulation have
as a reference implementation, to allow the simulation been considered and each evaluated with the test system.
results to be compared with the “original” excitation Method 1: Native controller “re-implementation”
system.
It is possible to re-implement the Simulink model in
The output signal of the voltage controller (i.e. generator
PowerFactory using the native control system design
1 excitation voltage in per-unit) is used as the monitored
suite, known as DIgSILENT Simulation Language
variable in the testing and, in Figure 3, the simulation
(DSL). This method is dependent on the user being fluent
results are shown to be identical to the “original” model,
in the techniques required to build and implement control
however the simulation time is drastically increased – to
models using DSL. An advantage of this solution is that it
111.56 seconds, a factor of around 504.
is easier for the user to quickly make incremental changes
to the controller model and rapidly test these changes in
the simulation environment, when compared to the
“conventional co-simulation” approach. This solution
also does not require re-configuration of the MATLAB
interface script whenever new variables or signals are
created within the model – an extra step which adds to
the implementation time and creates opportunities for
Figure 2: Block diagram of the voltage controller [7]. errors to appear. The other key advantage of re-
implementation of the model in DSL is that the user has
full access to the time series data for all of the internal
variables and signals of the controller during the
simulation. The MATLAB approach does not allow this
visibility of internal signals, instead treating the controller
model as a black box, which makes the debugging of
problems in the controller significantly more challenging.
However, in projects where a large number of control
functions have been implemented in Simulink, perhaps
by an external partner, it may prove costly and infeasible
to carry out the re-implementation process. For
comparison, the simulation time for the case where the
controller model is re-implemented in PowerFactory
using DSL is 0.2394 seconds, which is slightly longer
than the “original” case but still a factor of 466 faster
than the “conventional co-simulation” case.
Figure 3: “original” vs. “conventional co-simulation” cases.
CIRED 2017 2/5
24th International Conference on Electricity Distribution Glasgow, 12-15 June 2017
Paper 1175
Method 2: Dynamic-Link Library (DLL) run specifies the particular DLL file derived from an original
externally model). Two different approaches have been compared:
firstly with the DLL file derived from the re-implemented
The Simulink Coder toolbox has functionality to
PowerFactory “DSL” version of the controller, and
automatically generate an efficient C code representation
secondly with the DLL file derived from the Simulink
of a Simulink model [9]. This code can be used to
version of the controller.
compile a Dynamic-Link Library (DLL) which
Method 3a: DLL derived from DSL model
implements the original Simulink model. The
PowerFactory allows the user to automatically create a
“conventional co-simulation” approach (as described in
compiled version of any DSL model which has been built
the standard co-simulation approach from the
within the program itself. The model can be compiled in
PowerFactory User Manual) can be modified to interface
line with the instructions given in the User Manual,
with a DLL file, rather than with the Simulink model, i.e.,
resulting in a DLL file which can be used in the
PowerFactory’s link with MATLAB, via a script file,
subsequent time domain simulations. As shown in Figure
calls a DLL version of the controller model instead of a
5, further work is required to refine the calculation of the
Simulink version on each timestep. This method has the
initial conditions of the controller (because PowerFactory
advantage of still giving the user access to the MATLAB
handles the calculation of initial conditions differently
scripting environment for programming flexibility and
between internal and external models); however it can be
any data processing that they would like to perform,
seen that the controller model almost recovers to the
external to PowerFactory, during and after the simulation
nominal value during the event (Figure 6) and the results
runtime. However, the method also requires the user to be
then are in agreement with the “original” controller in the
familiar enough with MATLAB scripting to be able to
steady state (Figure 7). Despite the DLL file being
perform some significant changes to the .m file and adapt
derived from the DSL model described in the “re-
the code so that MATLAB runs the DLL instead of the
implement in DSL” case, these results show a marked
Simulink model in the simulation. However, this process
improvement in the accuracy of the results over the
could potentially be automated using a script, which
previous case. The simulation time for this method
mitigates this drawback.
The simulation time for this method was 9.97 seconds,
which is a factor of 45 times slower than the “original”
model implementation, but still 11.2 times faster than the
“conventional co-simulation” approach. This is due to the
fact that PowerFactory must still open the MATLAB
program, which then performs each timestep by running
the DLL file on each time step. As can be seen from
Figure 4, further development of this technique is
required to refine the accuracy of the results; however it
is clear that the technique does provide marked benefits
in terms of simulation run time.
Method 3: DLL run internally
The DLL file can also be referenced and run directly
from within PowerFactory, as an “.ElmDsl” object
(making reference to a block definition, where the user Figure 5: Results of “DLL from DSL” test case.
Figure 4: Results from “DLL run externally” test case. Figure 6: Deviation during event.
CIRED 2017 3/5
24th International Conference on Electricity Distribution Glasgow, 12-15 June 2017
Paper 1175
Figure 7: Results converge in steady state. Figure 8: Results of “.dll from Simulink” test case.
was0.2484 seconds, which takes 1.12 times as long as the
“original” model implementation, but is 449 times faster
than the “conventional co-simulation” approach.
Method 3b: DLL derived from Simulink model
It is likely that a power system analyst using
PowerFactory will not be immediately able or willing to
re-implement a controller model that may have been
developed by another user or users in the Simulink
environment. It may not be necessary to monitor the
internal signals of the controller model that has been
provided and it is therefore appropriate to simply
implement the finished controller – but avoiding the
lengthy simulation times that are inherent in the
“conventional co-simulation” approach from the User
Manual. The method which achieves these goals includes
the following general steps: Figure 9: Deviation which occurs during event.
1. Use Simulink Coder to generate a C code
implementation of the Simulink model, using the
Embedded Real-time Target (ERT). The Simulink
model must use the same timestep as the
PowerFactory model (as for Method 2).
2. Create an empty PowerFactory DSL, with the same
number of inputs and outputs as the Simulink model.
Use PowerFactory to automatically generate C code
representation of the DSL and a Visual Studio
project (as for Method 3a).
3. Add the Simulink Coder C code to the generated
Visual Studio project. Replace the contents of the
Initialise() and EvaluateEquations() functions with
calls to the appropriate Simulink Coder functions,
and map the Simulink inputs and outputs to the
PowerFactory variables. Figure 10: Results converge in steady state.
4. Compile the project as a DLL, and access the DLL
The simulation time for this study case was 0.3898
file from within PowerFactory.
seconds, a factor of 1.76 times that of “original” case, but
Figure 8 to Figure 10 show the results for this study case
importantly still approximately 286 times faster than the
in different levels of detail. It can be seen that the results
“conventional co-simulation” case.
match up well, however there is a slight deviation
between the study case and the base case around the
event, while the initial condition and the final value are DISCUSSION
entirely aligned with the base case. This error is likely to As the needs of power system analysts tend towards the
be eradicated with further development of the technique. use of a more diverse set of specialist controller system
CIRED 2017 4/5
24th International Conference on Electricity Distribution Glasgow, 12-15 June 2017
Paper 1175
modelling and network analysis tools, and reliance on the Horizon 2020 Program (H2020/2014-2020) under project
successful integration and co-simulation between these “ERIGrid” (Grant Agreement No. 654113). Further
different tools, it is vitally important that usability and information is provided at [Link] and
computational efficiency are ensured. This paper [Link].
describes several different approaches for co-simulation.
The packages PowerFactory and MATLAB/Simulink REFERENCES
have been used for illustration in this paper and three
alternative co-simulation methods have been compared to [1] A. Latif, et al. “An Alternative PowerFactory
two benchmark scenarios. By producing a DLL version Matlab Coupling Approach”, International
of the controller, the user can then choose to interface Symposium on Smart Electric Distribution Systems
with MATLAB and have it run the DLL file, giving the and Technologies (EDST), Vienna, Austria, Sept. 8-
flexibility provided by still being able to use the 11, 2015.
MATLAB scripting language for further data analysis. [2] F. M. Gonzalez-Longatt, 2014, PowerFactory
Alternatively, the MATLAB interface can be discarded Applications for Power System Analysis, Chapter
entirely by using PowerFactory run the DLL file directly. 15, Springer, 343-366.
This recommended method, which has been introduced in [3] T. Strasser et al. “Towards Holistic Power
this paper, has proved successful by allowing an Distribution System Validation and Testing – An
alternative technique for a power system control element Overview and Discussion of Different Possibilities”,
designed in MATLAB/Simulink to be integrated into a in Cigré Session 46 – Set of Papers, pp. 1-10, Paris,
DIgSILENT PowerFactory test power system, without France, Aug. 21-26, 2016.
the need to interface the two packages during the [4] European Liaison on Electricity Committed
simulation. The method improves on the conventional co- Towards long-term Research Activity Integrated
simulation approach described in the PowerFactory User Research Programme, [Link]
Manual by significantly reducing the time domain [5] L. Martini, et al., “ELECTRA IRP approach to
simulation runtimes, while maintaining accuracy of voltage and frequency control for future power
simulation results. These gains in simulation runtime systems with high DER penetrations”, in 23rd
have been achieved by having the entire simulation run International Conference on Electricity Distribution
within PowerFactory – using DLL calls where necessary CIRED, pp.1-4, Lyon, France, June 15-18, 2015.
– and therefore cuts out the lengthy process of running a [6] E. Guillo Sansano, et al. “Transitioning from
new instance of the controller in Simulink in each centralized to distributed control: using SGAM to
timestep. support a collaborative development of web of cells
architecture for real time control”, CIRED
CONCLUSION Workshop, Helsinki, Finland, June 14-15, 2016.
[7] DIgSILENT PowerFactory 15, "User Manual",
With relatively little work required by the user, a DIgSILENT GmbH, 2015.
controller built originally in Simulink can be integrated in [8] European Research Infrastructure supporting Smart
PowerFactory with virtually no penalty in terms of Grid Systems Technology Development, Validation
simulation times when compared with the case when the and Roll Out, [Link]
controller is re-implemented natively in PowerFactory. It [9] A. J. Roscoe, S. M. Blair, G. M. Burt,
is clear that eradicating the computationally intensive “Benchmarking and optimisation of Simulink code
step of running a complete Simulink controller model on using Real-Time Workshop and Embedded Coder
each timestep brings significant benefits, a lesson which for inverter and microgrid control applications”, 44 th
might extend readily to other power system analysis International Universities Power Engineering
software. While the test system is relatively simple in this Conference (UPEC), Glasgow, UK, Sept 1-4, 2009.
case, it is expected that the benefits of the technique, in
terms of simulation times and convenience, will be
compounded in applications with large test systems and
many controller models – a common feature of research
on future distributed control systems and networks with
large numbers of decentralised devices – yielding
significant reductions in time and cost to users.
Acknowledgments
This work is partly supported by the European
Community's Seventh Framework Program (FP7/2007-
2013) under project “ELECTRA IRP” (Grant Agreement
No. 609687) as well as by the European Community’s
CIRED 2017 5/5