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

update notebooks

parent 64725d8a
This diff is collapsed.
This diff is collapsed.
%% 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 0x7f4f4e1b06f0>
<dpsim.SystemTopology at 0x7f2850de38a0>
%% 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('%s_emt' % series, 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
INFO: #### Start Initialization ####
INFO: Found node n0
INFO: Found node n1
INFO: Found node n2
INFO: Created virtual node0 = 3 for v_s
INFO: Number of network nodes: 3
INFO: Number of nodes: 4
INFO: Number of network simulation nodes: 3
INFO: Number of simulation nodes: 4
INFO: Initialize power flow
INFO: Added DP::Ph1::VoltageSource 'v_s' to simulation.
INFO: Added DP::Ph1::Resistor 'r_line' to simulation.
INFO: Added DP::Ph1::Inductor 'l_line' to simulation.
INFO: Added DP::Ph1::Resistor 'r_load' to simulation.
INFO: System matrix:
1 -1 0 -1 0 0 0 -0
-1 1.00005 -4.99877e-05 0 0 7.85204e-07 -7.85204e-07 0
0 -4.99877e-05 0.00104999 0 0 -7.85204e-07 7.85204e-07 0
-1 0 0 0 -0 0 0 0
0 0 0 0 1 -1 0 -1
0 -7.85204e-07 7.85204e-07 0 -1 1.00005 -4.99877e-05 0
0 7.85204e-07 -7.85204e-07 0 0 -4.99877e-05 0.00104999 0
0 0 0 0 -1 0 0 0
INFO: LU decomposition:
1 -1 0 -1 0 0 0 -0
-1 -1 0 -1 0 0 0 0
0 4.99877e-05 0.00104999 4.99877e-05 0 -7.85204e-07 7.85204e-07 0
-1 -4.99877e-05 -0.0476079 -1.00005 0 7.47823e-07 -7.47823e-07 0
0 -0 0 -0 1 -1 0 -1
0 -0 0 -0 -1 -1 0 -1
0 -7.85204e-07 -0.000747823 7.47787e-07 0 4.99883e-05 0.00104999 4.99883e-05
0 7.85204e-07 0.000747823 -7.47787e-07 -1 -4.99883e-05 -0.0476084 -1.00005
INFO: Right side vector:
0
0
0
10000
0
0
0
0
INFO: Initial switch status: 00000000000000000000000000000000
%% 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