Commit 3962f1a1 authored by Markus Mirz's avatar Markus Mirz
Browse files

update examples with new grid data path


Former-commit-id: 5019f9f7
parent 2f332841
......@@ -40,7 +40,7 @@ int main(int argc, char** argv){
"Rootnet_FULL_NE_06J16h_EQ.xml",
"Rootnet_FULL_NE_06J16h_SV.xml",
"Rootnet_FULL_NE_06J16h_TP.xml"
}, "Examples/CIM/CIGRE_MV_NoTap", "CIMPATH");
}, "Examples/CIM/grid-data/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -68,7 +68,7 @@ int main(int argc, char** argv){
"Rootnet_FULL_NE_06J16h_EQ.xml",
"Rootnet_FULL_NE_06J16h_SV.xml",
"Rootnet_FULL_NE_06J16h_TP.xml"
}, "Examples/CIM/CIGRE_MV_NoTap", "CIMPATH");
}, "Examples/CIM/grid-data/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -40,7 +40,7 @@ int main(int argc, char** argv){
"Rootnet_FULL_NE_13J16h_EQ.xml",
"Rootnet_FULL_NE_13J16h_SV.xml",
"Rootnet_FULL_NE_13J16h_TP.xml"
}, "Examples/CIM/IEEE_EU_LV_reduced", "CIMPATH");
}, "Examples/CIM/grid-data/IEEE_EU_LV/IEEE_EU_LV_reduced", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -48,7 +48,7 @@ int main(int argc, char** argv){
"Rootnet_FULL_NE_06J16h_EQ.xml",
"Rootnet_FULL_NE_06J16h_SV.xml",
"Rootnet_FULL_NE_06J16h_TP.xml"
}, "Examples/CIM/IEEE_EU_LV_reduced", "CIMPATH");
}, "Examples/CIM/grid-data/IEEE_EU_LV/IEEE_EU_LV_reduced", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX_Dyn", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX_Dyn", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX_Dyn", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX_Dyn", "CIMPATH");
}
else {
filenames = std::list<fs::path>(argv + 1, argv + argc);
......
......@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX", "CIMPATH");
//for (Int copies = 0; copies < 20; copies++) {
// for (Int threads = 0; threads <= 12; threads = threads+2)
......
......@@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX", "CIMPATH");
//for (Int copies = 0; copies < 10; copies++) {
// for (Int threads = 0; threads <= 12; threads = threads+2)
......
......@@ -123,7 +123,7 @@ int main(int argc, char *argv[]) {
"WSCC-09_RX_EQ.xml",
"WSCC-09_RX_SV.xml",
"WSCC-09_RX_TP.xml"
}, "Examples/CIM/WSCC-09_RX", "CIMPATH");
}, "Examples/CIM/grid-data/WSCC-09/WSCC-09_RX", "CIMPATH");
//for (Int copies = 0; copies < 10; copies++) {
// for (Int threads = 0; threads <= 12; threads = threads+2) {
......
%% Cell type:markdown id: tags:
# CIGRE MV Powerflow Solver Test
%% Cell type:markdown id: tags:
## Run simulation
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
CIGRE_MV_PowerFlowTest ${TOP}/Examples/CIM/CIGRE_MV_NoTap/*.xml
CIGRE_MV_PowerFlowTest ${TOP}/Examples/CIM/grid-data/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results/*.xml
```
%% Cell type:code id: tags:
``` python
from villas.dataprocessing.readtools import *
from villas.dataprocessing.timeseries import *
import villas.dataprocessing.validationtools as validationtools
import os
import urllib.request
```
%% Cell type:markdown id: tags:
## Read DPsim results
%% Cell type:code id: tags:
``` python
path = 'logs/'
logName = 'CIGRE-MV-NoTap'
dpsim_result_file = path + logName + '.csv'
ts_dpsim = read_timeseries_csv(dpsim_result_file)
# Fix for dpsim naming - TODO: unify dpsim notation in log file and update villas-dataprocessing accordingly
for ts,values in ts_dpsim.items():
values.name = values.name[:-2]
```
%% Cell type:markdown id: tags:
## Read NEPLAN results as reference
%% Cell type:code id: tags:
``` python
if not os.path.exists('reference-results'):
os.mkdir('reference-results')
url = 'https://git.rwth-aachen.de/acs/public/simulation/reference-results/raw/master/Neplan/ReferenceGrids/CIGRE_MV.rlf'
neplan_result_file = 'reference-results/CIGRE_MV.rlf'
urllib.request.urlretrieve(url, neplan_result_file)
print(neplan_result_file)
ts_NEPLAN = read_timeseries_NEPLAN_loadflow(neplan_result_file)
#print([ts_NEPLAN[i].name for i in range(len(ts_NEPLAN))])
```
%% Cell type:markdown id: tags:
## Comparison and assertion of results
%% Cell type:code id: tags:
``` python
net_name='CIGRE_MV_NoTap'
threshold=0.5
ts_NEPLAN_standardized=validationtools.convert_neplan_to_standard_timeseries(ts_NEPLAN)
#print([ts_NEPLAN_standardized[i].name for i in range(len(ts_NEPLAN_standardized))])
ts_dpsim_standardized=validationtools.convert_dpsim_to_standard_timeseries(ts_dpsim)
#print([ts_dpsim_standardized[i].name for i in range(len(ts_dpsim_standardized))])
res_err=validationtools.compare_timeseries(ts_NEPLAN_standardized,ts_dpsim_standardized)
validationtools.assert_modelica_results(net_name,res_err,threshold)
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
# IEEE LV Powerflow Solver Test
%% Cell type:markdown id: tags:
## Run simulation
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
IEEE_LV_PowerFlowTest ${TOP}/Examples/CIM/IEEE_EU_LV_reduced/*.xml
IEEE_LV_PowerFlowTest ${TOP}/Examples/CIM/grid-data/IEEE_EU_LV/IEEE_EU_LV_reduced/*.xml
```
%% Cell type:code id: tags:
``` python
from villas.dataprocessing.readtools import *
from villas.dataprocessing.timeseries import *
import villas.dataprocessing.validationtools as validationtools
import os
import urllib.request
```
%% Cell type:markdown id: tags:
## Read DPsim results
%% Cell type:code id: tags:
``` python
path = 'logs/'
logName = 'IEEE_EU_LV_reduced'
dpsim_result_file = path + logName + '.csv'
ts_dpsim = read_timeseries_csv(dpsim_result_file)
# Fix for dpsim naming - TODO: unify dpsim notation in log file and update villas-dataprocessing accordingly
for ts,values in ts_dpsim.items():
values.name = values.name[:-2]
```
%% Cell type:markdown id: tags:
## Read NEPLAN results as reference
%% Cell type:code id: tags:
``` python
if not os.path.exists('reference-results'):
os.mkdir('reference-results')
url = 'https://git.rwth-aachen.de/acs/public/simulation/reference-results/raw/master/Neplan/ReferenceGrids/IEEE_EU_LV.rlf'
neplan_result_file = 'reference-results/IEEE_EU_LV.rlf'
urllib.request.urlretrieve(url, neplan_result_file)
print(neplan_result_file)
ts_NEPLAN = read_timeseries_NEPLAN_loadflow(neplan_result_file)
# print([ts_NEPLAN[i].name for i in range(len(ts_NEPLAN))])
```
%% Cell type:markdown id: tags:
## Comparison and assertion of results
%% Cell type:code id: tags:
``` python
net_name='IEEE_EU_LV_reduced'
threshold=0.5
ts_NEPLAN_standardized=validationtools.convert_neplan_to_standard_timeseries(ts_NEPLAN)
#print([[ts_NEPLAN_standardized[i].name, ts_NEPLAN_standardized[i].values] for i in range(len(ts_NEPLAN_standardized))])
ts_dpsim_standardized=validationtools.convert_dpsim_to_standard_timeseries(ts_dpsim)
#print([[ts_dpsim_standardized[i].name, ts_dpsim_standardized[i].values] for i in range(len(ts_dpsim_standardized))])
res_err=validationtools.compare_timeseries(ts_NEPLAN_standardized,ts_dpsim_standardized)
validationtools.assert_modelica_results(net_name,res_err,threshold)
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
# WSCC 9-bus System Static Test
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
WSCC-9bus_CIM ${TOP}/Examples/CIM/WSCC-09_RX/*.xml
WSCC-9bus_CIM ${TOP}/Examples/CIM/grid-data/WSCC-09/WSCC-09_RX/*.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:
## Initialization
%% Cell type:code id: tags:
``` python
path = 'logs/WSCC-9bus/'
logName = 'WSCC-9bus_InitLeftVector'
logFilename = path + logName + '.csv'
print(logFilename)
ts_dpsim_init = rt.read_timeseries_dpsim(logFilename)
```
%% Cell type:markdown id: tags:
### Phasors at first time step
%% Cell type:code id: tags:
``` python
phasors_init = ts.phasors(ts_dpsim_init)
for node, phasor in phasors_init.items():
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_init.items():
print(node + ': ' + str(phasor['abs'].values[-1]) + '<' + str(phasor['phase'].values[-1]))
```
%% Cell type:markdown id: tags:
### Difference
%% Cell type:code id: tags:
``` python
for node, phasor in phasors_init.items():
print(node + ': ' + str(phasor['abs'].values[-1] - phasor['abs'].values[0]) + '<' + str(phasor['phase'].values[-1] - phasor['phase'].values[0]))
```
%% Cell type:markdown id: tags:
## Simulation
%% Cell type:code id: tags:
``` python
path = 'logs/WSCC-9bus/'
logName = 'WSCC-9bus'
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 phase
The phase at BUS9 (solution vector: node00007) is not initialized properly from the CIM powerflow data. Therefore, the steady-state initialization implemented in the MNA solver is executed first so that the initial phase at t=0 is already very close to the correct one.
Using PI-lines with parallel impedances to ground not only during the initialization but also the simulation or more accurate CIM load flow results would probably further improve the results because the values around BUS9 have still not converged completely.
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, phasors['v9']['phase'])
plt.ylim([2.10405, 2.1042])
```
%% Cell type:markdown id: tags:
The next plot is showing the same value, BUS9 phase during the initialization. The phase oscillation is larger than in the actual simulation.
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, phasors_init['n00007f00']['phase'])
plt.ylim([2.10405, 2.1042])
```
%% Cell type:markdown id: tags:
### Plot node voltages
%% Cell type:code id: tags:
``` python
for node, phasor in phasors.items():
print(node + ': ' + str(phasor['abs'].values[-1]) + '<' + str(phasor['phase'].values[-1]))
```
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, phasors['v1']['abs'])
pt.plot_timeseries(1, phasors['v2']['abs'])
pt.plot_timeseries(1, phasors['v3']['abs'])
pt.plot_timeseries(2, phasors['v4']['abs'])
pt.plot_timeseries(2, phasors['v5']['abs'])
pt.plot_timeseries(2, phasors['v6']['abs'])
pt.plot_timeseries(2, phasors['v7']['abs'])
pt.plot_timeseries(2, phasors['v8']['abs'])
pt.plot_timeseries(2, phasors['v9']['abs'])
plt.gca().axes.set_ylim([200000,240000])
```
%% Cell type:markdown id: tags:
### Assert Steady-State
%% Cell type:code id: tags:
``` python
for node, phasor in phasors.items():
abs_diff = phasor['abs'].values[-1] - phasor['abs'].values[0]
assert abs_diff < 20
phase_diff = phasor['phase'].values[-1] - phasor['phase'].values[0]
assert phase_diff < 0.001
print(node + ': ' + str(abs_diff) + '<' + str(phase_diff))
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
# Dynamic WSCC 9-bus System
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
WSCC-9bus_CIM_Dyn ${TOP}/Examples/CIM/WSCC-09_RX_Dyn/*.xml
WSCC-9bus_CIM_Dyn ${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:
## Initialization
%% Cell type:code id: tags:
``` python
path = 'logs/WSCC-9bus_dyn/'
logName = 'WSCC-9bus_dyn_InitLeftVector'
logFilename = path + logName + '.csv'
print(logFilename)
ts_dpsim_init = rt.read_timeseries_dpsim(logFilename)
```
%% Cell type:markdown id: tags:
### Phasors at first time step
%% Cell type:code id: tags:
``` python
phasors_init = ts.phasors(ts_dpsim_init)
for node, phasor in phasors_init.items():
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_init.items():
print(node + ': ' + str(phasor['abs'].values[-1]) + '<' + str(phasor['phase'].values[-1]))
```
%% Cell type:markdown id: tags:
### Difference
%% Cell type:code id: tags:
``` python
for node, phasor in phasors_init.items():
print(node + ': ' + str(phasor['abs'].values[-1] - phasor['abs'].values[0]) + '<' + str(phasor['phase'].values[-1] - phasor['phase'].values[0]))
```
%% Cell type:markdown id: tags:
## Simulation
%% Cell type:code id: tags:
``` python
path = 'logs/WSCC-9bus_dyn/'
logName = 'WSCC-9bus_dyn'
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 phase
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, phasors['v9']['phase'])
#plt.xlim(0,0.2)
```
%% Cell type:markdown id: tags:
### Plot node voltages
%% Cell type:code id: tags:
``` python
for node, phasor in phasors.items():
print(node + ': ' + str(phasor['abs'].values[-1]) + '<' + str(phasor['phase'].values[-1]))
```
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, phasors['v1']['abs'])
pt.plot_timeseries(1, phasors['v2']['abs'])
pt.plot_timeseries(1, phasors['v3']['abs'])
pt.plot_timeseries(2, phasors['v4']['abs'])
pt.plot_timeseries(2, phasors['v5']['abs'])
pt.plot_timeseries(2, phasors['v6']['abs'])
pt.plot_timeseries(2, phasors['v7']['abs'])
pt.plot_timeseries(2, phasors['v8']['abs'])
pt.plot_timeseries(2, phasors['v9']['abs'])
plt.ylim([200000,240000])
plt.xlim([0,0.1])
```
%% Cell type:code id: tags:
``` python
for node, phasor in phasors.items():
abs_diff = phasor['abs'].values[-1] - phasor['abs'].values[0]
assert abs_diff < 20
phase_diff = phasor['phase'].values[-1] - phasor['phase'].values[0]
assert phase_diff < 0.001
print(node + ': ' + str(abs_diff) + '<' + str(phase_diff))
```
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, ts_dpsim['wr_1'])
pt.plot_timeseries(1, ts_dpsim['wr_2'])
pt.plot_timeseries(1, ts_dpsim['wr_3'])
plt.xlabel('time (s)')
plt.ylabel('mechanical speed (rad/s)')
#plt.ylim([370,380])
#plt.xlim([0,0.06])
```
......
%% 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/WSCC-09_RX_Dyn/*.xml
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'
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/WSCC-09_RX_Dyn/*.xml') + \
glob.glob('Examples/CIM/WSCC-09_RX_Dyn/*.xml')
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'
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