fpowerkit 0.3.2__tar.gz → 0.3.4__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.3.4/.gitignore +9 -0
- {fpowerkit-0.3.2/fpowerkit.egg-info → fpowerkit-0.3.4}/PKG-INFO +70 -43
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/README.md +17 -4
- fpowerkit-0.3.2/PKG-INFO → fpowerkit-0.3.4/desc.md +22 -23
- fpowerkit-0.3.4/fpowerkit/__init__.py +16 -0
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/bus.py +52 -6
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/cases.py +3 -1
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/ess.py +52 -6
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/gen.py +32 -2
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/grid.py +10 -8
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/island.py +15 -4
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/line.py +28 -2
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/pvwind.py +16 -1
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/solbase.py +5 -3
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/solcmb.py +7 -5
- fpowerkit-0.3.4/fpowerkit/solcvx.py +58 -0
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/soldist.py +7 -5
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/soldss.py +5 -1
- fpowerkit-0.3.4/fpowerkit/solldf.py +91 -0
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/solnt.py +11 -3
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/fpowerkit/utils.py +97 -2
- fpowerkit-0.3.4/main.py +90 -0
- fpowerkit-0.3.4/pyproject.toml +51 -0
- fpowerkit-0.3.4/test.py +32 -0
- fpowerkit-0.3.2/fpowerkit/__init__.py +0 -7
- fpowerkit-0.3.2/fpowerkit.egg-info/SOURCES.txt +0 -23
- fpowerkit-0.3.2/fpowerkit.egg-info/dependency_links.txt +0 -1
- fpowerkit-0.3.2/fpowerkit.egg-info/requires.txt +0 -2
- fpowerkit-0.3.2/fpowerkit.egg-info/top_level.txt +0 -1
- fpowerkit-0.3.2/setup.cfg +0 -4
- fpowerkit-0.3.2/setup.py +0 -21
- {fpowerkit-0.3.2 → fpowerkit-0.3.4}/LICENSE +0 -0
|
@@ -1,43 +1,70 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
2
|
-
Name: fpowerkit
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary: A PDN solver with multiple solutions.
|
|
5
|
-
Author:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Classifier:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Requires-Dist: feasytools>=0.0.21
|
|
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
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fpowerkit
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Summary: A PDN solver with multiple solutions.
|
|
5
|
+
Author: fmy-xfk
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Requires-Dist: feasytools>=0.0.21
|
|
13
|
+
Provides-Extra: distflow
|
|
14
|
+
Requires-Dist: cvxpy; extra == 'distflow'
|
|
15
|
+
Requires-Dist: ecos; extra == 'distflow'
|
|
16
|
+
Requires-Dist: numpy>=1.19.0; extra == 'distflow'
|
|
17
|
+
Provides-Extra: dss
|
|
18
|
+
Requires-Dist: numpy>=1.19.0; extra == 'dss'
|
|
19
|
+
Requires-Dist: py-dss-interface; extra == 'dss'
|
|
20
|
+
Provides-Extra: full
|
|
21
|
+
Requires-Dist: cvxpy; extra == 'full'
|
|
22
|
+
Requires-Dist: ecos; extra == 'full'
|
|
23
|
+
Requires-Dist: numpy>=1.19.0; extra == 'full'
|
|
24
|
+
Requires-Dist: py-dss-interface; extra == 'full'
|
|
25
|
+
Provides-Extra: newton
|
|
26
|
+
Requires-Dist: numpy>=1.19.0; extra == 'newton'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# FPowerKit - A power distribution network calculation component
|
|
30
|
+
|
|
31
|
+
This is a package designed for power distribution network description and solving. Solvers include Newton method, DistFlow and OpenDSS.
|
|
32
|
+
|
|
33
|
+
This package is affiliated to V2Sim, an open-aource microscopic V2G simulation platform in urban power and transportation network. If you are using the modified DistFlow model in this package, please cite the [paper](https://ieeexplore.ieee.org/document/10970754):
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
@ARTICLE{10970754,
|
|
37
|
+
author={Qian, Tao and Fang, Mingyu and Hu, Qinran and Shao, Chengcheng and Zheng, Junyi},
|
|
38
|
+
journal={IEEE Transactions on Smart Grid},
|
|
39
|
+
title={V2Sim: An Open-Source Microscopic V2G Simulation Platform in Urban Power and Transportation Network},
|
|
40
|
+
year={2025},
|
|
41
|
+
volume={16},
|
|
42
|
+
number={4},
|
|
43
|
+
pages={3167-3178},
|
|
44
|
+
keywords={Vehicle-to-grid;Partial discharges;Microscopy;Batteries;Planning;Discharges (electric);Optimization;Vehicle dynamics;Transportation;Roads;EV charging load simulation;microscopic EV behavior;vehicle-to-grid;charging station fault sensing},
|
|
45
|
+
doi={10.1109/TSG.2025.3560976}}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Installation options
|
|
49
|
+
If you want to use different features, install with different command:
|
|
50
|
+
|
|
51
|
+
|Feature|Command|
|
|
52
|
+
|---|---|
|
|
53
|
+
|Only grid description|`pip install fpowerkit`|
|
|
54
|
+
|Y matrix & Newton|`pip install fpowerkit[newton]`|
|
|
55
|
+
|OpenDSS|`pip install fpowerkit[dss]`|
|
|
56
|
+
|DistFlow|`pip install fpowerkit[distflow]`|
|
|
57
|
+
|All|`pip install fpowerkit[full]`|
|
|
58
|
+
|
|
59
|
+
Secondary development on this package requires all features.
|
|
60
|
+
|
|
61
|
+
### Introduction
|
|
62
|
+
There are 3 modes for this package to work:
|
|
63
|
+
|
|
64
|
+
- Optimal power flow (OPF): Use cvxpy to solve the optimal power flow and determine the output of the generators.
|
|
65
|
+
|
|
66
|
+
- Power flow calculation: Use OpenDSS/Newton-Raphson method to solve the power flow.
|
|
67
|
+
|
|
68
|
+
- Hybrid: Use OPF to determine the initial value, and then use OpenDSS/Newton-Raphson to perform accurate calculation.
|
|
69
|
+
|
|
70
|
+
Please visit https://gitee.com/fmy_xfk/fpowerkit to read the detailed introduction and the usage.
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# FPowerKit 配电网运算组件
|
|
2
2
|
**本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
|
|
3
3
|
|
|
4
|
+
## 安装
|
|
5
|
+
不同的体验所需的安装命令有所不同:
|
|
6
|
+
|
|
7
|
+
|体验|安装命令|
|
|
8
|
+
|---|---|
|
|
9
|
+
|仅电网描述|`pip install fpowerkit`|
|
|
10
|
+
|导纳矩阵和牛顿法|`pip install fpowerkit[newton]`|
|
|
11
|
+
|OpenDSS求解|`pip install fpowerkit[dss]`|
|
|
12
|
+
|DistFlow模型|`pip install fpowerkit[distflow]`|
|
|
13
|
+
|完整版|`pip install fpowerkit[full]`|
|
|
14
|
+
|
|
15
|
+
二次开发请使用完整版体验。
|
|
16
|
+
|
|
4
17
|
## 简介
|
|
5
18
|
- FPowerKit是一个配电网求解组件,它包含电网的描述(含母线、发电机、线路、光伏、风机和储能等)和多种内置和外部求解方案:
|
|
6
19
|
+ (内置) 改进DistFlow配电网最优潮流 ([原理介绍](docs/principle.md))
|
|
@@ -30,16 +43,16 @@ grid_obj69 = PDNCases.IEEE69()
|
|
|
30
43
|
|
|
31
44
|
如果你正在使用本项目中的**改进配电网DistFlow模型**,请引用[V2Sim正式版论文](https://ieeexplore.ieee.org/document/10970754):
|
|
32
45
|
|
|
33
|
-
```
|
|
34
46
|
@ARTICLE{10970754,
|
|
35
47
|
author={Qian, Tao and Fang, Mingyu and Hu, Qinran and Shao, Chengcheng and Zheng, Junyi},
|
|
36
48
|
journal={IEEE Transactions on Smart Grid},
|
|
37
49
|
title={V2Sim: An Open-Source Microscopic V2G Simulation Platform in Urban Power and Transportation Network},
|
|
38
50
|
year={2025},
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
volume={16},
|
|
52
|
+
number={4},
|
|
53
|
+
pages={3167-3178},
|
|
54
|
+
keywords={Vehicle-to-grid;Partial discharges;Microscopy;Batteries;Planning;Discharges (electric);Optimization;Vehicle dynamics;Transportation;Roads;EV charging load simulation;microscopic EV behavior;vehicle-to-grid;charging station fault sensing},
|
|
41
55
|
doi={10.1109/TSG.2025.3560976}}
|
|
42
|
-
|
|
43
56
|
```
|
|
44
57
|
|
|
45
58
|
IEEE33和IEEE69节点的配网数据从公开渠道收集。除配网数据以外,本仓库代码均遵循LGPL3.0协议使用。
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: fpowerkit
|
|
3
|
-
Version: 0.3.2
|
|
4
|
-
Summary: A PDN solver with multiple solutions.
|
|
5
|
-
Author: fmy_xfk
|
|
6
|
-
Classifier: Programming Language :: Python :: 3
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Operating System :: OS Independent
|
|
9
|
-
Requires-Python: >=3.8
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
Requires-Dist: feasytools>=0.0.21
|
|
13
|
-
Requires-Dist: numpy>=1.19.0
|
|
14
|
-
|
|
15
1
|
# FPowerKit - A power distribution network calculation component
|
|
16
2
|
|
|
17
|
-
This is a package designed for power distribution network solving.
|
|
3
|
+
This is a package designed for power distribution network description and solving. Solvers include Newton method, DistFlow and OpenDSS.
|
|
18
4
|
|
|
19
5
|
This package is affiliated to V2Sim, an open-aource microscopic V2G simulation platform in urban power and transportation network. If you are using the modified DistFlow model in this package, please cite the [paper](https://ieeexplore.ieee.org/document/10970754):
|
|
20
6
|
|
|
@@ -24,20 +10,33 @@ This package is affiliated to V2Sim, an open-aource microscopic V2G simulation p
|
|
|
24
10
|
journal={IEEE Transactions on Smart Grid},
|
|
25
11
|
title={V2Sim: An Open-Source Microscopic V2G Simulation Platform in Urban Power and Transportation Network},
|
|
26
12
|
year={2025},
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
volume={16},
|
|
14
|
+
number={4},
|
|
15
|
+
pages={3167-3178},
|
|
16
|
+
keywords={Vehicle-to-grid;Partial discharges;Microscopy;Batteries;Planning;Discharges (electric);Optimization;Vehicle dynamics;Transportation;Roads;EV charging load simulation;microscopic EV behavior;vehicle-to-grid;charging station fault sensing},
|
|
29
17
|
doi={10.1109/TSG.2025.3560976}}
|
|
30
|
-
|
|
31
18
|
```
|
|
32
19
|
|
|
20
|
+
### Installation options
|
|
21
|
+
If you want to use different features, install with different command:
|
|
22
|
+
|
|
23
|
+
|Feature|Command|
|
|
24
|
+
|---|---|
|
|
25
|
+
|Only grid description|`pip install fpowerkit`|
|
|
26
|
+
|Y matrix & Newton|`pip install fpowerkit[newton]`|
|
|
27
|
+
|OpenDSS|`pip install fpowerkit[dss]`|
|
|
28
|
+
|DistFlow|`pip install fpowerkit[distflow]`|
|
|
29
|
+
|All|`pip install fpowerkit[full]`|
|
|
30
|
+
|
|
31
|
+
Secondary development on this package requires all features.
|
|
32
|
+
|
|
33
|
+
### Introduction
|
|
33
34
|
There are 3 modes for this package to work:
|
|
34
35
|
|
|
35
36
|
- Optimal power flow (OPF): Use cvxpy to solve the optimal power flow and determine the output of the generators.
|
|
36
37
|
|
|
37
|
-
- Power flow calculation: Use OpenDSS/
|
|
38
|
-
|
|
39
|
-
- Hybrid: Use OPF to determine the initial value, and then use OpenDSS/GridCal/Inner Newton-Raphson to perform accurate calculation.
|
|
38
|
+
- Power flow calculation: Use OpenDSS/Newton-Raphson method to solve the power flow.
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
- Hybrid: Use OPF to determine the initial value, and then use OpenDSS/Newton-Raphson to perform accurate calculation.
|
|
42
41
|
|
|
43
|
-
Please visit https://gitee.com/fmy_xfk/fpowerkit to read the detailed introduction and the usage.
|
|
42
|
+
Please visit https://gitee.com/fmy_xfk/fpowerkit to read the detailed introduction and the usage.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .bus import *
|
|
2
|
+
from .cases import *
|
|
3
|
+
from .ess import *
|
|
4
|
+
from .gen import *
|
|
5
|
+
from .grid import *
|
|
6
|
+
from .island import *
|
|
7
|
+
from .line import *
|
|
8
|
+
from .pvwind import *
|
|
9
|
+
from .solbase import *
|
|
10
|
+
from .solcmb import *
|
|
11
|
+
from .solcvx import *
|
|
12
|
+
from .soldist import *
|
|
13
|
+
from .soldss import *
|
|
14
|
+
from .solldf import *
|
|
15
|
+
from .solnt import *
|
|
16
|
+
from .utils import *
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import math
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from xml.etree.ElementTree import Element
|
|
4
|
+
from feasytools import TimeFunc
|
|
2
5
|
from .utils import *
|
|
3
6
|
|
|
4
7
|
|
|
@@ -10,7 +13,7 @@ class Bus:
|
|
|
10
13
|
Lon: NFloat
|
|
11
14
|
|
|
12
15
|
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')):
|
|
16
|
+
v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
|
|
14
17
|
'''
|
|
15
18
|
Initialize
|
|
16
19
|
id: Bus ID
|
|
@@ -24,7 +27,7 @@ class Bus:
|
|
|
24
27
|
'''
|
|
25
28
|
self._id = id
|
|
26
29
|
self._v = v_pu
|
|
27
|
-
self._fixed_v =
|
|
30
|
+
self._fixed_v = v_pu is not None
|
|
28
31
|
self._minv = min_v_pu
|
|
29
32
|
self._maxv = max_v_pu
|
|
30
33
|
self.Pd = Float2Func(pd_pu)
|
|
@@ -32,8 +35,26 @@ class Bus:
|
|
|
32
35
|
self.ShadowPrice = None
|
|
33
36
|
self.Lat = lat
|
|
34
37
|
self.Lon = lon
|
|
35
|
-
self.
|
|
38
|
+
self._t = theta
|
|
39
|
+
self._fixed_t = self._t is not None
|
|
36
40
|
|
|
41
|
+
def V_var(self, bank: VarBank):
|
|
42
|
+
if self.FixedV:
|
|
43
|
+
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
44
|
+
return bank.fvar(f"{self.ID}_V", self, "_v", self.V, nonneg=True, lb=self.MinV, ub=self.MaxV)
|
|
45
|
+
|
|
46
|
+
def V2_var(self, bank: VarBank):
|
|
47
|
+
if self.FixedV:
|
|
48
|
+
raise ValueError("Voltage is fixed, cannot create a variable for it.")
|
|
49
|
+
v = self.V if self.V is not None else 1.0
|
|
50
|
+
return bank.fvar(f"{self.ID}_V2", self, "_v", v**2, nonneg=True,
|
|
51
|
+
lb=self.MinV**2, ub=self.MaxV**2, reflect=lambda x: math.sqrt(x))
|
|
52
|
+
|
|
53
|
+
def theta_var(self, bank: VarBank):
|
|
54
|
+
if self.FixedTheta:
|
|
55
|
+
raise ValueError("Voltage angle is fixed, cannot create a variable for it.")
|
|
56
|
+
return bank.fvar(f"{self.ID}_theta", self, "_theta", self._t)
|
|
57
|
+
|
|
37
58
|
@property
|
|
38
59
|
def V(self) -> FloatVar:
|
|
39
60
|
'''Voltage, pu'''
|
|
@@ -41,11 +62,19 @@ class Bus:
|
|
|
41
62
|
@V.setter
|
|
42
63
|
def V(self, v: float):
|
|
43
64
|
self._v = v
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def theta(self) -> float:
|
|
68
|
+
'''Voltage angle, rad'''
|
|
69
|
+
return self._t if self._t is not None else 0.0
|
|
70
|
+
@theta.setter
|
|
71
|
+
def theta(self, t: float):
|
|
72
|
+
self._t = t
|
|
44
73
|
|
|
45
74
|
@property
|
|
46
75
|
def V_cpx(self) -> Optional[complex]:
|
|
47
|
-
if self._v is None: return None
|
|
48
|
-
return self._v * math.cos(self.
|
|
76
|
+
if self._v is None or self._t is None: return None
|
|
77
|
+
return self._v * math.cos(self._t) + 1j * self._v * math.sin(self._t)
|
|
49
78
|
|
|
50
79
|
@property
|
|
51
80
|
def FixedV(self) -> bool:
|
|
@@ -61,6 +90,21 @@ class Bus:
|
|
|
61
90
|
self._v = None
|
|
62
91
|
self._fixed_v = False
|
|
63
92
|
|
|
93
|
+
@property
|
|
94
|
+
def FixedTheta(self) -> bool:
|
|
95
|
+
'''Whether the voltage angle is fixed'''
|
|
96
|
+
return self._fixed_t
|
|
97
|
+
|
|
98
|
+
def fixTheta(self, theta: float):
|
|
99
|
+
'''Fix the voltage angle'''
|
|
100
|
+
self._t = theta
|
|
101
|
+
self._fixed_t = True
|
|
102
|
+
|
|
103
|
+
def unfixTheta(self):
|
|
104
|
+
'''Unfix the voltage angle'''
|
|
105
|
+
self._t = None
|
|
106
|
+
self._fixed_t = False
|
|
107
|
+
|
|
64
108
|
@property
|
|
65
109
|
def ID(self) -> str:
|
|
66
110
|
'''Name of the bus'''
|
|
@@ -150,4 +194,6 @@ class Bus:
|
|
|
150
194
|
unit = ["pu", "pu"]
|
|
151
195
|
e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
|
|
152
196
|
e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
|
|
153
|
-
return e
|
|
197
|
+
return e
|
|
198
|
+
|
|
199
|
+
__all__ = ["Bus"]
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
from enum import IntEnum, Enum
|
|
2
1
|
import math
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from enum import IntEnum, Enum
|
|
4
|
+
from xml.etree.ElementTree import Element
|
|
3
5
|
from feasytools import RangeList
|
|
4
6
|
from .utils import *
|
|
5
7
|
|
|
@@ -7,6 +9,7 @@ class ESSPolicy(Enum):
|
|
|
7
9
|
Manual = "Manual" # Charging/discharging manually
|
|
8
10
|
Time = "Time" # Charging/discharging at given period
|
|
9
11
|
Price = "Price" # Charging at low price, discharging at high price
|
|
12
|
+
ByOptim = "Optim" # Charging according to solver optimization
|
|
10
13
|
|
|
11
14
|
class ESSManualState(IntEnum):
|
|
12
15
|
Idle = 0
|
|
@@ -51,8 +54,45 @@ class ESS:
|
|
|
51
54
|
self._cprice = cprice
|
|
52
55
|
self._dprice = dprice
|
|
53
56
|
self._manstate = ESSManualState.Idle
|
|
57
|
+
self._manpower = 0.0
|
|
54
58
|
self.P:FloatVar = None
|
|
55
59
|
|
|
60
|
+
def setManualPower(self, power: float):
|
|
61
|
+
'''
|
|
62
|
+
Set the manual power of the ESS
|
|
63
|
+
power: Power to charge/discharge, pu. Positive value means charging, negative value means discharging, 0.0 means idle.
|
|
64
|
+
'''
|
|
65
|
+
if power > 0:
|
|
66
|
+
self.setManualState(ESSManualState.Charge, power)
|
|
67
|
+
elif power < 0:
|
|
68
|
+
self.setManualState(ESSManualState.Discharge, -power)
|
|
69
|
+
else:
|
|
70
|
+
self.setManualState(ESSManualState.Idle, 0.0)
|
|
71
|
+
|
|
72
|
+
def setManualState(self, state: ESSManualState, power: Optional[float] = None):
|
|
73
|
+
'''
|
|
74
|
+
Set the manual state of the ESS
|
|
75
|
+
state: ESSManualState
|
|
76
|
+
power: Power to charge/discharge, pu, absolute value. If None, use MaxPc/MaxPd.
|
|
77
|
+
'''
|
|
78
|
+
self._manstate = state
|
|
79
|
+
if state == ESSManualState.Charge:
|
|
80
|
+
assert power is None or power >= 0, "Power must be >= 0 or None"
|
|
81
|
+
if power is None:
|
|
82
|
+
self._manpower = self.MaxPc
|
|
83
|
+
else:
|
|
84
|
+
self._manpower = power
|
|
85
|
+
elif state == ESSManualState.Discharge:
|
|
86
|
+
assert power is None or power >= 0, "Power must be >= 0 or None"
|
|
87
|
+
if power is None:
|
|
88
|
+
self._manpower = -self.MaxPd
|
|
89
|
+
else:
|
|
90
|
+
self._manpower = -power
|
|
91
|
+
else:
|
|
92
|
+
assert power == 0.0 or power is None, "Power must be 0 or None when state is Idle"
|
|
93
|
+
self._manpower = 0.0
|
|
94
|
+
self.P = self._manpower
|
|
95
|
+
|
|
56
96
|
@property
|
|
57
97
|
def Q(self) -> float:
|
|
58
98
|
'''Reactive power output'''
|
|
@@ -63,9 +103,9 @@ class ESS:
|
|
|
63
103
|
'''State of charge'''
|
|
64
104
|
return self._elec / self._cap
|
|
65
105
|
|
|
66
|
-
def Apply(self,
|
|
106
|
+
def Apply(self, dur_second:int):
|
|
67
107
|
if self.P is not None:
|
|
68
|
-
dur =
|
|
108
|
+
dur = dur_second / 3600
|
|
69
109
|
if self.P < 0:
|
|
70
110
|
return self.Discharge(-self.P, dur)
|
|
71
111
|
else:
|
|
@@ -81,6 +121,10 @@ class ESS:
|
|
|
81
121
|
'''Calculate reactive power'''
|
|
82
122
|
return P * self.tanPhi
|
|
83
123
|
|
|
124
|
+
def P_var(self, bank: VarBank):
|
|
125
|
+
'''Return a variable for the power of the ESS. Positive value means charging, negative value means discharging.'''
|
|
126
|
+
return bank.fvar(f"{self.ID}_P", self, "P", value=self.P)
|
|
127
|
+
|
|
84
128
|
def GetLoad(self, t: int, cprice:float, dprice:float) -> 'tuple[float, float]':
|
|
85
129
|
'''
|
|
86
130
|
Get the power of the ESS. Return p+jq.
|
|
@@ -89,9 +133,9 @@ class ESS:
|
|
|
89
133
|
'''
|
|
90
134
|
if self._policy == ESSPolicy.Manual:
|
|
91
135
|
if self._manstate == ESSManualState.Charge and self._elec < self._cap:
|
|
92
|
-
return self.
|
|
136
|
+
return self._manpower, self.__q(self._manpower)
|
|
93
137
|
elif self._manstate == ESSManualState.Discharge and self._elec > 0:
|
|
94
|
-
return
|
|
138
|
+
return self._manpower, -self.__q(-self._manpower)
|
|
95
139
|
elif self._policy == ESSPolicy.Time:
|
|
96
140
|
if self._ctime is not None and t in self._ctime and self._elec < self._cap:
|
|
97
141
|
return self._pc_max, self.__q(self._pc_max)
|
|
@@ -265,4 +309,6 @@ class ESS:
|
|
|
265
309
|
e.attrib["init_elec"] = str(self._elec*mul) + unit[0]
|
|
266
310
|
if self._cprice: e.attrib["cprice"] = str(self._cprice*mul) + unit[2]
|
|
267
311
|
if self._dprice: e.attrib["dprice"] = str(self._dprice*mul) + unit[2]
|
|
268
|
-
return e
|
|
312
|
+
return e
|
|
313
|
+
|
|
314
|
+
__all__ = ["ESS", "ESSPolicy", "ESSManualState"]
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
from copy import deepcopy
|
|
2
|
+
from typing import Optional, Union
|
|
3
|
+
from xml.etree.ElementTree import Element
|
|
4
|
+
from feasytools import TimeFunc
|
|
2
5
|
from .utils import *
|
|
3
6
|
|
|
4
7
|
NFloatOrFunc = Union[None, float, TimeFunc]
|
|
@@ -17,7 +20,7 @@ class Generator:
|
|
|
17
20
|
pmin_pu: NFloatLike = None, pmax_pu: NFloatLike = None,
|
|
18
21
|
qmin_pu: NFloatLike = None, qmax_pu: NFloatLike = None,
|
|
19
22
|
Lat: NFloat = None, Lon: NFloat = None,
|
|
20
|
-
P: NFloatLike = None, Q: NFloatLike = None,
|
|
23
|
+
P: NFloatLike = None, Q: NFloatLike = None, active: bool = True
|
|
21
24
|
):
|
|
22
25
|
'''
|
|
23
26
|
Initialize
|
|
@@ -71,6 +74,29 @@ class Generator:
|
|
|
71
74
|
self.CostB = Float2Func(costB)
|
|
72
75
|
self.CostC = Float2Func(costC)
|
|
73
76
|
self.CostShadow = None
|
|
77
|
+
self.active = active
|
|
78
|
+
|
|
79
|
+
def P_var(self, bank: VarBank, t:int = 0):
|
|
80
|
+
'''Return a variable for the active power output'''
|
|
81
|
+
if self.FixedP:
|
|
82
|
+
raise ValueError("Active power output is fixed, cannot create a variable for it.")
|
|
83
|
+
pmin = self.Pmin(t) if isinstance(self.Pmin, TimeFunc) else self.Pmin
|
|
84
|
+
pmax = self.Pmax(t) if isinstance(self.Pmax, TimeFunc) else self.Pmax
|
|
85
|
+
p = self.P(t) if isinstance(self.P, TimeFunc) else self.P
|
|
86
|
+
return bank.fvar(f"{self.ID}_P", self, "_p", p, lb=pmin, ub=pmax)
|
|
87
|
+
|
|
88
|
+
def Q_var(self, bank: VarBank, t:int = 0):
|
|
89
|
+
if self.FixedQ:
|
|
90
|
+
raise ValueError("Reactive power output is fixed, cannot create a variable for it.")
|
|
91
|
+
qmin = self.Qmin(t) if isinstance(self.Qmin, TimeFunc) else self.Qmin
|
|
92
|
+
qmax = self.Qmax(t) if isinstance(self.Qmax, TimeFunc) else self.Qmax
|
|
93
|
+
q = self.Q(t) if isinstance(self.Q, TimeFunc) else self.Q
|
|
94
|
+
return bank.fvar(f"{self.ID}_Q", self, "_q", q, lb=qmin, ub=qmax)
|
|
95
|
+
|
|
96
|
+
def active_var(self, bank: VarBank):
|
|
97
|
+
if self.FixedP or self.FixedQ:
|
|
98
|
+
raise ValueError("Active or reactive power output is fixed, cannot create an active variable for it.")
|
|
99
|
+
return bank.bvar(f"{self.ID}_active", self, "active", True)
|
|
74
100
|
|
|
75
101
|
@property
|
|
76
102
|
def P(self) -> NFloatOrFunc:
|
|
@@ -84,6 +110,7 @@ class Generator:
|
|
|
84
110
|
|
|
85
111
|
def fixP(self, p: float):
|
|
86
112
|
'''Fix the active power output'''
|
|
113
|
+
self.active = True
|
|
87
114
|
self._p = p
|
|
88
115
|
self._fixed_p = True
|
|
89
116
|
|
|
@@ -104,6 +131,7 @@ class Generator:
|
|
|
104
131
|
|
|
105
132
|
def fixQ(self, q: float):
|
|
106
133
|
'''Fix the reactive power output'''
|
|
134
|
+
self.active = True
|
|
107
135
|
self._q = q
|
|
108
136
|
self._fixed_q = True
|
|
109
137
|
|
|
@@ -275,4 +303,6 @@ class GeneratorModel:
|
|
|
275
303
|
e.append(Func2Elem(self.CostA, "CostA"))
|
|
276
304
|
e.append(Func2Elem(self.CostB, "CostB"))
|
|
277
305
|
e.append(Func2Elem(self.CostC, "CostC"))
|
|
278
|
-
return e
|
|
306
|
+
return e
|
|
307
|
+
|
|
308
|
+
__all__ = ["Generator", "GeneratorModel"]
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
from collections import deque
|
|
2
|
-
from enum import IntEnum
|
|
3
1
|
import gzip
|
|
4
|
-
from xml.etree.ElementTree import ElementTree
|
|
5
2
|
import zipfile
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
import
|
|
3
|
+
from xml.etree.ElementTree import Element, ElementTree
|
|
4
|
+
from enum import IntEnum
|
|
5
|
+
from typing import Iterable, Optional
|
|
6
|
+
from feasytools import ConstFunc
|
|
7
|
+
from .utils import *
|
|
9
8
|
from .bus import *
|
|
10
9
|
from .line import *
|
|
11
10
|
from .gen import *
|
|
@@ -445,8 +444,9 @@ class Grid:
|
|
|
445
444
|
raise ValueError(f"Unknown XML node: {e.tag}")
|
|
446
445
|
return Grid(Sb, Ub, buses, lines, gens, pvws, esss, cp, dp, holdShadowPrice)
|
|
447
446
|
|
|
448
|
-
def YMat(self)
|
|
449
|
-
'''Return the admittance matrix of the grid'''
|
|
447
|
+
def YMat(self):
|
|
448
|
+
'''(NumPy required) Return the admittance matrix of the grid'''
|
|
449
|
+
import numpy as np
|
|
450
450
|
n = len(self._buses)
|
|
451
451
|
Y = np.zeros((n, n), dtype=complex)
|
|
452
452
|
for l in self.ActiveLines:
|
|
@@ -523,3 +523,5 @@ class Grid:
|
|
|
523
523
|
bn, p, q = ln.strip().split(',')
|
|
524
524
|
self.Bus(bn).Pd = ConstFunc(float(p) / self.Sb)
|
|
525
525
|
self.Bus(bn).Qd = ConstFunc(float(q) / self.Sb)
|
|
526
|
+
|
|
527
|
+
__all__ = ["Grid", "PQSaveMode", "USaveMode", "ZSaveMode", "BusID", "LineID"]
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
from collections import deque
|
|
2
|
+
from enum import IntEnum
|
|
3
|
+
from itertools import chain
|
|
4
|
+
from typing import Any, Iterable
|
|
2
5
|
from .grid import *
|
|
3
6
|
|
|
4
7
|
class IslandResult(IntEnum):
|
|
@@ -74,9 +77,10 @@ class Island:
|
|
|
74
77
|
def ESSItems(self):
|
|
75
78
|
for e in self.ESSs:
|
|
76
79
|
yield e, self.grid.ESS(e)
|
|
77
|
-
|
|
78
|
-
def YMat(self) -> 'tuple[dict[str,int],
|
|
79
|
-
'''Return the admittance matrix of the grid'''
|
|
80
|
+
|
|
81
|
+
def YMat(self) -> 'tuple[dict[str,int], Any]':
|
|
82
|
+
'''(NumPy required) Return the admittance matrix of the grid'''
|
|
83
|
+
import numpy as np
|
|
80
84
|
n = len(self.Buses)
|
|
81
85
|
bus_dict = {b: i for i, b in enumerate(self.Buses)}
|
|
82
86
|
Y = np.zeros((n, n), dtype=complex)
|
|
@@ -88,4 +92,11 @@ class Island:
|
|
|
88
92
|
Y[j, i] -= y
|
|
89
93
|
Y[i, i] += y
|
|
90
94
|
Y[j, j] += y
|
|
91
|
-
return bus_dict, Y
|
|
95
|
+
return bus_dict, Y
|
|
96
|
+
|
|
97
|
+
def hasName(self, name: str) -> bool:
|
|
98
|
+
"""Check if the island has a bus, generator, line, PVW or ESS with the given name."""
|
|
99
|
+
for s in chain(self.Buses, self.Gens, self.Lines, self.PVWs, self.ESSs):
|
|
100
|
+
if s in name:
|
|
101
|
+
return True
|
|
102
|
+
return False
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import math
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from xml.etree.ElementTree import Element
|
|
2
4
|
from .utils import *
|
|
3
5
|
|
|
4
6
|
|
|
@@ -31,6 +33,28 @@ class Line:
|
|
|
31
33
|
self.L = length_km
|
|
32
34
|
self.active = active
|
|
33
35
|
|
|
36
|
+
def active_var(self, bank: VarBank):
|
|
37
|
+
'''Return a variable indicating whether the line is active'''
|
|
38
|
+
return bank.bvar(f"{self.ID}_active", self, "active", value=self.active)
|
|
39
|
+
|
|
40
|
+
def I_var(self, bank: VarBank):
|
|
41
|
+
'''Return a variable for the current of the line'''
|
|
42
|
+
return bank.fvar(f"{self.ID}_I", self, "I", value=self.I, nonneg=True, lb=0.0, ub=self.max_I)
|
|
43
|
+
|
|
44
|
+
def I2_var(self, bank: VarBank):
|
|
45
|
+
'''Return a variable for the square of the current of the line'''
|
|
46
|
+
i = self.I if self.I is not None else 0.0
|
|
47
|
+
return bank.fvar(f"{self.ID}_I2", self, "I", value=i**2, nonneg=True,
|
|
48
|
+
lb=0.0, ub=self.max_I**2, reflect=lambda x: math.sqrt(x))
|
|
49
|
+
|
|
50
|
+
def P_var(self, bank: VarBank):
|
|
51
|
+
'''Return a variable for the real power flow of the line'''
|
|
52
|
+
return bank.fvar(f"{self.ID}_P", self, "P", value=self.P)
|
|
53
|
+
|
|
54
|
+
def Q_var(self, bank: VarBank):
|
|
55
|
+
'''Return a variable for the reactive power flow of the line'''
|
|
56
|
+
return bank.fvar(f"{self.ID}_Q", self, "Q", value=self.Q)
|
|
57
|
+
|
|
34
58
|
@property
|
|
35
59
|
def ID(self) -> str:
|
|
36
60
|
'''Name of the line'''
|
|
@@ -100,5 +124,7 @@ class Line:
|
|
|
100
124
|
"R": f"{self.R*Zb_Ohm:.6f}ohm" if Zb_Ohm is not None else f"{self.R:.8f}pu",
|
|
101
125
|
"X": f"{self.X*Zb_Ohm:.6f}ohm" if Zb_Ohm is not None else f"{self.X:.8f}pu",
|
|
102
126
|
"MaxIkA": str(self.max_I),
|
|
103
|
-
"Length_km": str(self.L)
|
|
104
|
-
})
|
|
127
|
+
"Length_km": str(self.L) if self.L is not None else "-1"
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
__all__ = ['Line']
|