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

update dp basics

parent cddafb02
......@@ -18,6 +18,13 @@ set(CIRCUIT_SOURCES
Circuits/DP_VS_CS_R4.cpp
Circuits/DP_VS_R2L3.cpp
DP_Basics/DP_VS_RL_f60.cpp
DP_Basics/DP_VS_RL_f60_largeTs.cpp
DP_Basics/DP_VS_RL_f60_vlargeTs.cpp
DP_Basics/DP_VS_RL_f500.cpp
DP_Basics/DP_VS_RL_f500_largeTs.cpp
DP_Basics/DP_VS_RL_f500_ph500.cpp
#Circuits/DP_VS_PiLine_R.cpp
#Circuits/DP_VS_Trafo_R.cpp
#Circuits/DP_ResVS_RL_Switch.cpp
......@@ -31,6 +38,10 @@ set(CIRCUIT_SOURCES
Circuits/EMT_VS_R2L3.cpp
Circuits/EMT_VS_CS_R4_AC.cpp
Circuits/EMT_VS_CS_R4_DC.cpp
DP_Basics/EMT_VS_RL_f60.cpp
DP_Basics/EMT_VS_RL_f60_largeTs.cpp
DP_Basics/EMT_VS_RL_f500.cpp
#Circuits/EMT_ResVS_RL_Switch.cpp
......@@ -48,6 +59,7 @@ set(SYNCGEN_SOURCES
set(INVERTER_SOURCES
Inverter/DP_Inverter_Grid_Test.cpp
Inverter/DP_Inverter_Grid_Test_Parallel.cpp
Inverter/DP_Vsrc_Grid_Parallel.cpp
)
if(WITH_SUNDIALS)
......
%% Cell type:markdown id: tags:
Quickstart Guide
================
This guides demonstrates the basic usage of DPsim as a [Python module](https://dpsim.fein-aachen.org/doc/development/sphinx/Python.html).
(Please note that DPsim also provides a [C++ API](https://dpsim.fein-aachen.org/doc/development/doxygen).)
The first simulation
--------------------
As a first simple, test we will simulate the following static network:
![](Figures/vs_line_load.svg)
The network consists of 4 nodes and 4 elements:
| Component | Type | Python Class | Node A | Node B | Paramter |
| :---------| :---- | :---------------------------------------- | :----- | :----- | :------- |
| v_s | Voltage Source | `dpsim.dp.ph1.VoltageSource` | 0 | GND | 10 kV |
| r_line | Line Resistance | `dpsim.dp.ph1.Resistor` | 0 | 1 | 1 Ohm |
| l_line | Line Inductance | `dpsim.dp.ph1.Inductor` | 1 | 2 | 1 Henry |
| r_load | Load | `dpsim.dp.ph1.Resistor` | 2 | GND | 1 kOhm |
%% Cell type:markdown id: tags:
Before we can start, we must import the DPsim Python module.
We also add `dp` as an alias for the dynamic phasor components.
%% Cell type:code id: tags:
``` python
import dpsim
```
%% Cell type:markdown id: tags:
Next, we can define the model by creating a couple of components.
Each component is identified by a name which is passed as the first argument.
Following arguments are used to define the topology by assigning the component to a specific node / bus or to pass parameters.
%% Cell type:code id: tags:
``` python
gnd = dpsim.dp.Node.GND()
n0 = dpsim.dp.Node("n0")
n1 = dpsim.dp.Node("n1")
n2 = dpsim.dp.Node("n2")
v_s = dpsim.dp.ph1.VoltageSource("v_s", [n0, gnd], V_ref=10000+0j)
r_line = dpsim.dp.ph1.Resistor("r_line", [n0, n1], R=1)
l_line = dpsim.dp.ph1.Inductor("l_line", [n1, n2], L=1)
r_load = dpsim.dp.ph1.Resistor("r_load", [n2, gnd], R=1000)
```
%% Cell type:markdown id: tags:
Next, we have to create a simulation object:
%% Cell type:code id: tags:
``` python
sys = dpsim.SystemTopology(50, [ n0, n1, n2 ], [ v_s, r_line, l_line, r_load ])
```
%% Cell type:markdown id: tags:
We can also visualize the system topology:
%% Cell type:code id: tags:
``` python
sys
```
%% Output
<dpsim.SystemTopology at 0x7fba5737dd50>
<dpsim.SystemTopology at 0x7f70586ff690>
%% Cell type:markdown id: tags:
Finally, we can start the simulation and wait for its completion:
%% Cell type:code id: tags:
``` python
sim = dpsim.Simulation("Example1", sys, timestep = 1e-4, duration = 0.03, pbar = True)
log = dpsim.Logger("Example1")
for n in sys.nodes:
log.log_attribute(sys.nodes[n], "v")
sim.add_logger(log)
await sim.simulate()
```
%% Output
%% Cell type:markdown id: tags:
Results can be analyzed and plotted by the `villas.dataprocessing` package:
%% Cell type:code id: tags:
``` python
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
%config InlineBackend.rc = {'font.size': 10, 'figure.figsize': (6.0, 4.0), 'figure.facecolor': 'white', 'savefig.dpi': 72, 'figure.subplot.bottom': 0.125, 'figure.edgecolor': 'white'}
import matplotlib.pyplot as plt
import villas.dataprocessing.plottools as pt
import villas.dataprocessing.readtools as rt
import villas.dataprocessing.timeseries as ts
results = rt.read_timeseries_dpsim('logs/Example1.csv')
results_emt = [ results[series].frequency_shift(50) for series in results ]
for series in results_emt:
pt.plot_timeseries('Results EMT', series)
plt.show()
```
%% Output
column number: 3
results length: 301
real column names: []
complex column names: ['n0.v', 'n1.v', 'n2.v']
%% Cell type:code id: tags:
``` python
!cat logs/Example1_MNA.log
```
%% Output
[I] ---- Start initialization ----
[I] -- Process system components
[I] Added DP::Ph1::VoltageSource 'v_s' to simulation.
[I] Added DP::Ph1::Resistor 'r_line' to simulation.
[I] Added DP::Ph1::Inductor 'l_line' to simulation.
[I] Added DP::Ph1::Resistor 'r_load' to simulation.
[I] Found node n0
[I] Found node n1
[I] Found node n2
[I] Created virtual node 0 = 3 for v_s
[I] Created virtual nodes:
[I] Number of network nodes: 3
[I] Number of network and virtual nodes: 4
[I] Assigned simulation nodes to topology nodes:
[I] Number of network simulation nodes: 3
[I] Number of simulation nodes: 4
[I] Number of harmonic simulation nodes: 0
[I] -- Create empty MNA system matrices and vectors
[I] -- Initialize components from power flow
[I] -- Initialize MNA properties of components
[I] -- Initialize MNA system matrices and source vector
[I] --- Initialization finished ---
[I] --- Initial system matrices and vectors ---
[I] System matrix:
1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 -0.000000e+00
-1.000000e+00 1.000050e+00 -4.998767e-05 0.000000e+00 0.000000e+00 7.852044e-07 -7.852044e-07 0.000000e+00
0.000000e+00 -4.998767e-05 1.049988e-03 0.000000e+00 0.000000e+00 -7.852044e-07 7.852044e-07 0.000000e+00
-1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 -0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00
0.000000e+00 -7.852044e-07 7.852044e-07 0.000000e+00 -1.000000e+00 1.000050e+00 -4.998767e-05 0.000000e+00
0.000000e+00 7.852044e-07 -7.852044e-07 0.000000e+00 0.000000e+00 -4.998767e-05 1.049988e-03 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[I] LU decomposition:
1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 -0.000000e+00
-1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 4.998767e-05 1.049988e-03 4.998767e-05 0.000000e+00 -7.852044e-07 7.852044e-07 0.000000e+00
-1.000000e+00 -4.998767e-05 -4.760786e-02 -1.000048e+00 0.000000e+00 7.478225e-07 -7.478225e-07 0.000000e+00
0.000000e+00 -0.000000e+00 0.000000e+00 -0.000000e+00 1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00
0.000000e+00 -0.000000e+00 0.000000e+00 -0.000000e+00 -1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00
0.000000e+00 -7.852044e-07 -7.478225e-04 7.477869e-07 0.000000e+00 4.998825e-05 1.049988e-03 4.998825e-05
0.000000e+00 7.852044e-07 7.478225e-04 -7.477869e-07 -1.000000e+00 -4.998825e-05 -4.760839e-02 -1.000048e+00
[I] Right side vector:
0.000000e+00
0.000000e+00
-0.000000e+00
1.000000e+04
0.000000e+00
0.000000e+00
-0.000000e+00
0.000000e+00
[I] ---- Start initialization ----
[I] -- Process system components
[I] Added DP::Ph1::VoltageSource 'v_s' to simulation.
[I] Added DP::Ph1::Resistor 'r_line' to simulation.
[I] Added DP::Ph1::Inductor 'l_line' to simulation.
[I] Added DP::Ph1::Resistor 'r_load' to simulation.
[I] Found node n0
[I] Found node n1
[I] Found node n2
[I] Created virtual node 0 = 3 for v_s
[I] Created virtual nodes:
[I] Number of network nodes: 3
[I] Number of network and virtual nodes: 4
[I] Assigned simulation nodes to topology nodes:
[I] Number of network simulation nodes: 3
[I] Number of simulation nodes: 4
[I] Number of harmonic simulation nodes: 0
[I] -- Create empty MNA system matrices and vectors
[I] -- Initialize components from power flow
[I] -- Initialize MNA properties of components
[I] -- Initialize MNA system matrices and source vector
[I] --- Initialization finished ---
[I] --- Initial system matrices and vectors ---
[I] System matrix:
1.000000e+00 -1.000000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 -0.000000e+00
-1.000000e+00 1.000050e+00 -4.998767e-05 0.000000e+00 0.000000e+00 7.852044e-07 -7.852044e-07 0.000000e+00
0.000000e+00 -4.998767e-05 1.04
%% 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