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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -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[bool, float]':
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
- model.optimize()
641
- if model.Status != GRB.Status.OPTIMAL:
642
- return False, 0
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 True, model.ObjVal
682
+ return GridSolveResult.OK, model.ObjVal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf8") as f:
5
5
 
6
6
  setup(
7
7
  name="fpowerkit",
8
- version="0.0.5",
8
+ version="0.0.6",
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