Commit 342cdb90 authored by Markus Mirz's avatar Markus Mirz
Browse files

remove notebook output


Former-commit-id: 1e82c92a
parent 111ed641
%% Cell type:markdown id: tags:
# Circuit CS_R2CL
%% 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
```
%% Cell type:markdown id: tags:
## DPsim EMT
%% Cell type:code id: tags:
``` python
# DPsim EMT simulation
import dpsim
name = 'EMT_CS_R2CL'
# Nodes
gnd = dpsim.emt.Node.GND()
n1 = dpsim.emt.Node('n1')
n2 = dpsim.emt.Node('n2')
# Components
cs = dpsim.emt.ph1.CurrentSource('cs')
cs.I_ref = complex(10,0)
cs.f_src = 50
r1 = dpsim.emt.ph1.Resistor('r_1');
r1.R = 1;
c1 = dpsim.emt.ph1.Capacitor('c_1');
c1.C = 0.001;
l1 = dpsim.emt.ph1.Inductor('l_1');
l1.L = 0.001;
r2 = dpsim.emt.ph1.Resistor('r_2');
r2.R = 1;
# Connections
cs.connect([gnd, n1])
r1.connect([n1, gnd])
c1.connect([n1, n2]);
l1.connect([n2, gnd]);
r2.connect([n2, gnd]);
# Define system topology
system = dpsim.SystemTopology(50, [gnd, n1, n2], [cs, r1, c1, l1, r2]);
# Logging
logger = dpsim.Logger(name)
logger.log_attribute(n1, 'v');
logger.log_attribute(n2, 'v');
logger.log_attribute(cs, 'i_intf');
logger.log_attribute(c1, 'i_intf');
sim = dpsim.Simulation(name, system, timestep=0.0001, duration=0.1, pbar=True, sim_type=1)
sim.add_logger(logger)
await sim.simulate()
```
%% Cell type:code id: tags:
``` python
# read EMT results
work_dir = 'logs/'
log_name = 'EMT_CS_R2CL'
print(work_dir + log_name + '.csv')
ts_dpsim_emt = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')
```
%% Cell type:code id: tags:
``` python
v1_emt = 'n1.v'
v2_emt = 'n2.v'
i01_emt = 'cs.i_intf'
i12_emt = 'c_1.i_intf'
ts_dpsim_emt[v1_emt].label = 'v1 EMT'
ts_dpsim_emt[v2_emt].label = 'v2 EMT'
ts_dpsim_emt[i01_emt].label = 'i01 EMT'
ts_dpsim_emt[i12_emt].label = 'i12 EMT'
pt.plot_timeseries(1, ts_dpsim_emt[v1_emt])
pt.plot_timeseries(1, ts_dpsim_emt[v2_emt])
pt.plot_timeseries(2, ts_dpsim_emt[i01_emt])
pt.plot_timeseries(2, ts_dpsim_emt[i12_emt])
```
%% Cell type:markdown id: tags:
## DPsim DP
%% Cell type:code id: tags:
``` python
# DPsim DP simulation
import dpsim
name = 'DP_CS_R2CL'
# Nodes
gnd = dpsim.dp.Node.GND()
n1 = dpsim.dp.Node('n1')
n2 = dpsim.dp.Node('n2')
# Components
cs = dpsim.dp.ph1.CurrentSource('cs')
cs.I_ref = complex(10,0)
r1 = dpsim.dp.ph1.Resistor('r_1');
r1.R = 1;
c1 = dpsim.dp.ph1.Capacitor('c_1');
c1.C = 0.001;
l1 = dpsim.dp.ph1.Inductor('l_1');
l1.L = 0.001;
r2 = dpsim.dp.ph1.Resistor('r_2');
r2.R = 1;
# Connections
cs.connect([gnd, n1])
r1.connect([n1, gnd])
c1.connect([n1, n2]);
l1.connect([n2, gnd]);
r2.connect([n2, gnd]);
# Define system topology
system = dpsim.SystemTopology(50, [gnd, n1, n2], [cs, r1, c1, l1, r2]);
# Logging
logger = dpsim.Logger(name)
logger.log_attribute(n1, 'v');
logger.log_attribute(n2, 'v');
logger.log_attribute(cs, 'i_intf');
logger.log_attribute(c1, 'i_intf');
sim = dpsim.Simulation(name, system, timestep=0.0001, duration=0.1, pbar=True)
sim.add_logger(logger)
await sim.simulate()
```
%% Cell type:code id: tags:
``` python
# read DP results
work_dir = 'logs/'
log_name = 'DP_CS_R2CL'
print(work_dir + log_name + '.csv')
ts_dpsim_dp = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')
#convert to emt
ts_dpsim_dp_emt = ts.frequency_shift_list(ts_dpsim_dp, 50)
```
%% Cell type:code id: tags:
``` python
v1_dp = 'n1.v_shift'
v2_dp = 'n2.v_shift'
i01_dp = 'cs.i_intf_shift'
i12_dp = 'c_1.i_intf_shift'
ts_dpsim_dp_emt[v1_dp].label = 'v1 DP'
ts_dpsim_dp_emt[v2_dp].label = 'v2 DP'
ts_dpsim_dp_emt[i01_dp].label = 'i01 DP'
ts_dpsim_dp_emt[i12_dp].label = 'i12 DP'
pt.plot_timeseries(1, ts_dpsim_dp_emt[v1_dp])
pt.plot_timeseries(1, ts_dpsim_dp_emt[v2_dp])
pt.plot_timeseries(2, ts_dpsim_dp_emt[i01_dp])
pt.plot_timeseries(2, ts_dpsim_dp_emt[i12_dp])
```
%% Cell type:markdown id: tags:
## Simulink reference results
%% 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/Circuits/SL_CS_R2CL.csv'
local_file = 'reference-results/SL_CS_R2CL.csv'
urllib.request.urlretrieve(url, local_file)
ts_sl = rt.read_timeseries_simulink(local_file)
```
%% Cell type:code id: tags:
``` python
v1_sl = 'v1'
v2_sl = 'v2'
i01_sl = 'i12'
i12_sl = 'i34'
ts_sl[v1_sl].label = 'v1 SL'
ts_sl[v2_sl].label = 'v2 SL'
ts_sl[i01_sl].label = 'i01 SL'
ts_sl[i12_sl].label = 'i12 SL'
pt.plot_timeseries(1, ts_sl[v1_sl])
pt.plot_timeseries(1, ts_sl[v2_sl])
pt.plot_timeseries(2, ts_sl[i01_sl])
pt.plot_timeseries(2, ts_sl[i12_sl])
```
%% Cell type:markdown id: tags:
## Comparison
%% Cell type:code id: tags:
``` python
# plot v1
pt.plot_timeseries(1, ts_dpsim_emt[v1_emt])
pt.plot_timeseries(1, ts_dpsim_dp_emt[v1_dp])
pt.plot_timeseries(1, ts_dpsim_dp['n1.v'].abs())
pt.plot_timeseries(1, ts_sl[v1_sl])
# plot v2
pt.plot_timeseries(2, ts_dpsim_emt[v2_emt])
pt.plot_timeseries(2, ts_dpsim_dp_emt[v2_dp])
pt.plot_timeseries(2, ts_sl[v2_sl])
# plot i01
pt.plot_timeseries(5, ts_dpsim_emt[i01_emt])
pt.plot_timeseries(5, ts_dpsim_dp_emt[i01_dp])
pt.plot_timeseries(5, ts_sl[i01_sl])
# plot i12
pt.plot_timeseries(6, ts_dpsim_emt[i12_emt])
pt.plot_timeseries(6, ts_dpsim_dp_emt[i12_dp])
ts_i12_sl = ts_sl[i12_sl].scale(-1)
ts_i12_sl.label = '-i12 SL'
pt.plot_timeseries(6, ts_i12_sl)
```
%% Cell type:code id: tags:
``` python
# calculate the RMSE between Simulink (ts_sl) and EMT (ts_dpsim_emt)
err_sl_emt = 0
err_sl_emt += ts.rmse(ts_sl[v1_sl], ts_dpsim_emt[v1_emt])
err_sl_emt += ts.rmse(ts_sl[v2_sl], ts_dpsim_emt[v2_emt])
err_sl_emt = err_sl_emt / 2
print("Total RMSE of Simulink reference and DPsim EMT: %g" % (err_sl_emt))
# calculate the RMSE between Simulink (ts_sl) and DP (ts_dpsim_dp_emt)
err_sl_dp = 0
err_sl_dp += ts.rmse(ts_sl[v1_sl], ts_dpsim_dp_emt[v1_dp])
err_sl_dp += ts.rmse(ts_sl[v2_sl], ts_dpsim_dp_emt[v2_dp])
err_sl_dp = err_sl_dp / 2
print("Total RMSE of Simulink reference and DPsim DP: %g" % (err_sl_dp))
```
%% Cell type:code id: tags:
``` python
assert err_sl_emt < 0.1
assert err_sl_dp < 0.1
```
%% Cell type:code id: tags:
``` python
```
d0a52f9fc70b7461ce94ee1a534ec0b15ae0335d
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="123.83142mm"
height="41.120247mm"
viewBox="0 0 123.83142 41.120247"
version="1.1"
id="svg8"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
sodipodi:docname="RLC_circuit.svg">
<defs
id="defs2" />