fpowerkit 0.0.13__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/PKG-INFO +2 -1
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/README.md +2 -4
- fpowerkit-0.1.1/fpowerkit/bus.py +153 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit/cases.py +17 -10
- fpowerkit-0.1.1/fpowerkit/gen.py +278 -0
- fpowerkit-0.1.1/fpowerkit/grid.py +441 -0
- fpowerkit-0.1.1/fpowerkit/line.py +96 -0
- fpowerkit-0.1.1/fpowerkit/pvwind.py +156 -0
- fpowerkit-0.1.1/fpowerkit/solver.py +400 -0
- fpowerkit-0.1.1/fpowerkit/utils.py +143 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit.egg-info/PKG-INFO +2 -1
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit.egg-info/SOURCES.txt +5 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit.egg-info/requires.txt +1 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/setup.py +2 -2
- fpowerkit-0.0.13/fpowerkit/grid.py +0 -799
- fpowerkit-0.0.13/fpowerkit/solver.py +0 -198
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/LICENSE +0 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit/__init__.py +0 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit.egg-info/dependency_links.txt +0 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/fpowerkit.egg-info/top_level.txt +0 -0
- {fpowerkit-0.0.13 → fpowerkit-0.1.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fpowerkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: A Distflow PDN solver based on Gurobi.
|
|
5
5
|
Author: fmy_xfk
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -11,6 +11,7 @@ Description-Content-Type: text/markdown
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: feasytools>=0.0.18
|
|
13
13
|
Requires-Dist: gurobipy>=9.1.0
|
|
14
|
+
Requires-Dist: numpy>=1.20.0
|
|
14
15
|
|
|
15
16
|
# FPowerKit - A power distribution network calculation component
|
|
16
17
|
|
|
@@ -37,8 +37,6 @@ B0->B1->B2
|
|
|
37
37
|
您也换成自己的配电网文件来求解,例如`python main.py -g path/to/your_zipfile.zip`
|
|
38
38
|
|
|
39
39
|
## 配电网文件格式
|
|
40
|
-
|
|
40
|
+
[XML格式](docs/xml_file.md)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
[ZIP格式](docs/zip_file.md)
|
|
42
|
+
ZIP格式已经不再支持。
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from .utils import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Bus:
|
|
6
|
+
Pd: TimeFunc # pu
|
|
7
|
+
Qd: TimeFunc # pu
|
|
8
|
+
ShadowPrice: FloatVar # Shadow price of generators on this bus,$/pu power
|
|
9
|
+
Lat: NFloat
|
|
10
|
+
Lon: NFloat
|
|
11
|
+
|
|
12
|
+
def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, lat: NFloat = None, lon: NFloat = None,
|
|
13
|
+
v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf')):
|
|
14
|
+
'''
|
|
15
|
+
Initialize
|
|
16
|
+
id: Bus ID
|
|
17
|
+
pd_pu: Active power demand, pu
|
|
18
|
+
qd_pu: Reactive power demand, pu
|
|
19
|
+
lat: Latitude of the bus
|
|
20
|
+
lon: Longitude of the bus
|
|
21
|
+
v_pu: Voltage, pu. None for unfixed voltage
|
|
22
|
+
min_v_pu: Minimal voltage, pu
|
|
23
|
+
max_v_pu: Maximal voltage, pu
|
|
24
|
+
'''
|
|
25
|
+
self._id = id
|
|
26
|
+
self._v = v_pu
|
|
27
|
+
self._fixed_v = self.V is not None
|
|
28
|
+
self._minv = min_v_pu
|
|
29
|
+
self._maxv = max_v_pu
|
|
30
|
+
self.Pd = Float2Func(pd_pu)
|
|
31
|
+
self.Qd = Float2Func(qd_pu)
|
|
32
|
+
self.ShadowPrice = None
|
|
33
|
+
self.Lat = lat
|
|
34
|
+
self.Lon = lon
|
|
35
|
+
self.theta = 0.0
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def V(self) -> FloatVar:
|
|
39
|
+
'''Voltage, pu'''
|
|
40
|
+
return self._v
|
|
41
|
+
@V.setter
|
|
42
|
+
def V(self, v: float):
|
|
43
|
+
self._v = v
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def V_cpx(self) -> Optional[complex]:
|
|
47
|
+
if self._v is None: return None
|
|
48
|
+
return self._v * math.cos(self.theta) + 1j * self._v * math.sin(self.theta)
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def FixedV(self) -> bool:
|
|
52
|
+
'''Whether the voltage is fixed'''
|
|
53
|
+
return self._fixed_v
|
|
54
|
+
|
|
55
|
+
def fixV(self, v: float):
|
|
56
|
+
'''Fix the voltage'''
|
|
57
|
+
self._v = v
|
|
58
|
+
self._fixed_v = True
|
|
59
|
+
|
|
60
|
+
def unfixV(self):
|
|
61
|
+
self._v = None
|
|
62
|
+
self._fixed_v = False
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def ID(self) -> str:
|
|
66
|
+
'''Name of the bus'''
|
|
67
|
+
return self._id
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def MinV(self) -> float:
|
|
71
|
+
'''Minimal voltage, pu'''
|
|
72
|
+
return self._minv
|
|
73
|
+
@MinV.setter
|
|
74
|
+
def MinV(self, v: float):
|
|
75
|
+
assert v >= 0 and v <= self._maxv, "MinV should be in [0, MaxV]"
|
|
76
|
+
self._minv = v
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def MaxV(self) -> float:
|
|
80
|
+
'''Maximal voltage, pu'''
|
|
81
|
+
return self._maxv
|
|
82
|
+
@MaxV.setter
|
|
83
|
+
def MaxV(self, v: float):
|
|
84
|
+
assert v >= self._minv, "MaxV should be no less than MinV"
|
|
85
|
+
self._maxv = v
|
|
86
|
+
|
|
87
|
+
def setVRange(self, min_v: float, max_v: float):
|
|
88
|
+
assert 0 <= min_v <= max_v, "MinV should be in [0, MaxV]"
|
|
89
|
+
self._minv = min_v
|
|
90
|
+
self._maxv = max_v
|
|
91
|
+
|
|
92
|
+
def __repr__(self):
|
|
93
|
+
return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
|
|
94
|
+
f"lat={self.Lat}, lon={self.Lon}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
95
|
+
|
|
96
|
+
def __str__(self):
|
|
97
|
+
return repr(self)
|
|
98
|
+
|
|
99
|
+
def str_t(self, _t: int, /):
|
|
100
|
+
return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
|
|
101
|
+
f"lat={self.Lat}, lon={self.Lon}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def position(self) -> 'tuple[NFloat, NFloat]':
|
|
105
|
+
'''Return the position of the bus, (lat, lon)'''
|
|
106
|
+
return self.Lat, self.Lon
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def LonLat(self) -> 'tuple[NFloat, NFloat]':
|
|
110
|
+
return self.Lon, self.Lat
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
|
|
114
|
+
id = node.attrib["ID"]
|
|
115
|
+
p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
|
|
116
|
+
q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
|
|
117
|
+
lat = node.attrib.get("Lat", None)
|
|
118
|
+
if lat is not None: lat = float(lat)
|
|
119
|
+
lon = node.attrib.get("Lon", None)
|
|
120
|
+
if lon is not None: lon = float(lon)
|
|
121
|
+
if "V" in node.attrib:
|
|
122
|
+
v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
|
|
123
|
+
minv = maxv = v
|
|
124
|
+
else:
|
|
125
|
+
minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
|
|
126
|
+
maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
|
|
127
|
+
v = None
|
|
128
|
+
return Bus(id, p, q, lat, lon, v, minv, maxv)
|
|
129
|
+
|
|
130
|
+
def toXMLNode(self, Ub_kV:Optional[float] = None,
|
|
131
|
+
Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
|
|
132
|
+
e = Element("bus", {"ID": self.ID})
|
|
133
|
+
if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
|
|
134
|
+
if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
|
|
135
|
+
if self.V is not None and self.FixedV:
|
|
136
|
+
e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
|
|
137
|
+
else:
|
|
138
|
+
e.attrib["MinV"] = str(self.MinV * Ub_kV)+"kV" if Ub_kV else str(self.MinV)
|
|
139
|
+
e.attrib["MaxV"] = str(self.MaxV * Ub_kV)+"kV" if Ub_kV else str(self.MaxV)
|
|
140
|
+
if Sb_MVA is not None and Sb_kVA is not None:
|
|
141
|
+
raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
|
|
142
|
+
if Sb_MVA is not None:
|
|
143
|
+
mul = Sb_MVA
|
|
144
|
+
unit = ["MW", "Mvar"]
|
|
145
|
+
elif Sb_kVA is not None:
|
|
146
|
+
mul = Sb_kVA
|
|
147
|
+
unit = ["kW", "kvar"]
|
|
148
|
+
else:
|
|
149
|
+
mul = 1
|
|
150
|
+
unit = ["pu", "pu"]
|
|
151
|
+
e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
|
|
152
|
+
e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
|
|
153
|
+
return e
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from feasytools import SegFunc
|
|
1
|
+
from feasytools import SegFunc, ConstFunc
|
|
2
2
|
from .grid import GeneratorModel, Grid, Bus, Line, Generator
|
|
3
3
|
|
|
4
4
|
# IEEE33 kVA
|
|
@@ -277,19 +277,24 @@ def _get_buses(
|
|
|
277
277
|
load_fluctuation.append((ls[j][0] + load_period * i, ls[j][1]))
|
|
278
278
|
if grid_repeat == 1:
|
|
279
279
|
B = [Bus("B"+str(p[0]), _create_load(p[1]/Sb_KVA,load_fluctuation),
|
|
280
|
-
_create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD]
|
|
280
|
+
_create_load(p[2]/Sb_KVA,load_fluctuation),min_v_pu=0.9,max_v_pu=1.1) for p in LOAD]
|
|
281
281
|
else:
|
|
282
282
|
B = []
|
|
283
283
|
for i in range(grid_repeat):
|
|
284
284
|
B.extend([Bus(f"B{i}_{p[0]}", _create_load(p[1]/Sb_KVA,load_fluctuation),
|
|
285
|
-
_create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD])
|
|
285
|
+
_create_load(p[2]/Sb_KVA,load_fluctuation),min_v_pu=0.9,max_v_pu=1.1) for p in LOAD])
|
|
286
286
|
else:
|
|
287
287
|
if grid_repeat == 1:
|
|
288
|
-
B = [Bus("B"+str(p[0]), p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD]
|
|
288
|
+
B = [Bus("B"+str(p[0]), p[1]/Sb_KVA, p[2]/Sb_KVA,min_v_pu=0.9,max_v_pu=1.1) for p in LOAD]
|
|
289
289
|
else:
|
|
290
290
|
B = []
|
|
291
291
|
for i in range(grid_repeat):
|
|
292
|
-
B.extend([Bus(f"B{i}_{p[0]}", p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD])
|
|
292
|
+
B.extend([Bus(f"B{i}_{p[0]}", p[1]/Sb_KVA, p[2]/Sb_KVA, min_v_pu=0.9,max_v_pu=1.1) for p in LOAD])
|
|
293
|
+
B[0].fixV(1.0)
|
|
294
|
+
B[0].Pd = ConstFunc(0)
|
|
295
|
+
B[0].Qd = ConstFunc(0)
|
|
296
|
+
B[0].MaxV = float('inf')
|
|
297
|
+
B[0].MinV = 0
|
|
293
298
|
return B
|
|
294
299
|
|
|
295
300
|
def _get_lines(Zb:float, LINE:'list[tuple[int,int,int,float,float]]', grid_repeat:int):
|
|
@@ -313,8 +318,8 @@ def _get_gens(default_gen:GeneratorModel, gen_pos:'list[int]', grid_repeat:int):
|
|
|
313
318
|
class PDNCases:
|
|
314
319
|
@staticmethod
|
|
315
320
|
def IEEE33(
|
|
316
|
-
Ub_kV:float=
|
|
317
|
-
Sb_MVA:float=
|
|
321
|
+
Ub_kV:float=12.66,
|
|
322
|
+
Sb_MVA:float=1,
|
|
318
323
|
gen_pos:'list[int]'=_DEFAULT_GEN_POS,
|
|
319
324
|
default_gen:GeneratorModel=_DEFAULT_GENERATOR,
|
|
320
325
|
grid_repeat:int = 1,
|
|
@@ -327,13 +332,14 @@ class PDNCases:
|
|
|
327
332
|
return Grid(Sb_MVA, Ub_kV,
|
|
328
333
|
_get_buses(Sb_MVA*1000, grid_repeat, _IEEE33_LOAD, changeable_load, load_fluctuation, load_repeat, load_period),
|
|
329
334
|
_get_lines(Ub_kV**2/Sb_MVA, _IEEE33_LINE, grid_repeat),
|
|
330
|
-
_get_gens(default_gen, gen_pos, grid_repeat)
|
|
335
|
+
_get_gens(default_gen, gen_pos, grid_repeat),
|
|
336
|
+
[]
|
|
331
337
|
)
|
|
332
338
|
|
|
333
339
|
@staticmethod
|
|
334
340
|
def IEEE69(
|
|
335
341
|
Ub_kV:float=10.0,
|
|
336
|
-
Sb_MVA:float=
|
|
342
|
+
Sb_MVA:float=1,
|
|
337
343
|
gen_pos:'list[int]'=_DEFAULT_GEN_POS,
|
|
338
344
|
default_gen:GeneratorModel=_DEFAULT_GENERATOR,
|
|
339
345
|
grid_repeat:int = 1,
|
|
@@ -346,5 +352,6 @@ class PDNCases:
|
|
|
346
352
|
return Grid(Sb_MVA, Ub_kV,
|
|
347
353
|
_get_buses(Sb_MVA*1000, grid_repeat, _IEEE69_LOAD, changeable_load, load_fluctuation, load_repeat, load_period),
|
|
348
354
|
_get_lines(Ub_kV**2/Sb_MVA, _IEEE69_LINE, grid_repeat),
|
|
349
|
-
_get_gens(default_gen, gen_pos, grid_repeat)
|
|
355
|
+
_get_gens(default_gen, gen_pos, grid_repeat),
|
|
356
|
+
[]
|
|
350
357
|
)
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from .utils import *
|
|
3
|
+
|
|
4
|
+
NFloatOrFunc = Union[None, float, TimeFunc]
|
|
5
|
+
|
|
6
|
+
class Generator:
|
|
7
|
+
Pmin: Optional[TimeFunc] #pu
|
|
8
|
+
Pmax: Optional[TimeFunc] #pu
|
|
9
|
+
Qmin: Optional[TimeFunc] #pu
|
|
10
|
+
Qmax: Optional[TimeFunc] #pu
|
|
11
|
+
CostA: TimeFunc #$/(pu Power·h)**2
|
|
12
|
+
CostB: TimeFunc #$/pu Power·h
|
|
13
|
+
CostC: TimeFunc #$
|
|
14
|
+
|
|
15
|
+
def __init__(self, id: str, busid: str,
|
|
16
|
+
costA: FloatLike, costB: FloatLike, costC: FloatLike,
|
|
17
|
+
pmin_pu: NFloatLike = None, pmax_pu: NFloatLike = None,
|
|
18
|
+
qmin_pu: NFloatLike = None, qmax_pu: NFloatLike = None,
|
|
19
|
+
Lat: NFloat = None, Lon: NFloat = None,
|
|
20
|
+
P: NFloatLike = None, Q: NFloatLike = None,
|
|
21
|
+
):
|
|
22
|
+
'''
|
|
23
|
+
Initialize
|
|
24
|
+
id: Generator ID
|
|
25
|
+
busid: ID of the bus where the generator is located
|
|
26
|
+
costA: Secondary cost, $/(pu Power·h)**2
|
|
27
|
+
costB: Primary cost, $/pu Power·h
|
|
28
|
+
costC: Fixed cost, $
|
|
29
|
+
Lat: Latitude of the generator
|
|
30
|
+
Lon: Longitude of the generator
|
|
31
|
+
Provide either group of parameters:
|
|
32
|
+
pmin_pu: Minimal active power output, pu. None for fixed power
|
|
33
|
+
pmax_pu: Maximal active power output, pu. None for fixed power
|
|
34
|
+
Or:
|
|
35
|
+
P: Active power output, pu. None for unfixed power
|
|
36
|
+
Provide either group of parameters:
|
|
37
|
+
qmin_pu: Minimal reactive power output, pu. None for fixed power
|
|
38
|
+
qmax_pu: Maximal reactive power output, pu. None for fixed power
|
|
39
|
+
Or:
|
|
40
|
+
Q: Reactive power output, pu. None for unfixed power
|
|
41
|
+
'''
|
|
42
|
+
self._id = id
|
|
43
|
+
self._bus = busid
|
|
44
|
+
self.Lat = Lat
|
|
45
|
+
self.Lon = Lon
|
|
46
|
+
if P is not None:
|
|
47
|
+
self._p = Float2Func(P)
|
|
48
|
+
self._fixed_p = True
|
|
49
|
+
self.Pmin = None
|
|
50
|
+
self.Pmax = None
|
|
51
|
+
elif pmin_pu is not None and pmax_pu is not None:
|
|
52
|
+
self._p = None
|
|
53
|
+
self._fixed_p = False
|
|
54
|
+
self.Pmin = Float2Func(pmin_pu)
|
|
55
|
+
self.Pmax = Float2Func(pmax_pu)
|
|
56
|
+
else:
|
|
57
|
+
raise ValueError("Either P or (pmin, pmax) should be provided.")
|
|
58
|
+
if Q is not None:
|
|
59
|
+
self._q = Float2Func(Q)
|
|
60
|
+
self._fixed_q = True
|
|
61
|
+
self.Qmin = None
|
|
62
|
+
self.Qmax = None
|
|
63
|
+
elif qmin_pu is not None and qmax_pu is not None:
|
|
64
|
+
self._q = None
|
|
65
|
+
self._fixed_q = False
|
|
66
|
+
self.Qmin = Float2Func(qmin_pu)
|
|
67
|
+
self.Qmax = Float2Func(qmax_pu)
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError("Either Q or (qmin, qmax) should be provided.")
|
|
70
|
+
self.CostA = Float2Func(costA)
|
|
71
|
+
self.CostB = Float2Func(costB)
|
|
72
|
+
self.CostC = Float2Func(costC)
|
|
73
|
+
self.CostShadow = None
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def P(self) -> NFloatOrFunc:
|
|
77
|
+
'''Active power output, pu'''
|
|
78
|
+
return self._p
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def FixedP(self) -> bool:
|
|
82
|
+
'''Whether the active power output is fixed'''
|
|
83
|
+
return self._fixed_p
|
|
84
|
+
|
|
85
|
+
def fixP(self, p: float):
|
|
86
|
+
'''Fix the active power output'''
|
|
87
|
+
self._p = p
|
|
88
|
+
self._fixed_p = True
|
|
89
|
+
|
|
90
|
+
def unfixP(self):
|
|
91
|
+
'''Unfix the active power output'''
|
|
92
|
+
self._p = None
|
|
93
|
+
self._fixed_p = False
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def Q(self) -> NFloatOrFunc:
|
|
97
|
+
'''Reactive power output, pu'''
|
|
98
|
+
return self._q
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def FixedQ(self) -> bool:
|
|
102
|
+
'''Whether the reactive power output is fixed'''
|
|
103
|
+
return self._fixed_q
|
|
104
|
+
|
|
105
|
+
def fixQ(self, q: float):
|
|
106
|
+
'''Fix the reactive power output'''
|
|
107
|
+
self._q = q
|
|
108
|
+
self._fixed_q = True
|
|
109
|
+
|
|
110
|
+
def unfixQ(self):
|
|
111
|
+
'''Unfix the reactive power output'''
|
|
112
|
+
self._q = None
|
|
113
|
+
self._fixed_q = False
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def position(self) -> 'tuple[NFloat, NFloat]':
|
|
117
|
+
'''Position of the generator, (Lat, Lon)'''
|
|
118
|
+
return (self.Lat, self.Lon)
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def LonLat(self) -> 'tuple[NFloat, NFloat]':
|
|
122
|
+
return self.Lon, self.Lat
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def ID(self) -> str:
|
|
126
|
+
'''Name of the generator'''
|
|
127
|
+
return self._id
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def BusID(self) -> str:
|
|
131
|
+
'''ID of the bus where the generator is located'''
|
|
132
|
+
return self._bus
|
|
133
|
+
|
|
134
|
+
def __repr__(self) -> str:
|
|
135
|
+
return (f"Generator(id='{self.ID}', busid='{self.BusID}', P={self.P}, Q={self.Q}, " +
|
|
136
|
+
f"pmin_pu={self.Pmin}, pmax_pu={self.Pmax}, qmin_pu={self.Qmin}, qmax_pu={self.Qmax}, " +
|
|
137
|
+
f"costA={self.CostA}, costB={self.CostB}, costC={self.CostC}, Lat={self.Lat}, Lon={self.Lon})")
|
|
138
|
+
|
|
139
|
+
def __str__(self) -> str:
|
|
140
|
+
return repr(self)
|
|
141
|
+
|
|
142
|
+
def str_t(self, _t: int, /) -> str:
|
|
143
|
+
p = self.P(_t) if isinstance(self.P, TimeFunc) else FVstr(self.P)
|
|
144
|
+
pmin = self.Pmin(_t) if isinstance(self.Pmin, TimeFunc) else None
|
|
145
|
+
pmax = self.Pmax(_t) if isinstance(self.Pmax, TimeFunc) else None
|
|
146
|
+
q = self.Q(_t) if isinstance(self.Q, TimeFunc) else FVstr(self.Q)
|
|
147
|
+
qmin = self.Qmin(_t) if isinstance(self.Qmin, TimeFunc) else None
|
|
148
|
+
qmax = self.Qmax(_t) if isinstance(self.Qmax, TimeFunc) else None
|
|
149
|
+
return (f"Generator(id='{self.ID}', busid='{self.BusID}', P={p}, Q={q}, " +
|
|
150
|
+
f"pmin_pu={pmin}, pmax_pu={pmax}, qmin_pu={qmin}, qmax_pu={qmax}, " +
|
|
151
|
+
f"costA={self.CostA(_t)}, costB={self.CostB(_t)}, costC={self.CostC(_t)}, Lat={self.Lat}, Lon={self.Lon})")
|
|
152
|
+
|
|
153
|
+
def Cost(self, _t: int, /, secondary: bool = True) -> FloatVar:
|
|
154
|
+
'''
|
|
155
|
+
Get the cost of the generator at time _t, $/h
|
|
156
|
+
_t: time
|
|
157
|
+
secondary: whether to use the secondary cost model, False for the primary cost model
|
|
158
|
+
'''
|
|
159
|
+
if self.P is None: return None
|
|
160
|
+
p = self.P(_t) if isinstance(self.P, TimeFunc) else self.P
|
|
161
|
+
ret = self.CostB(_t) * p + self.CostC(_t)
|
|
162
|
+
if secondary: ret += self.CostA(_t) * p ** 2
|
|
163
|
+
return ret
|
|
164
|
+
|
|
165
|
+
def CostPerPUPower(self, _t: int, /, secondary: bool = True) -> FloatVar:
|
|
166
|
+
'''
|
|
167
|
+
Get the cost of the generator per pu power at time _t, $/pu Power·h
|
|
168
|
+
_t: time
|
|
169
|
+
secondary: whether to use the secondary cost model, False for the primary cost model
|
|
170
|
+
'''
|
|
171
|
+
if self.P is None: return None
|
|
172
|
+
p = self.P(_t) if isinstance(self.P, TimeFunc) else self.P
|
|
173
|
+
if p == 0: return None
|
|
174
|
+
ret = self.CostB(_t) * p + self.CostC(_t)
|
|
175
|
+
if secondary: ret += self.CostA(_t) * p ** 2
|
|
176
|
+
return ret / p
|
|
177
|
+
|
|
178
|
+
@staticmethod
|
|
179
|
+
def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
|
|
180
|
+
id = node.attrib["ID"]
|
|
181
|
+
busid = node.attrib["Bus"]
|
|
182
|
+
pmin = ReadNFloatLike(node.find("Pmin"), Sb_MVA, Ub_kV)
|
|
183
|
+
pmax = ReadNFloatLike(node.find("Pmax"), Sb_MVA, Ub_kV)
|
|
184
|
+
qmin = ReadNFloatLike(node.find("Qmin"), Sb_MVA, Ub_kV)
|
|
185
|
+
qmax = ReadNFloatLike(node.find("Qmax"), Sb_MVA, Ub_kV)
|
|
186
|
+
ca = ReadFloatLike(node.find("CostA"), Sb_MVA, Ub_kV)
|
|
187
|
+
cb = ReadFloatLike(node.find("CostB"), Sb_MVA, Ub_kV)
|
|
188
|
+
cc = ReadFloatLike(node.find("CostC"), Sb_MVA, Ub_kV)
|
|
189
|
+
p = ReadNFloatLike(node.find("P"), Sb_MVA, Ub_kV)
|
|
190
|
+
q = ReadNFloatLike(node.find("Q"), Sb_MVA, Ub_kV)
|
|
191
|
+
lat = node.attrib.get("Lat", None)
|
|
192
|
+
if lat is not None: lat = float(lat)
|
|
193
|
+
lon = node.attrib.get("Lon", None)
|
|
194
|
+
if lon is not None: lon = float(lon)
|
|
195
|
+
return Generator(id, busid, ca, cb, cc, pmin, pmax, qmin, qmax, lat, lon, p, q)
|
|
196
|
+
|
|
197
|
+
def toXMLNode(self, Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
|
|
198
|
+
e = Element("gen", {
|
|
199
|
+
"ID": self.ID,
|
|
200
|
+
"Bus": self.BusID,
|
|
201
|
+
})
|
|
202
|
+
if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
|
|
203
|
+
if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
|
|
204
|
+
if Sb_MVA is not None and Sb_kVA is not None:
|
|
205
|
+
raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
|
|
206
|
+
if Sb_MVA is not None:
|
|
207
|
+
mul = Sb_MVA
|
|
208
|
+
unit = ["MW", "Mvar", "$/MWh2", "$/MWh", "$"]
|
|
209
|
+
elif Sb_kVA is not None:
|
|
210
|
+
mul = Sb_kVA
|
|
211
|
+
unit = ["kW", "kvar", "$/kWh2", "$/kWh", "$"]
|
|
212
|
+
else:
|
|
213
|
+
mul = 1
|
|
214
|
+
unit = ["pu", "pu", "$/puh2", "$/puh", "$"]
|
|
215
|
+
if self.Pmin: e.append(Func2Elem(self.Pmin, "Pmin", mul, unit[0]))
|
|
216
|
+
if self.Pmax: e.append(Func2Elem(self.Pmax, "Pmax", mul, unit[0]))
|
|
217
|
+
if self.Qmin: e.append(Func2Elem(self.Qmin, "Qmin", mul, unit[1]))
|
|
218
|
+
if self.Qmax: e.append(Func2Elem(self.Qmax, "Qmax", mul, unit[1]))
|
|
219
|
+
e.append(Func2Elem(self.CostA, "CostA", 1 / (mul*mul), unit[2]))
|
|
220
|
+
e.append(Func2Elem(self.CostB, "CostB", 1 / mul, unit[3]))
|
|
221
|
+
e.append(Func2Elem(self.CostC, "CostC", 1, unit[4]))
|
|
222
|
+
return e
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class GeneratorModel:
|
|
226
|
+
Pmin: TimeFunc #pu
|
|
227
|
+
Pmax: TimeFunc #pu
|
|
228
|
+
Qmin: TimeFunc #pu
|
|
229
|
+
Qmax: TimeFunc #pu
|
|
230
|
+
CostA: TimeFunc #$/(pu Power·h)**2
|
|
231
|
+
CostB: TimeFunc #$/pu Power·h
|
|
232
|
+
CostC: TimeFunc #$
|
|
233
|
+
def __init__(self, pmin_pu: FloatLike, pmax_pu: FloatLike, qmin_pu: FloatLike, qmax_pu: FloatLike,
|
|
234
|
+
costA: FloatLike, costB: FloatLike, costC: FloatLike):
|
|
235
|
+
'''
|
|
236
|
+
Initialize
|
|
237
|
+
pmin_pu: Minimal active power output, pu
|
|
238
|
+
pmax_pu: Maximal active power output, pu
|
|
239
|
+
qmin_pu: Minimal reactive power output, pu
|
|
240
|
+
qmax_pu: Maximal reactive power output, pu
|
|
241
|
+
costA: Secondary cost, $/(pu Power·h)**2
|
|
242
|
+
costB: Primary cost, $/pu Power·h
|
|
243
|
+
costC: Fixed cost, $
|
|
244
|
+
'''
|
|
245
|
+
self.Pmin = Float2Func(pmin_pu)
|
|
246
|
+
self.Pmax = Float2Func(pmax_pu)
|
|
247
|
+
self.Qmin = Float2Func(qmin_pu)
|
|
248
|
+
self.Qmax = Float2Func(qmax_pu)
|
|
249
|
+
self.CostA = Float2Func(costA)
|
|
250
|
+
self.CostB = Float2Func(costB)
|
|
251
|
+
self.CostC = Float2Func(costC)
|
|
252
|
+
|
|
253
|
+
def toGenerator(self, id:str, busid:str):
|
|
254
|
+
return Generator(id, busid, deepcopy(self.CostA), deepcopy(self.CostB),
|
|
255
|
+
deepcopy(self.CostC), deepcopy(self.Pmin), deepcopy(self.Pmax),
|
|
256
|
+
deepcopy(self.Qmin), deepcopy(self.Qmax))
|
|
257
|
+
|
|
258
|
+
@staticmethod
|
|
259
|
+
def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
|
|
260
|
+
pmin = ReadFloatLike(node.find("Pmin"), Sb_MVA, Ub_kV)
|
|
261
|
+
pmax = ReadFloatLike(node.find("Pmax"), Sb_MVA, Ub_kV)
|
|
262
|
+
qmin = ReadFloatLike(node.find("Qmin"), Sb_MVA, Ub_kV)
|
|
263
|
+
qmax = ReadFloatLike(node.find("Qmax"), Sb_MVA, Ub_kV)
|
|
264
|
+
ca = ReadFloatLike(node.find("CostA"), Sb_MVA, Ub_kV)
|
|
265
|
+
cb = ReadFloatLike(node.find("CostB"), Sb_MVA, Ub_kV)
|
|
266
|
+
cc = ReadFloatLike(node.find("CostC"), Sb_MVA, Ub_kV)
|
|
267
|
+
return GeneratorModel(pmin, pmax, qmin, qmax, ca, cb, cc)
|
|
268
|
+
|
|
269
|
+
def toXMLNode(self) -> 'Element':
|
|
270
|
+
e = Element("genmodel")
|
|
271
|
+
e.append(Func2Elem(self.Pmin, "Pmin"))
|
|
272
|
+
e.append(Func2Elem(self.Pmax, "Pmax"))
|
|
273
|
+
e.append(Func2Elem(self.Qmin, "Qmin"))
|
|
274
|
+
e.append(Func2Elem(self.Qmax, "Qmax"))
|
|
275
|
+
e.append(Func2Elem(self.CostA, "CostA"))
|
|
276
|
+
e.append(Func2Elem(self.CostB, "CostB"))
|
|
277
|
+
e.append(Func2Elem(self.CostC, "CostC"))
|
|
278
|
+
return e
|