Commit 5dbe648a authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'update-inverter-nbs' into 'master'

update inverter nbs

See merge request acs/public/simulation/dpsim!87
parents 8f4b41e7 6825fef0
%% Cell type:markdown id: tags:
# Inverter Grid Test
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
DP_Inverter_Grid_Test
```
%% Output
0.000395416
%% Cell type:code id: tags:
``` python
import villas.dataprocessing.readtools as rt
import villas.dataprocessing.plottools as pt
from villas.dataprocessing.timeseries import TimeSeries
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
# read results
work_dir = 'logs/DP_Inverter_Grid_Test/'
log_name = 'DP_Inverter_Grid_Test'
print(work_dir + log_name + '.csv')
ts_dpsim = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')
```
%% Output
logs/DP_Inverter_Grid_Test/DP_Inverter_Grid_Test.csv
column number: 15
results length: 50000
real column names: []
complex column names: ['i12_0_0', 'i34_0_0', 'v1_0_0', 'v1_0_1', 'v1_0_2', 'v1_0_3', 'v1_0_4', 'v2_0_0', 'v3_0_0', 'v3_0_1', 'v3_0_2', 'v3_0_3', 'v3_0_4', 'v4_0_0', 'v5_0_0']
%% Cell type:code id: tags:
``` python
ts_list_v1 = [
ts_dpsim['v1_0_0'],
ts_dpsim['v1_0_1'],
ts_dpsim['v1_0_2'],
ts_dpsim['v1_0_3'],
ts_dpsim['v1_0_4']]
ts_list_v3 = [
ts_dpsim['v3_0_0'],
ts_dpsim['v3_0_1'],
ts_dpsim['v3_0_2'],
ts_dpsim['v3_0_3'],
ts_dpsim['v3_0_4']]
freq_list = [
50,
19850,
19950,
20050,
20150]
ts_dpsim_emt_v1 = TimeSeries.create_emt_from_dp(ts_list_v1, freq_list)
ts_dpsim_emt_v1.values
```
%% Output
array([ 0. , -0.07476615, -0.14131796, ..., -0.19165711,
-0.14131796, -0.07476615])
%% Cell type:code id: tags:
``` python
#%matplotlib qt
pt.plot_timeseries(1, ts_dpsim_emt_v1)
plt.xlim(0, 0.05)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
``` python
ts_dpsim_emt_v3 = TimeSeries.create_emt_from_dp(ts_list_v3, freq_list)
pt.plot_timeseries(1, ts_dpsim_emt_v3)
plt.xlim(0, 0.05)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
``` python
ts_dpsim_emt_v5 = ts_dpsim['v5_0_0'].frequency_shift(50)
#%matplotlib qt
pt.plot_timeseries(1, ts_dpsim_emt_v1)
pt.plot_timeseries(1, ts_dpsim_emt_v3)
pt.plot_timeseries(1, ts_dpsim_emt_v5)
plt.xlim(0, 0.05)
```
%% Output
(0, 0.05)
%% Cell type:code id: tags:
``` python
ts_dpsim_emt_v1 = ts_dpsim['v1_0_0'].frequency_shift(50)
pt.plot_timeseries(1, ts_dpsim_emt_v1)
plt.xlim(0, 0.05)
```
%% Output
(0, 0.05)
%% 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/reference-results/raw/master/Simulink/Inverter/ML_SP_Inverter_OL_v_i.csv'
local_file = 'reference-results/ML_SP_Inverter_OL_v_i.csv'
urllib.request.urlretrieve(url, local_file)
ts_ml_inverter = rt.read_timeseries_simulink(local_file)
```
%% Output
column number: 4
results length: 100001
real column names: ['v_inv', 'v_c', 'i1', 'i2']
complex column names: []
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, ts_ml_inverter['v_inv'])
```
%% Output
%% Cell type:code id: tags:
``` python
#plt.figure(figsize=(20,10))
pt.plot_timeseries(1, ts_ml_inverter['v_c'])
pt.plot_timeseries(1, ts_dpsim_emt_v3)
plt.xlim(0.024, 0.026)
plt.ylim(300, 320)
```
%% Output
(300, 320)
%% Cell type:code id: tags:
``` python
import numpy as np
diff = ts_ml_inverter['v_c'].values[:5000] - np.interp(ts_ml_inverter['v_c'].time[:5000], ts_dpsim_emt_v3.time, ts_dpsim_emt_v3.values)
assert np.all(diff) < 10
```
%% 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/reference-results/raw/master/Simulink/Inverter/SL_SP_Inverter_OL_v_i.csv'
local_file = 'reference-results/SL_SP_Inverter_OL_v_i.csv'
urllib.request.urlretrieve(url, local_file)
ts_sl_inverter = rt.read_timeseries_simulink(local_file)
```
%% Output
column number: 4
results length: 712639
real column names: ['v_inv', 'v_c', 'i1', 'i2']
complex column names: []
%% Cell type:code id: tags:
``` python
pt.plot_timeseries(1, ts_sl_inverter['v_inv'])
```
%% Output
%% Cell type:code id: tags:
``` python
#plt.figure(figsize=(20,10))
pt.plot_timeseries(1, ts_ml_inverter['v_c'])
pt.plot_timeseries(1, ts_sl_inverter['v_c'])
pt.plot_timeseries(1, ts_dpsim_emt_v3)
plt.xlim(0.024, 0.026)
plt.ylim(300, 320)
```
%% Output
(300, 320)
%% Cell type:code id: tags:
``` python
import numpy as np
ts_sl_inverter['v_c'].label = 'vc_sl'
ts_dpsim_emt_v3.label = 'vc_dpsim'
ts_sl_inverter['v_c'].label = 'simulink'
ts_dpsim_emt_v3.label = 'dyn. phasor'
pt.plot_timeseries(1, ts_sl_inverter['v_c'])
pt.plot_timeseries(1, ts_dpsim_emt_v3)
plt.xlim(0.0245, 0.0255)
plt.ylim(306, 315)
plt.xlabel('time (s)')
plt.ylabel('voltage (V)')
ax = plt.gca()
ax.xaxis.set_major_locator(plt.MaxNLocator(5))
#plt.savefig('dp_simulink_inv_4_harm.pdf')
```
%% Output
%% Cell type:code id: tags:
``` python
```
......