Commit a7261036 authored by Markus Mirz's avatar Markus Mirz
Browse files

update dpsim results path in notebooks

parent 6c5405ff
%% Cell type:markdown id: tags:
# Dynamic WSCC 9-bus System with Switch
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
WSCC-9bus_CIM_Dyn_Switch ${TOP}/Examples/CIM/grid-data/WSCC-09/WSCC-09_RX_Dyn/*.xml
```
%% Cell type:code id: tags:
``` python
import villas.dataprocessing.readtools as rt
import villas.dataprocessing.plottools as pt
from villas.dataprocessing.timeseries import TimeSeries as ts
import matplotlib.pyplot as plt
```
%% Cell type:markdown id: tags:
## Simulation
%% Cell type:code id: tags:
``` python
path = 'logs/WSCC-9bus_dyn_switch/'
logName = 'WSCC-9bus_dyn_switch'
logFilename = path + logName + '.csv'
print(logFilename)
ts_dpsim = rt.read_timeseries_dpsim(logFilename)
phasors = ts.phasors(ts_dpsim)
```
%% Cell type:markdown id: tags:
### Phasors at last time step in per unit
%% Cell type:code id: tags:
``` python
nominal_voltages = {'v1': 16500, 'v2': 18000, 'v3': 13800,
'v4': 230000, 'v5': 230000, 'v6': 230000,
'v7': 230000, 'v8': 230000, 'v9': 230000}
for node, nom_voltage in nominal_voltages.items():
print(node + ': ' + str(phasors[node]['abs'].values[0] / nom_voltage) + '<' + str(phasors[node]['phase'].values[0]))
```
%% Cell type:markdown id: tags:
### Plot node voltages
%% Cell type:code id: tags:
``` python
plt.plot(phasors['v1']['abs'].time, phasors['v1']['abs'].values)
plt.plot(phasors['v2']['abs'].time, phasors['v2']['abs'].values)
plt.plot(phasors['v3']['abs'].time, phasors['v3']['abs'].values)
plt.ylim([0,20000])
plt.figure()
plt.plot(phasors['v4']['abs'].time, phasors['v4']['abs'].values)
plt.plot(phasors['v5']['abs'].time, phasors['v5']['abs'].values)
plt.plot(phasors['v6']['abs'].time, phasors['v6']['abs'].values)
plt.plot(phasors['v7']['abs'].time, phasors['v7']['abs'].values)
plt.plot(phasors['v8']['abs'].time, phasors['v8']['abs'].values)
plt.plot(phasors['v9']['abs'].time, phasors['v9']['abs'].values)
plt.ylim([0,240000])
```
%% Cell type:markdown id: tags:
### Generator Speed
%% Cell type:code id: tags:
``` python
plt.plot(ts_dpsim['wr_1'].time, ts_dpsim['wr_1'].values)
plt.plot(ts_dpsim['wr_2'].time, ts_dpsim['wr_2'].values)
plt.plot(ts_dpsim['wr_3'].time, ts_dpsim['wr_3'].values)
plt.xlabel('time (s)')
plt.ylabel('mechanical speed (rad/s)')
plt.xlim([0,2])
#plt.savefig('wscc_9bus_fault_gen_speed.pdf')
```
%% Cell type:markdown id: tags:
## Validation
%% Cell type:code id: tags:
``` python
# read Simulink log file
import os
import urllib.request
if not os.path.exists('reference-results'):
os.mkdir('reference-results')
url = 'https://git.rwth-aachen.de/acs/public/simulation/dpsim-results/raw/master/WSCC-9bus/WSCC-9bus_dyn_switch_mod_inertia.csv'
url = 'https://git.rwth-aachen.de/acs/public/simulation/dpsim/dpsim-results/raw/master/WSCC-9bus/WSCC-9bus_dyn_switch_mod_inertia.csv'
local_file = 'reference-results/WSCC-9bus_dyn_switch.csv'
urllib.request.urlretrieve(url, local_file)
ts_sl = rt.read_timeseries_simulink(local_file)
```
%% Cell type:code id: tags:
``` python
import numpy as np
assert np.all(ts_sl['wr_1'].values - ts_dpsim['wr_1'].values < 0.001)
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
# Dynamic WSCC 9-bus System with Switch Event
%% Cell type:markdown id: tags:
**Authors**:
- Markus Mirz <mmirz@eonerc.rwth-aachen.de>
- Steffen Vogel <stvogel@eoner.rwth-aachen.de>
This Jupyter Notebook shows a simple dynamic phasor simulation of the WSCC-9bus benchmark model.
The grid data is loaded from CIM-XML files, while simulation results are stored in CSV files and plotted via Matplotlib
%% Cell type:code id: tags:
``` python
%gui asyncio
#%matplotlib widget
import dpsim
from dpsim.Event import Event
import glob
import asyncio
import matplotlib.pyplot as plt
```
%% Cell type:markdown id: tags:
### Loading Grid Topology from CIM-XML Model
%% Cell type:code id: tags:
``` python
name = 'WSCC-9bus_dyn_switch'
files = glob.glob('../../CIM/grid-data/WSCC-09/WSCC-09_RX_Dyn/*.xml') + \
glob.glob('Examples/CIM/grid-data/WSCC-09/WSCC-09_RX_Dyn/*.xml')
print(files)
system = dpsim.load_cim(name, files, frequency=60)
```
%% Cell type:markdown id: tags:
### Rending Network Topology via Graphiz/SVG
We use Graphviz to render the network model into a layouted SVG figure
%% Cell type:code id: tags:
``` python
system
```
%% Cell type:markdown id: tags:
### Extending Network with Switch and Load
%% Cell type:markdown id: tags:
Here we add a new switch to Bus 9 that is triggered at 0.05s. This component could be added permantely to the CIM model as well using tools like Pintura.
%% Cell type:code id: tags:
``` python
## Switch
sw = dpsim.dp.ph1.Switch("Switch")
sw.R_open = 1e9
sw.R_closed = 0.1
sw.is_closed = False
## Load
load = dpsim.dp.ph1.PQLoadCS("Switched Load")
load.V_nom = 230950
load.P = 30000000
load.Q = 0
## Topology
bus9 = system.nodes["BUS6"]
gnd = dpsim.dp.Node.GND()
sw.connect([ bus9, gnd ])
system.add_component(sw)
```
%% Cell type:code id: tags:
``` python
system
```
%% Cell type:markdown id: tags:
### Running Simulation
The actual simulation is done by the C++ DPsim solver. Python is just used for configuration, scripting and analysis
%% Cell type:code id: tags:
``` python
sim = dpsim.Simulation(name, system, timestep=0.0001, duration=2, init_steady_state=True, pbar=True)
#system.components['GEN3'].inertia *= 2
sw.is_closed = False
sim.add_event(0.2, sw, 'is_closed', True)
logger = dpsim.Logger(name)
sim.add_logger(logger)
for i in range(1,4):
logger.log_attribute(system.components['GEN%d' % i], 'w_r')
for node in system.nodes:
logger.log_attribute(system.nodes[node], 'v')
sim.start()
```
%% Cell type:markdown id: tags:
## Analysis
### Read log files and list all column names
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import villas.dataprocessing.plottools as pt
import villas.dataprocessing.readtools as rt
from villas.dataprocessing.timeseries import TimeSeries as ts
import numpy as np
res = rt.read_timeseries_dpsim('logs/WSCC-9bus_dyn_switch.csv')
```
%% Cell type:markdown id: tags:
### Phasors at first time step
%% Cell type:code id: tags:
``` python
phasors = ts.phasors(res)
for node, phasor in phasors.items():
if 'v' in node:
print(node + ': ' + str(phasor['abs'].values[0]) + '<' + str(phasor['phase'].values[0]))
```
%% Cell type:markdown id: tags:
### Phasors at last time step
%% Cell type:code id: tags:
``` python
for node, phasor in phasors.items():
if 'v' in node:
print(node + ': ' + str(phasor['abs'].values[-1]) + '<' + str(phasor['phase'].values[-1]))
```
%% Cell type:markdown id: tags:
### Phasors at last time step in per unit
%% Cell type:code id: tags:
``` python
nominal_voltages = {
'BUS1.v': 16.5e3,
'BUS2.v': 18e3,
'BUS3.v': 13.8e3,
'BUS4.v': 230e3,
'BUS5.v': 230e3,
'BUS6.v': 230e3,
'BUS7.v': 230e3,
'BUS8.v': 230e3,
'BUS9.v': 230e3
}
plt.figure(1)
for node, nom_voltage in nominal_voltages.items():
mag = phasors[node]['abs'].values[0] / nom_voltage
pha = phasors[node]['phase'].values[0]
print(node + ': ' + str(mag) + '<' + str(pha))
plt.polar([0, pha / 180 * np.pi], [0, mag], marker='o', label=node)
plt.show()
```
%% Cell type:markdown id: tags:
### Plot node phases
%% Cell type:code id: tags:
``` python
for i in range(1,9):
pt.plot_timeseries(20, phasors['BUS%d.v' % i]['phase'])
```
%% Cell type:markdown id: tags:
### Plot node voltages
%% Cell type:code id: tags:
``` python
for i in range(4,9):
pt.plot_timeseries(10, phasors['BUS%d.v' % i]['abs'])
for i in range(1,4):
pt.plot_timeseries(11, phasors['BUS%d.v' % i]['abs'])
plt.xlim(0.0, 0.06)
```
%% Cell type:code id: tags:
``` python
res['GEN1.w_r'].label = 'GEN1 wr'
res['GEN2.w_r'].label = 'GEN2 wr'
res['GEN3.w_r'].label = 'GEN3 wr'
pt.plot_timeseries(1, res['GEN1.w_r'])
pt.plot_timeseries(1, res['GEN2.w_r'])
pt.plot_timeseries(1, res['GEN3.w_r'])
plt.xlabel('time (s)')
plt.ylabel('mechanical speed (rad/s)')
```
%% Cell type:markdown id: tags:
## Validation
%% Cell type:code id: tags:
``` python
# read Simulink log file
import os
import urllib.request
if not os.path.exists('reference-results'):
os.mkdir('reference-results')
url = 'https://git.rwth-aachen.de/acs/public/simulation/dpsim-results/raw/master/WSCC-9bus/WSCC-9bus_dyn_switch.csv'
url = 'https://git.rwth-aachen.de/acs/public/simulation/dpsim/dpsim-results/raw/master/WSCC-9bus/WSCC-9bus_dyn_switch.csv'
local_file = 'reference-results/WSCC-9bus_dyn_switch.csv'
urllib.request.urlretrieve(url, local_file)
ts_sl = rt.read_timeseries_simulink(local_file)
```
%% Cell type:code id: tags:
``` python
import numpy as np
assert np.all(ts_sl['GEN1.w_r'].values - res['GEN1.w_r'].values < 0.001)
```
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment