fpowerkit 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -16,15 +16,15 @@ grid_obj69 = PDNCases.IEEE69()
16
16
 
17
17
  ## 使用
18
18
 
19
- 克隆本仓库,并输入以下命令开始仿真:
19
+ 克隆本仓库,并输入以下命令开始求解:
20
20
 
21
21
  ```bash
22
- python main.py -g cases/ieee33.grid.zip
22
+ python main.py -g cases/33base.xml
23
23
  ```
24
24
 
25
25
  请注意上述命令不适用于pip安装的版本。
26
26
 
27
- `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
27
+ `33base`描述了IEEE 33节点配电网模型。换成`3nodes`则是一个极简版3节点辐射形配电网模型,结构如下:
28
28
 
29
29
  ```
30
30
  G0 G1
@@ -2,4 +2,5 @@ from .grid import *
2
2
  from .solbase import *
3
3
  from .solnt import *
4
4
  from .soldist import *
5
+ from .soldss import *
5
6
  from .cases import PDNCases
@@ -1,12 +1,12 @@
1
- from enum import IntEnum
1
+ from enum import IntEnum, Enum
2
2
  import math
3
3
  from feasytools import RangeList
4
4
  from .utils import *
5
5
 
6
- class ESSPolicy(IntEnum):
7
- Manual = 0 # Charging/discharging manually
8
- Time = 1 # Charging/discharging at given period
9
- Price = 2 # Charging at low price, discharging at high price
6
+ class ESSPolicy(Enum):
7
+ Manual = "Manual" # Charging/discharging manually
8
+ Time = "Time" # Charging/discharging at given period
9
+ Price = "Price" # Charging at low price, discharging at high price
10
10
 
11
11
  class ESSManualState(IntEnum):
12
12
  Idle = 0
@@ -93,6 +93,8 @@ class ESS:
93
93
  return self._pc_max, self.__q(self._pc_max)
94
94
  elif self._dprice > dprice and self._elec > 0:
95
95
  return -self._pd_max, -self.__q(self._pd_max)
96
+ else:
97
+ raise ValueError("Unknown ESS policy")
96
98
  return 0, 0
97
99
 
98
100
  def Charge(self, P: float, dt: float):
@@ -201,7 +203,7 @@ class ESS:
201
203
  pc_max = ReadConst(node.attrib["pc_max"], Sb_MVA, Ub_kV)
202
204
  pd_max = ReadConst(node.attrib["pd_max"], Sb_MVA, Ub_kV)
203
205
  pf = float(node.attrib["pf"])
204
- policy = ESSPolicy(int(node.attrib["policy"])) if "policy" in node.attrib else ESSPolicy.Manual
206
+ policy = ESSPolicy(node.attrib["policy"]) if "policy" in node.attrib else ESSPolicy.Manual
205
207
  ctime_node = node.find("ctime")
206
208
  if ctime_node is not None:
207
209
  ctime = RangeList(ctime_node)
@@ -228,6 +230,7 @@ class ESS:
228
230
  "ec": str(self.EC),
229
231
  "ed": str(self.ED),
230
232
  "pf": str(self.PF),
233
+ "policy": self._policy.value
231
234
  })
232
235
  if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
233
236
  if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
@@ -474,6 +474,11 @@ class Grid:
474
474
  Sb_MVA = self.Sb_MVA if PQmode == PQSaveMode.MVA else None,
475
475
  Sb_kVA = self.Sb_kVA if PQmode == PQSaveMode.KVA else None
476
476
  ))
477
+ for es in self.ESSs:
478
+ e.append(es.toXMLNode(
479
+ Sb_MVA = self.Sb_MVA if PQmode == PQSaveMode.MVA else None,
480
+ Sb_kVA = self.Sb_kVA if PQmode == PQSaveMode.KVA else None
481
+ ))
477
482
  return e
478
483
 
479
484
  def saveFileXML(self, path:str,
@@ -0,0 +1,47 @@
1
+ from .solbase import *
2
+
3
+ class OpenDSSSolver(SolverBase):
4
+
5
+ def __init__(self, grid:Grid, eps:float = 1e-6, default_saveto:str = DEFAULT_SAVETO, max_iter:int = 100, init_t:int = 0, source_bus:str=""):
6
+ super().__init__(grid, eps, default_saveto)
7
+ from py_dss_interface import DSS
8
+ self._g = grid
9
+ t = init_t
10
+ d = DSS()
11
+ d.text("clear")
12
+ cir = f"new circuit.my_circuit basekv={grid.Ub} pu=1.0 phases=3"
13
+ if source_bus != "":
14
+ cir += f" bus1={source_bus}"
15
+ d.text(cir)
16
+ for bus in grid.Buses:
17
+ bid = bus.ID
18
+ p = bus.Pd(t) * grid.Sb_kVA
19
+ q = bus.Qd(t) * grid.Sb_kVA
20
+ print(f"bus {bid} Pd={p} Qd={q}")
21
+ d.text(f"New Load.{bid} bus1={bid}.1.2.3 phases=3 kW={p} kvar={q} vmin={bus.MinV} vmax={bus.MaxV}")
22
+ for line in self.grid.Lines:
23
+ fid = line.fBus
24
+ tid = line.tBus
25
+ d.text(f"New Line.{line.ID} bus1={fid}.1.2.3 bus2={tid}.1.2.3 length={line.L} units=km R1={line.R*grid.Zb} units=ohm X1={line.X*grid.Zb} units=ohm")
26
+ for gen in self.grid.Gens:
27
+ if gen.P is None:
28
+ p = None
29
+ else:
30
+ p = gen.P(t) if isinstance(gen.P, TimeFunc) else gen.P
31
+ if gen.Q is None:
32
+ q = None
33
+ else:
34
+ q = gen.Q(t) if isinstance(gen.Q, TimeFunc) else gen.Q
35
+ bid = gen.BusID
36
+ s = f"New Generator.{gen.ID} bus1={bid} phases=1 kv={grid.Ub} "
37
+ if p is not None:
38
+ s += f"kw={p*grid.Sb_kVA} "
39
+ if q is not None:
40
+ s += f"kvar={q*grid.Sb_kVA} "
41
+ d.text(s)
42
+ d.text("set mode=snapshot")
43
+ self.dss = d
44
+
45
+ def solve(self, _t:int, /, *, timeout_s:float = 1) -> 'tuple[GridSolveResult, float]':
46
+ self.dss.text("solve")
47
+ return GridSolveResult.OK, 0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.1.2
3
+ Version: 0.1.3
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 @@ fpowerkit/line.py
11
11
  fpowerkit/pvwind.py
12
12
  fpowerkit/solbase.py
13
13
  fpowerkit/soldist.py
14
+ fpowerkit/soldss.py
14
15
  fpowerkit/solnt.py
15
16
  fpowerkit/utils.py
16
17
  fpowerkit.egg-info/PKG-INFO
@@ -5,7 +5,7 @@ with open("desc.md", "r", encoding="utf8") as f:
5
5
 
6
6
  setup(
7
7
  name="fpowerkit",
8
- version="0.1.2",
8
+ version="0.1.3",
9
9
  author="fmy_xfk",
10
10
  packages=find_packages(),
11
11
  description="A Distflow PDN solver based on Gurobi.",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes