-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation_with_inputs.py
89 lines (81 loc) · 2.91 KB
/
simulation_with_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''Example of a PowerFactory simulation
This example demonstrate how to simulate a model in PowerFactory.
The example uses CSV files as inputs at the PCC. They are either
generated by wavegn or used directly.
'''
import sys
import os
sys.path.append('.')
import pfpy.models as models
import matplotlib.pyplot as plt
folder_path = os.path.abspath('./examples/data/tmp/')
# Defining model outputs
outputs = {
'ElmRes' : 'DemoSimulation',
'variables': {
'SourcePCC.ElmVac': ['m:Psum:bus1','m:Qsum:bus1','m:u:bus1','m:phiu1:bus1']
}
}
generate = True
if generate:
# Defining model inputs
inputpath = os.path.join(folder_path, 'signal_PCCVoltFile.csv')
inputs = [
# VOLTAGE INPUT
{'network' : 'MV_EUR',
'ElmFile' : 'PCCVolt',
'source' : 'generate',
'filepath' : inputpath,
'wave_specs' : {
'type' : 'dip', 'tstart' : 0,
'tstop' : 10, 'step' : 0.01,
'deltat' : 0.1, 'deltay' : 0.2,
'y0' : 1, 't0' : 1}
},
# FREQUENCY INPUT
{'network' : 'MV_EUR',
'ElmFile' : 'PCCFreq',
'source' : 'generate',
# 'filepath' : filepath can be also left undefined
'wave_specs' : {
'type' : 'const',
'y0' : 1,
'tstart' : 0,
'tstop' : 10,
'step' : 0.01}
}
]
else:
input_path_frequency = os.path.abspath('./examples/data/input_signals/pf_freq.csv')
input_path_voltage = os.path.abspath('./examples/data/input_signals/pf_volt.csv')
inputs = [{'network' : 'MV_EUR', # VOLTAGE INPUT
'ElmFile' : 'PCCVolt',
'source' : 'ext_file',
'filepath' : input_path_voltage,
},
{'network' : 'NET_WITH_ELMFILE', # FREQUENCY INPUT
'ElmFile' : 'PCCFreq',
'source' : 'ext_file',
'filepath' : input_path_frequency
}
]
# Instantiating the model and simulating
model = models.PowerFactoryModel(project_name = 'PFPY_DEMO',
study_case='01 - Base Case', networks=['MV_EUR'],
outputs = outputs, inputs = inputs)
results = model.simulate(0, 10, 0.01)
# Plotting the simulation results
fig, axs = plt.subplots(2,2)
axs[0,0].plot(results['SourcePCC.ElmVac\\m:Qsum:bus1'])
axs[0,0].set_xlabel('Time (s)')
axs[0,0].set_ylabel('Reactive Power')
axs[0,1].plot(results['SourcePCC.ElmVac\\m:Psum:bus1'])
axs[0,1].set_xlabel('Time (s)')
axs[0,1].set_ylabel('Active Power')
axs[1,0].plot(results['SourcePCC.ElmVac\\m:u:bus1'])
axs[1,0].set_xlabel('Time (s)')
axs[1,0].set_ylabel('Voltage')
axs[1,1].plot(results['SourcePCC.ElmVac\\m:phiu1:bus1'])
axs[1,1].set_xlabel('Time (s)')
axs[1,1].set_ylabel('Phase Angle')
plt.show()