In [1]:
import sys
sys.path.append(r"C:\DigSILENT15p1p7\python") # set the path to python folder inside your
# digsilent instalation folder
# import PowerFactory module
import powerfactory
In [2]:
# start PowerFactory in engine mode
app = powerfactory.GetApplication('jmmauricio','') # change 'jmmauricio' by
# your user name and '' by your password
# activate project
project = app.ActivateProject("Nine Bus System") # change "Nine Bus System" by
# the name of your project
prj = app.GetActiveProject() # active project instance
print('prj: {:s}'.format(prj)) # to check if the project is opened properly
ldf = app.GetFromStudyCase("ComLdf") # Load flow
ini = app.GetFromStudyCase('ComInc') # Dynamic initialization
sim = app.GetFromStudyCase('ComSim') # Transient simulations
In [3]:
buses = app.GetCalcRelevantObjects("*.ElmTerm")
syms = app.GetCalcRelevantObjects("*.ElmSym")
loads = app.GetCalcRelevantObjects("*.ElmLod")
elmres = app.GetFromStudyCase('Results.ElmRes')
# channels for buses
for bus in buses:
elmres.AddVars(bus,
'm:u', # voltage ('m:u')
'm:phiu', # angle ('m:phi')
'm:fehz', # frequency ('m:fehz')
)
# channels for synchronous machines
for sym in syms:
elmres.AddVars(sym,
's:ve', # p.u Excitation Voltage
's:pt', # p.u. IN Turbine Power
's:ut', # p.u. OUT Terminal Voltage
's:ie', # p.u. OUT Excitation Current
's:xspeed',# p.u. OUT Speed
's:xme', # p.u. OUT Electrical Torque
's:xmt', # p.u. OUT Mechanical Torque
's:cur1', # p.u. OUT Positive-Sequence Current, Magnitude
's:P1', # MW OUT Positive-Sequence, Active Power
's:Q1', # Mvar OUT Positive-Sequence, Reactive Power
'c:firel', # deg Rotor angle with reference to reference machine angle
)
# channels for loads
for load in loads: # creating channels for:
elmres.AddVars(load, 'n:u1:bus1', # voltage ('m:u')
'm:I1:bus1', # current ('s:P1')
'm:Psum:bus1', # active power ('s:P1')
'm:Qsum:bus1') # reactive power ('s:Q1')
In [4]:
events_folder = app.GetFromStudyCase('IntEvt'); # to get events folder
evt1 = events_folder.CreateObject('EvtSwitch', 'gen 1 trip event'); # generator switch
# event is created here
evt1[0].p_target = syms[2] # event target is the second synchronous generator
evt1[0].time = 1.0
#evt1.clear()
#evt2.clear()
In [5]:
#print(evt1[0].time)
#print(evt2)
In [6]:
ldf.iopt_net = 0
ldf.Execute()
Out[6]:
In [7]:
ini.iopt_dtgrd = 0.001 # step size
ini.Execute()
Out[7]:
In [8]:
sim.tstop = 15.0
sim.Execute()
Out[8]:
In [1]:
comres = app.GetFromStudyCase('ComRes');
comres.iopt_csel = 0
comres.iopt_tsel = 0
comres.iopt_locn = 2
comres.ciopt_head = 1
comres.pResult=elmres
comres.f_name = r'C:\Users\jmmauricio\hola.txt' # change 'C:\Users\jmmauricio\hola.txt'
# with your path
comres.iopt_exp=4
comres.Execute()
In [10]:
evt1.clear()
In [2]:
import pypstools.digsilent_simulation as ds
res = ds.ds_2_dict(r'C:\Users\jmmauricio\hola.txt')
print(res['sys'])
In [12]:
%matplotlib inline
import matplotlib.pyplot as plt
# create figure and axis instances
fig, (ax0, ax1) = plt.subplots(nrows=2, figsize=(10, 10))
t = res['sys']['time'] # simulation time vector
# axe 1
ax0.plot(t,res['sym']['G1']['speed']['data'], label='G1')
ax0.plot(t,res['sym']['G2']['speed']['data'], label='G2')
ax0.plot(t,res['sym']['G3']['speed']['data'], label='G3')
ax0.legend(loc='best')
ax0.grid(True)
ax0.set_ylabel('Speed (p.u.)')
ax0.set_xlim((0,t[-1]))
# ax 2
ax1.plot(t,res['sym']['G1']['p']['data'], label='G1')
ax1.plot(t,res['sym']['G2']['p']['data'], label='G2')
ax1.plot(t,res['sym']['G3']['p']['data'], label='G3')
ax1.legend(loc='best')
ax1.grid(True)
ax1.set_ylabel('Ative Power (MW)')
ax1.set_xlim((0,t[-1]))
ax1.set_xlabel('Time (s)')
Out[12]:
In [13]:
# create figure and axis instances
fig, (ax0, ax1) = plt.subplots(nrows=2, figsize=(10, 10))
t = res['sys']['time'] # simulation time vector
# axe 1
for load in res['sys']['loads']:
ax0.plot(t,res['load'][load]['n:u1:bus1 in p.u.']['data'], label=load)
ax0.legend(loc='best')
ax0.grid(True)
ax0.set_ylabel('Volatage (p.u.)')
ax0.set_xlim((0,t[-1]))
# ax 2
for load in res['sys']['loads']:
ax1.plot(t,res['load'][load]['p']['data'], label=load)
ax1.legend(loc='best')
ax1.grid(True)
ax1.set_ylabel('Ative Power (MW)')
ax1.set_xlim((0,t[-1]))
ax1.set_xlabel('Time (s)')
Out[13]:
In [14]:
# create figure and axis instances
fig, (ax0) = plt.subplots(nrows=1, figsize=(10, 8))
t = res['sys']['time'] # simulation time vector
buses = ['Fault',
'Bus 1',
'Bus 2',
'Bus 3',
'Bus 7',
'Bus 8',
'Bus 9']
# axe 1
for bus in buses:
ax0.plot(t,res['bus'][bus]['m:u in p.u.']['data'], label=bus)
ax0.legend(loc='best')
ax0.grid(True)
ax0.set_ylabel('Volatage (p.u.)')
ax0.set_xlim((0,t[-1]))
ax0.set_xlabel('Time (s)')
Out[14]:
In [ ]: