fpowerkit 0.0.5__tar.gz → 0.0.6__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.5 → fpowerkit-0.0.6}/PKG-INFO +1 -1
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit/grid.py +23 -5
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit.egg-info/PKG-INFO +1 -1
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/setup.py +1 -1
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/LICENSE +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/README.md +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit/__init__.py +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit.egg-info/SOURCES.txt +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit.egg-info/dependency_links.txt +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit.egg-info/requires.txt +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/fpowerkit.egg-info/top_level.txt +0 -0
- {fpowerkit-0.0.5 → fpowerkit-0.0.6}/setup.cfg +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
1
2
|
import zipfile
|
|
2
3
|
from io import BytesIO, TextIOWrapper
|
|
3
4
|
from typing import Any, TextIO, Iterable, Optional, Union
|
|
@@ -389,6 +390,12 @@ BusID = str
|
|
|
389
390
|
LineID = str
|
|
390
391
|
|
|
391
392
|
|
|
393
|
+
class GridSolveResult(IntEnum):
|
|
394
|
+
'''Result of grid solving'''
|
|
395
|
+
Failed = 0
|
|
396
|
+
OK = 1
|
|
397
|
+
OKwithoutVICons = 2
|
|
398
|
+
|
|
392
399
|
class Grid:
|
|
393
400
|
Sb: float #MVA
|
|
394
401
|
Ub: float #kV
|
|
@@ -573,8 +580,15 @@ class Grid:
|
|
|
573
580
|
raise ValueError(f"Invalid power unit: {gens_unit}")
|
|
574
581
|
return Grid(Sb, Ub, buses, lines, gens, holdShadowPrice)
|
|
575
582
|
|
|
583
|
+
def loadPQofBus(self, file_name: str):
|
|
584
|
+
with open(file_name) as fp:
|
|
585
|
+
for ln in fp.readlines()[1:]:
|
|
586
|
+
bn, p, q = ln.strip().split(',')
|
|
587
|
+
self.Bus(bn).Pd = ConstFunc(float(p) / self.Sb)
|
|
588
|
+
self.Bus(bn).Qd = ConstFunc(float(q) / self.Sb)
|
|
589
|
+
|
|
576
590
|
def solve(self, _t: int, /, *, max_v_pu:float = 1.1, min_v_pu: float = 0.9, max_I_kA: float = 0.866,
|
|
577
|
-
source_buses:'list[BusID]' = [], source_bus_V_pu:float = 1.0) -> 'tuple[
|
|
591
|
+
source_buses:'list[BusID]' = [], source_bus_V_pu:float = 1.0) -> 'tuple[GridSolveResult, float]':
|
|
578
592
|
'''Get the best result at time _t, return a tuple: (success?, optimal objective value)'''
|
|
579
593
|
model = Model("model")
|
|
580
594
|
max_v = max_v_pu ** 2
|
|
@@ -637,9 +651,13 @@ class Grid:
|
|
|
637
651
|
model.update()
|
|
638
652
|
model.optimize()
|
|
639
653
|
if model.Status != GRB.Status.OPTIMAL:
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
654
|
+
# Remove VI constraints and try again
|
|
655
|
+
state, val = self.solve(_t, max_v_pu=float("inf"), min_v_pu=0, max_I_kA=float("inf"),
|
|
656
|
+
source_buses=source_buses,source_bus_V_pu=source_bus_V_pu)
|
|
657
|
+
if state == GridSolveResult.OK:
|
|
658
|
+
return GridSolveResult.OKwithoutVICons, val
|
|
659
|
+
else:
|
|
660
|
+
return GridSolveResult.Failed, val
|
|
643
661
|
|
|
644
662
|
for bus in self.Buses:
|
|
645
663
|
j = bus.ID
|
|
@@ -661,4 +679,4 @@ class Grid:
|
|
|
661
679
|
gen.P = pg0[j].X
|
|
662
680
|
gen.Q = qg0[j].X
|
|
663
681
|
|
|
664
|
-
return
|
|
682
|
+
return GridSolveResult.OK, model.ObjVal
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|