forked from PyPSA/PyPSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal_example_pf.py
57 lines (37 loc) · 1.1 KB
/
minimal_example_pf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
## Minimal 3-node example of PyPSA power flow
#
# Available as a Jupyter notebook at <https://pypsa.readthedocs.io/en/latest/examples/minimal_example_pf.ipynb>.
import numpy as np
import pypsa
network = pypsa.Network()
# add three buses
n_buses = 3
for i in range(n_buses):
network.add("Bus", "My bus {}".format(i), v_nom=20.0)
print(network.buses)
# add three lines in a ring
for i in range(n_buses):
network.add(
"Line",
"My line {}".format(i),
bus0="My bus {}".format(i),
bus1="My bus {}".format((i + 1) % n_buses),
x=0.1,
r=0.01,
)
print(network.lines)
# add a generator at bus 0
network.add("Generator", "My gen", bus="My bus 0", p_set=100, control="PQ")
print(network.generators)
print(network.generators.p_set)
# add a load at bus 1
network.add("Load", "My load", bus="My bus 1", p_set=100)
print(network.loads)
print(network.loads.p_set)
network.loads.q_set = 100.0
# Do a Newton-Raphson power flow
network.pf()
print(network.lines_t.p0)
print(network.buses_t.v_ang * 180 / np.pi)
print(network.buses_t.v_mag_pu)