fpowerkit 0.4.3__tar.gz → 0.5.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.4.3 → fpowerkit-0.5.1}/PKG-INFO +2 -2
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/README.md +8 -2
- fpowerkit-0.5.1/bench_parameter_reuse.py +42 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/__init__.py +4 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/bus.py +183 -183
- fpowerkit-0.5.1/fpowerkit/comb.py +28 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/gen.py +2 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/grid.py +576 -562
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/island.py +5 -5
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/lpwrapper.py +396 -375
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solbase.py +14 -10
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solcmb.py +1 -1
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solcvx.py +3 -1
- fpowerkit-0.5.1/fpowerkit/soldc.py +116 -0
- fpowerkit-0.5.1/fpowerkit/soldcopf.py +185 -0
- fpowerkit-0.5.1/fpowerkit/soldist.py +762 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solldf.py +216 -169
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solldf2.py +190 -163
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/solnt.py +36 -18
- fpowerkit-0.5.1/fpowerkit/solpq.py +282 -0
- fpowerkit-0.5.1/fpowerkit/solsw.py +266 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/pyproject.toml +1 -1
- fpowerkit-0.4.3/fpowerkit/soldist.py +0 -321
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/.gitignore +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/LICENSE +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/desc.md +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/cases.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/ess.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/line.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/pvwind.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/soldss.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/fpowerkit/utils.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/main.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/test.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/test314t.py +0 -0
- {fpowerkit-0.4.3 → fpowerkit-0.5.1}/test_cmb.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# FPowerKit
|
|
1
|
+
# FPowerKit 电网运算组件
|
|
2
2
|
**本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
|
|
3
3
|
|
|
4
4
|
## 许可证变更
|
|
@@ -19,9 +19,15 @@
|
|
|
19
19
|
二次开发请使用完整版体验。
|
|
20
20
|
|
|
21
21
|
## 简介
|
|
22
|
-
- FPowerKit
|
|
22
|
+
- FPowerKit是一个电网求解组件,它包含电网的描述(含母线、发电机、线路、光伏、风机和储能等)和多种内置和外部求解方案:
|
|
23
23
|
+ (内置) 改进DistFlow配电网最优潮流 ([原理介绍](docs/principle.md))
|
|
24
|
+
+ (内置) LinDistFlow配电网最优潮流 (支持cvxpy,scipy两种实现)
|
|
24
25
|
+ (内置) Newton-Raphson潮流计算
|
|
26
|
+
+ (内置) PQ解耦法潮流计算
|
|
27
|
+
+ (内置) 直流潮流计算
|
|
28
|
+
+ (内置) 直流最优潮流计算
|
|
29
|
+
+ (内置) 支持线路开断优化的直流最优潮流计算
|
|
30
|
+
+ (内置) 自定义目标函数的最优化求解
|
|
25
31
|
+ (外接) OpenDSS配电网潮流计算
|
|
26
32
|
+ 最优潮流+潮流计算核验的混合方案
|
|
27
33
|
- 对于最优潮流模型,优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$或者一次函数$f(x)=bx+c$。
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Small smoke benchmark for the parameterized fpowerkit package.
|
|
2
|
+
|
|
3
|
+
Run from the directory containing the modified `fpowerkit` package, e.g.:
|
|
4
|
+
python bench_parameter_reuse.py --solver ECOS --n 20
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import statistics
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
from fpowerkit import PDNCases, DistFlowSolver
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main() -> None:
|
|
16
|
+
ap = argparse.ArgumentParser()
|
|
17
|
+
ap.add_argument("--solver", default="ECOS")
|
|
18
|
+
ap.add_argument("--n", type=int, default=20)
|
|
19
|
+
args = ap.parse_args()
|
|
20
|
+
|
|
21
|
+
grid = PDNCases.IEEE33(changeable_load=True)
|
|
22
|
+
solver = DistFlowSolver(grid, solver=args.solver)
|
|
23
|
+
|
|
24
|
+
times = []
|
|
25
|
+
for k in range(args.n):
|
|
26
|
+
t = (k * 900) % 86400
|
|
27
|
+
tic = time.perf_counter()
|
|
28
|
+
status, obj = solver.solve(t)
|
|
29
|
+
dt = time.perf_counter() - tic
|
|
30
|
+
times.append(dt)
|
|
31
|
+
print(f"k={k:02d} t={t:5d} status={status!s:>12} obj={obj:12.6g} "
|
|
32
|
+
f"wall={dt:.6f}s builds={solver.CVXBuildCount}")
|
|
33
|
+
|
|
34
|
+
if len(times) > 1:
|
|
35
|
+
print("\nfirst solve: ", times[0])
|
|
36
|
+
print("median later: ", statistics.median(times[1:]))
|
|
37
|
+
print("mean later: ", statistics.mean(times[1:]))
|
|
38
|
+
print("CVX build count: ", solver.CVXBuildCount)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import math
|
|
2
|
-
from typing import Optional, Any, Tuple
|
|
3
|
-
from xml.etree.ElementTree import Element
|
|
4
|
-
from feasytools import TimeFunc
|
|
5
|
-
from .utils import *
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Bus(PositionBase):
|
|
9
|
-
Pd: TimeFunc # pu
|
|
10
|
-
Qd: TimeFunc # pu
|
|
11
|
-
ShadowPrice: FloatVar #
|
|
12
|
-
|
|
13
|
-
def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, x: float, y: float, proj:Optional[Any] = None,
|
|
14
|
-
v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
|
|
15
|
-
'''
|
|
16
|
-
Initialize
|
|
17
|
-
id: Bus ID
|
|
18
|
-
pd_pu: Active power demand, pu
|
|
19
|
-
qd_pu: Reactive power demand, pu
|
|
20
|
-
x: X coordinate (for plotting)
|
|
21
|
-
y: Y coordinate (for plotting)
|
|
22
|
-
v_pu: Voltage, pu. None for unfixed voltage
|
|
23
|
-
min_v_pu: Minimal voltage, pu
|
|
24
|
-
max_v_pu: Maximal voltage, pu
|
|
25
|
-
'''
|
|
26
|
-
super().__init__(x, y, proj)
|
|
27
|
-
self._id = id
|
|
28
|
-
self._v = v_pu
|
|
29
|
-
self._fixed_v = v_pu is not None
|
|
30
|
-
self._minv = min_v_pu
|
|
31
|
-
self._maxv = max_v_pu
|
|
32
|
-
self.Pd = Float2Func(pd_pu)
|
|
33
|
-
self.Qd = Float2Func(qd_pu)
|
|
34
|
-
self.ShadowPrice = None
|
|
35
|
-
self._t = theta
|
|
36
|
-
self._fixed_t = self._t is not None
|
|
37
|
-
|
|
38
|
-
def V_var(self, bank: VarBank):
|
|
39
|
-
if self.FixedV:
|
|
40
|
-
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
41
|
-
return bank.fvar(f"{self.ID}_V", self, "_v", self.V, nonneg=True, lb=self.MinV, ub=self.MaxV)
|
|
42
|
-
|
|
43
|
-
def V2_var(self, bank: VarBank):
|
|
44
|
-
if self.FixedV:
|
|
45
|
-
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
46
|
-
v = self.V if self.V is not None else 1.0
|
|
47
|
-
return bank.fvar(f"{self.ID}_V2", self, "_v", v**2, nonneg=True,
|
|
48
|
-
lb=self.MinV**2, ub=self.MaxV**2, reflect=lambda x: math.sqrt(x))
|
|
49
|
-
|
|
50
|
-
def theta_var(self, bank: VarBank):
|
|
51
|
-
if self.FixedTheta:
|
|
52
|
-
raise ValueError("Voltage angle is fixed, cannot create a variable for it.")
|
|
53
|
-
return bank.fvar(f"{self.ID}_theta", self, "_theta", self._t)
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def V(self) -> FloatVar:
|
|
57
|
-
'''Voltage, pu'''
|
|
58
|
-
return self._v
|
|
59
|
-
@V.setter
|
|
60
|
-
def V(self, v: float):
|
|
61
|
-
self._v = v
|
|
62
|
-
|
|
63
|
-
@property
|
|
64
|
-
def theta(self) -> float:
|
|
65
|
-
'''Voltage angle, rad'''
|
|
66
|
-
return self._t if self._t is not None else 0.0
|
|
67
|
-
@theta.setter
|
|
68
|
-
def theta(self, t: float):
|
|
69
|
-
self._t = t
|
|
70
|
-
|
|
71
|
-
@property
|
|
72
|
-
def V_cpx(self) -> Optional[complex]:
|
|
73
|
-
if self._v is None or self._t is None: return None
|
|
74
|
-
return self._v * math.cos(self._t) + 1j * self._v * math.sin(self._t)
|
|
75
|
-
|
|
76
|
-
@property
|
|
77
|
-
def FixedV(self) -> bool:
|
|
78
|
-
'''Whether the voltage is fixed'''
|
|
79
|
-
return self._fixed_v
|
|
80
|
-
|
|
81
|
-
def fixV(self, v: float):
|
|
82
|
-
'''Fix the voltage'''
|
|
83
|
-
self._v = v
|
|
84
|
-
self._fixed_v = True
|
|
85
|
-
|
|
86
|
-
def unfixV(self):
|
|
87
|
-
self._v = None
|
|
88
|
-
self._fixed_v = False
|
|
89
|
-
|
|
90
|
-
@property
|
|
91
|
-
def FixedTheta(self) -> bool:
|
|
92
|
-
'''Whether the voltage angle is fixed'''
|
|
93
|
-
return self._fixed_t
|
|
94
|
-
|
|
95
|
-
def fixTheta(self, theta: float):
|
|
96
|
-
'''Fix the voltage angle'''
|
|
97
|
-
self._t = theta
|
|
98
|
-
self._fixed_t = True
|
|
99
|
-
|
|
100
|
-
def unfixTheta(self):
|
|
101
|
-
'''Unfix the voltage angle'''
|
|
102
|
-
self._t = None
|
|
103
|
-
self._fixed_t = False
|
|
104
|
-
|
|
105
|
-
@property
|
|
106
|
-
def ID(self) -> str:
|
|
107
|
-
'''Name of the bus'''
|
|
108
|
-
return self._id
|
|
109
|
-
|
|
110
|
-
@property
|
|
111
|
-
def MinV(self) -> float:
|
|
112
|
-
'''Minimal voltage, pu'''
|
|
113
|
-
return self._minv
|
|
114
|
-
@MinV.setter
|
|
115
|
-
def MinV(self, v: float):
|
|
116
|
-
assert v >= 0 and v <= self._maxv, "MinV should be in [0, MaxV]"
|
|
117
|
-
self._minv = v
|
|
118
|
-
|
|
119
|
-
@property
|
|
120
|
-
def MaxV(self) -> float:
|
|
121
|
-
'''Maximal voltage, pu'''
|
|
122
|
-
return self._maxv
|
|
123
|
-
@MaxV.setter
|
|
124
|
-
def MaxV(self, v: float):
|
|
125
|
-
assert v >= self._minv, "MaxV should be no less than MinV"
|
|
126
|
-
self._maxv = v
|
|
127
|
-
|
|
128
|
-
def setVRange(self, min_v: float, max_v: float):
|
|
129
|
-
assert 0 <= min_v <= max_v, "MinV should be in [0, MaxV]"
|
|
130
|
-
self._minv = min_v
|
|
131
|
-
self._maxv = max_v
|
|
132
|
-
|
|
133
|
-
def __repr__(self):
|
|
134
|
-
return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
|
|
135
|
-
f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
136
|
-
|
|
137
|
-
def __str__(self):
|
|
138
|
-
return repr(self)
|
|
139
|
-
|
|
140
|
-
def str_t(self, _t: int, /):
|
|
141
|
-
return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
|
|
142
|
-
f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
143
|
-
|
|
144
|
-
@staticmethod
|
|
145
|
-
def fromXML(node: Element, Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Bus':
|
|
146
|
-
id = node.attrib["ID"]
|
|
147
|
-
p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
|
|
148
|
-
q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
|
|
149
|
-
x, y = PositionBase.load_pos_from_xml(node, proj)
|
|
150
|
-
if "V" in node.attrib:
|
|
151
|
-
v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
|
|
152
|
-
minv = maxv = v
|
|
153
|
-
else:
|
|
154
|
-
minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
|
|
155
|
-
maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
|
|
156
|
-
v = None
|
|
157
|
-
return Bus(id, p, q, x, y, proj, v, minv, maxv)
|
|
158
|
-
|
|
159
|
-
def toXMLNode(self, Ub_kV:Optional[float] = None,
|
|
160
|
-
Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
|
|
161
|
-
e = Element("bus", {"ID": self.ID})
|
|
162
|
-
if self.x is not None: e.attrib["x"] = f"{self.x:.6f}"
|
|
163
|
-
if self.y is not None: e.attrib["y"] = f"{self.y:.6f}"
|
|
164
|
-
if self.V is not None and self.FixedV:
|
|
165
|
-
e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
|
|
166
|
-
else:
|
|
167
|
-
e.attrib["MinV"] = str(self.MinV * Ub_kV)+"kV" if Ub_kV else str(self.MinV)
|
|
168
|
-
e.attrib["MaxV"] = str(self.MaxV * Ub_kV)+"kV" if Ub_kV else str(self.MaxV)
|
|
169
|
-
if Sb_MVA is not None and Sb_kVA is not None:
|
|
170
|
-
raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
|
|
171
|
-
if Sb_MVA is not None:
|
|
172
|
-
mul = Sb_MVA
|
|
173
|
-
unit = ["MW", "Mvar"]
|
|
174
|
-
elif Sb_kVA is not None:
|
|
175
|
-
mul = Sb_kVA
|
|
176
|
-
unit = ["kW", "kvar"]
|
|
177
|
-
else:
|
|
178
|
-
mul = 1
|
|
179
|
-
unit = ["pu", "pu"]
|
|
180
|
-
e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
|
|
181
|
-
e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
|
|
182
|
-
return e
|
|
183
|
-
|
|
1
|
+
import math
|
|
2
|
+
from typing import Optional, Any, Tuple
|
|
3
|
+
from xml.etree.ElementTree import Element
|
|
4
|
+
from feasytools import TimeFunc
|
|
5
|
+
from .utils import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Bus(PositionBase):
|
|
9
|
+
Pd: TimeFunc # pu
|
|
10
|
+
Qd: TimeFunc # pu
|
|
11
|
+
ShadowPrice: FloatVar # Marginal objective cost of +1 pu active demand at this bus, $/(pu power*h)
|
|
12
|
+
|
|
13
|
+
def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, x: float, y: float, proj:Optional[Any] = None,
|
|
14
|
+
v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
|
|
15
|
+
'''
|
|
16
|
+
Initialize
|
|
17
|
+
id: Bus ID
|
|
18
|
+
pd_pu: Active power demand, pu
|
|
19
|
+
qd_pu: Reactive power demand, pu
|
|
20
|
+
x: X coordinate (for plotting)
|
|
21
|
+
y: Y coordinate (for plotting)
|
|
22
|
+
v_pu: Voltage, pu. None for unfixed voltage
|
|
23
|
+
min_v_pu: Minimal voltage, pu
|
|
24
|
+
max_v_pu: Maximal voltage, pu
|
|
25
|
+
'''
|
|
26
|
+
super().__init__(x, y, proj)
|
|
27
|
+
self._id = id
|
|
28
|
+
self._v = v_pu
|
|
29
|
+
self._fixed_v = v_pu is not None
|
|
30
|
+
self._minv = min_v_pu
|
|
31
|
+
self._maxv = max_v_pu
|
|
32
|
+
self.Pd = Float2Func(pd_pu)
|
|
33
|
+
self.Qd = Float2Func(qd_pu)
|
|
34
|
+
self.ShadowPrice = None
|
|
35
|
+
self._t = theta
|
|
36
|
+
self._fixed_t = self._t is not None
|
|
37
|
+
|
|
38
|
+
def V_var(self, bank: VarBank):
|
|
39
|
+
if self.FixedV:
|
|
40
|
+
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
41
|
+
return bank.fvar(f"{self.ID}_V", self, "_v", self.V, nonneg=True, lb=self.MinV, ub=self.MaxV)
|
|
42
|
+
|
|
43
|
+
def V2_var(self, bank: VarBank):
|
|
44
|
+
if self.FixedV:
|
|
45
|
+
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
46
|
+
v = self.V if self.V is not None else 1.0
|
|
47
|
+
return bank.fvar(f"{self.ID}_V2", self, "_v", v**2, nonneg=True,
|
|
48
|
+
lb=self.MinV**2, ub=self.MaxV**2, reflect=lambda x: math.sqrt(x))
|
|
49
|
+
|
|
50
|
+
def theta_var(self, bank: VarBank):
|
|
51
|
+
if self.FixedTheta:
|
|
52
|
+
raise ValueError("Voltage angle is fixed, cannot create a variable for it.")
|
|
53
|
+
return bank.fvar(f"{self.ID}_theta", self, "_theta", self._t)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def V(self) -> FloatVar:
|
|
57
|
+
'''Voltage, pu'''
|
|
58
|
+
return self._v
|
|
59
|
+
@V.setter
|
|
60
|
+
def V(self, v: float):
|
|
61
|
+
self._v = v
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def theta(self) -> float:
|
|
65
|
+
'''Voltage angle, rad'''
|
|
66
|
+
return self._t if self._t is not None else 0.0
|
|
67
|
+
@theta.setter
|
|
68
|
+
def theta(self, t: float):
|
|
69
|
+
self._t = t
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def V_cpx(self) -> Optional[complex]:
|
|
73
|
+
if self._v is None or self._t is None: return None
|
|
74
|
+
return self._v * math.cos(self._t) + 1j * self._v * math.sin(self._t)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def FixedV(self) -> bool:
|
|
78
|
+
'''Whether the voltage is fixed'''
|
|
79
|
+
return self._fixed_v
|
|
80
|
+
|
|
81
|
+
def fixV(self, v: float):
|
|
82
|
+
'''Fix the voltage'''
|
|
83
|
+
self._v = v
|
|
84
|
+
self._fixed_v = True
|
|
85
|
+
|
|
86
|
+
def unfixV(self):
|
|
87
|
+
self._v = None
|
|
88
|
+
self._fixed_v = False
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def FixedTheta(self) -> bool:
|
|
92
|
+
'''Whether the voltage angle is fixed'''
|
|
93
|
+
return self._fixed_t
|
|
94
|
+
|
|
95
|
+
def fixTheta(self, theta: float):
|
|
96
|
+
'''Fix the voltage angle'''
|
|
97
|
+
self._t = theta
|
|
98
|
+
self._fixed_t = True
|
|
99
|
+
|
|
100
|
+
def unfixTheta(self):
|
|
101
|
+
'''Unfix the voltage angle'''
|
|
102
|
+
self._t = None
|
|
103
|
+
self._fixed_t = False
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def ID(self) -> str:
|
|
107
|
+
'''Name of the bus'''
|
|
108
|
+
return self._id
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def MinV(self) -> float:
|
|
112
|
+
'''Minimal voltage, pu'''
|
|
113
|
+
return self._minv
|
|
114
|
+
@MinV.setter
|
|
115
|
+
def MinV(self, v: float):
|
|
116
|
+
assert v >= 0 and v <= self._maxv, "MinV should be in [0, MaxV]"
|
|
117
|
+
self._minv = v
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def MaxV(self) -> float:
|
|
121
|
+
'''Maximal voltage, pu'''
|
|
122
|
+
return self._maxv
|
|
123
|
+
@MaxV.setter
|
|
124
|
+
def MaxV(self, v: float):
|
|
125
|
+
assert v >= self._minv, "MaxV should be no less than MinV"
|
|
126
|
+
self._maxv = v
|
|
127
|
+
|
|
128
|
+
def setVRange(self, min_v: float, max_v: float):
|
|
129
|
+
assert 0 <= min_v <= max_v, "MinV should be in [0, MaxV]"
|
|
130
|
+
self._minv = min_v
|
|
131
|
+
self._maxv = max_v
|
|
132
|
+
|
|
133
|
+
def __repr__(self):
|
|
134
|
+
return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
|
|
135
|
+
f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
136
|
+
|
|
137
|
+
def __str__(self):
|
|
138
|
+
return repr(self)
|
|
139
|
+
|
|
140
|
+
def str_t(self, _t: int, /):
|
|
141
|
+
return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
|
|
142
|
+
f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
|
|
143
|
+
|
|
144
|
+
@staticmethod
|
|
145
|
+
def fromXML(node: Element, Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Bus':
|
|
146
|
+
id = node.attrib["ID"]
|
|
147
|
+
p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
|
|
148
|
+
q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
|
|
149
|
+
x, y = PositionBase.load_pos_from_xml(node, proj)
|
|
150
|
+
if "V" in node.attrib:
|
|
151
|
+
v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
|
|
152
|
+
minv = maxv = v
|
|
153
|
+
else:
|
|
154
|
+
minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
|
|
155
|
+
maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
|
|
156
|
+
v = None
|
|
157
|
+
return Bus(id, p, q, x, y, proj, v, minv, maxv)
|
|
158
|
+
|
|
159
|
+
def toXMLNode(self, Ub_kV:Optional[float] = None,
|
|
160
|
+
Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
|
|
161
|
+
e = Element("bus", {"ID": self.ID})
|
|
162
|
+
if self.x is not None: e.attrib["x"] = f"{self.x:.6f}"
|
|
163
|
+
if self.y is not None: e.attrib["y"] = f"{self.y:.6f}"
|
|
164
|
+
if self.V is not None and self.FixedV:
|
|
165
|
+
e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
|
|
166
|
+
else:
|
|
167
|
+
e.attrib["MinV"] = str(self.MinV * Ub_kV)+"kV" if Ub_kV else str(self.MinV)
|
|
168
|
+
e.attrib["MaxV"] = str(self.MaxV * Ub_kV)+"kV" if Ub_kV else str(self.MaxV)
|
|
169
|
+
if Sb_MVA is not None and Sb_kVA is not None:
|
|
170
|
+
raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
|
|
171
|
+
if Sb_MVA is not None:
|
|
172
|
+
mul = Sb_MVA
|
|
173
|
+
unit = ["MW", "Mvar"]
|
|
174
|
+
elif Sb_kVA is not None:
|
|
175
|
+
mul = Sb_kVA
|
|
176
|
+
unit = ["kW", "kvar"]
|
|
177
|
+
else:
|
|
178
|
+
mul = 1
|
|
179
|
+
unit = ["pu", "pu"]
|
|
180
|
+
e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
|
|
181
|
+
e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
|
|
182
|
+
return e
|
|
183
|
+
|
|
184
184
|
__all__ = ["Bus"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
def combine_py_files_to_md(root_dir, output_md):
|
|
5
|
+
"""
|
|
6
|
+
Combines all .py files in the root directory and its subdirectories into a single Markdown file.
|
|
7
|
+
Each .py file is represented as a section with a header and a code block.
|
|
8
|
+
"""
|
|
9
|
+
with open(output_md, 'w', encoding='utf-8') as md_file:
|
|
10
|
+
for py_file in pathlib.Path(root_dir).rglob('*.py'):
|
|
11
|
+
relative_path = py_file.relative_to(root_dir)
|
|
12
|
+
if relative_path.name == pathlib.Path(__file__).name:
|
|
13
|
+
continue
|
|
14
|
+
md_file.write(f"## {relative_path}\n\n")
|
|
15
|
+
md_file.write("```python\n")
|
|
16
|
+
try:
|
|
17
|
+
with open(py_file, 'r', encoding='utf-8') as f:
|
|
18
|
+
content = f.read()
|
|
19
|
+
md_file.write(content)
|
|
20
|
+
except Exception as e:
|
|
21
|
+
md_file.write(f"# Error reading file: {e}\n")
|
|
22
|
+
md_file.write("\n```\n\n")
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
26
|
+
output_file = os.path.join(current_dir, "fpowerkit.md")
|
|
27
|
+
combine_py_files_to_md(current_dir, output_file)
|
|
28
|
+
print(f"Combined Markdown file created at: {output_file}")
|
|
@@ -14,6 +14,7 @@ class Generator(PositionBase):
|
|
|
14
14
|
CostA: TimeFunc #$/(pu Power·h)**2
|
|
15
15
|
CostB: TimeFunc #$/pu Power·h
|
|
16
16
|
CostC: TimeFunc #$
|
|
17
|
+
QtoPRatio: Optional[float]
|
|
17
18
|
|
|
18
19
|
def __init__(self, id: str, busid: str,
|
|
19
20
|
costA: FloatLike, costB: FloatLike, costC: FloatLike,
|
|
@@ -74,6 +75,7 @@ class Generator(PositionBase):
|
|
|
74
75
|
self.CostC = Float2Func(costC)
|
|
75
76
|
self.CostShadow = None
|
|
76
77
|
self.active = active
|
|
78
|
+
self.QtoPRatio = None
|
|
77
79
|
|
|
78
80
|
def P_var(self, bank: VarBank, t:int = 0):
|
|
79
81
|
'''Return a variable for the active power output'''
|