fpowerkit 0.3.7__tar.gz → 0.4.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.
Files changed (29) hide show
  1. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/PKG-INFO +3 -3
  2. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/bus.py +13 -28
  3. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/cases.py +42 -12
  4. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/ess.py +15 -24
  5. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/gen.py +17 -29
  6. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/grid.py +89 -53
  7. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/island.py +1 -2
  8. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/pvwind.py +12 -21
  9. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solbase.py +51 -2
  10. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solcmb.py +3 -3
  11. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/soldist.py +9 -46
  12. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solldf.py +21 -7
  13. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solldf2.py +21 -6
  14. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solnt.py +3 -0
  15. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/utils.py +66 -2
  16. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/pyproject.toml +3 -3
  17. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/.gitignore +0 -0
  18. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/LICENSE +0 -0
  19. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/README.md +0 -0
  20. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/desc.md +0 -0
  21. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/__init__.py +0 -0
  22. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/line.py +0 -0
  23. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/lpwrapper.py +0 -0
  24. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/solcvx.py +0 -0
  25. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/fpowerkit/soldss.py +0 -0
  26. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/main.py +0 -0
  27. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/test.py +0 -0
  28. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/test314t.py +0 -0
  29. {fpowerkit-0.3.7 → fpowerkit-0.4.1}/test_cmb.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fpowerkit
3
- Version: 0.3.7
3
+ Version: 0.4.1
4
4
  Summary: A PDN solver with multiple solutions.
5
5
  Author: fmy-xfk
6
6
  License-Expression: MIT
@@ -12,13 +12,13 @@ Requires-Python: >=3.8
12
12
  Requires-Dist: feasytools>=0.0.21
13
13
  Requires-Dist: numpy>=1.19.0
14
14
  Provides-Extra: distflow
15
+ Requires-Dist: cbc; extra == 'distflow'
15
16
  Requires-Dist: cvxpy; extra == 'distflow'
16
- Requires-Dist: ecos; extra == 'distflow'
17
17
  Provides-Extra: dss
18
18
  Requires-Dist: py-dss-interface; extra == 'dss'
19
19
  Provides-Extra: full
20
+ Requires-Dist: cbc; extra == 'full'
20
21
  Requires-Dist: cvxpy; extra == 'full'
21
- Requires-Dist: ecos; extra == 'full'
22
22
  Requires-Dist: py-dss-interface; extra == 'full'
23
23
  Provides-Extra: ldf
24
24
  Requires-Dist: scipy; extra == 'ldf'
@@ -1,30 +1,29 @@
1
1
  import math
2
- from typing import Optional
2
+ from typing import Optional, Any, Tuple
3
3
  from xml.etree.ElementTree import Element
4
4
  from feasytools import TimeFunc
5
5
  from .utils import *
6
6
 
7
7
 
8
- class Bus:
8
+ class Bus(PositionBase):
9
9
  Pd: TimeFunc # pu
10
10
  Qd: TimeFunc # pu
11
11
  ShadowPrice: FloatVar # Shadow price of generators on this bus,$/pu power
12
- Lat: NFloat
13
- Lon: NFloat
14
12
 
15
- def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, lat: NFloat = None, lon: NFloat = None,
13
+ def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, x: float, y: float, proj:Optional[Any] = None,
16
14
  v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
17
15
  '''
18
16
  Initialize
19
17
  id: Bus ID
20
18
  pd_pu: Active power demand, pu
21
19
  qd_pu: Reactive power demand, pu
22
- lat: Latitude of the bus
23
- lon: Longitude of the bus
20
+ x: X coordinate (for plotting)
21
+ y: Y coordinate (for plotting)
24
22
  v_pu: Voltage, pu. None for unfixed voltage
25
23
  min_v_pu: Minimal voltage, pu
26
24
  max_v_pu: Maximal voltage, pu
27
25
  '''
26
+ super().__init__(x, y, proj)
28
27
  self._id = id
29
28
  self._v = v_pu
30
29
  self._fixed_v = v_pu is not None
@@ -33,8 +32,6 @@ class Bus:
33
32
  self.Pd = Float2Func(pd_pu)
34
33
  self.Qd = Float2Func(qd_pu)
35
34
  self.ShadowPrice = None
36
- self.Lat = lat
37
- self.Lon = lon
38
35
  self._t = theta
39
36
  self._fixed_t = self._t is not None
40
37
 
@@ -135,33 +132,21 @@ class Bus:
135
132
 
136
133
  def __repr__(self):
137
134
  return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
138
- f"lat={self.Lat}, lon={self.Lon}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
135
+ f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
139
136
 
140
137
  def __str__(self):
141
138
  return repr(self)
142
139
 
143
140
  def str_t(self, _t: int, /):
144
141
  return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
145
- f"lat={self.Lat}, lon={self.Lon}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
146
-
147
- @property
148
- def position(self) -> 'tuple[NFloat, NFloat]':
149
- '''Return the position of the bus, (lat, lon)'''
150
- return self.Lat, self.Lon
151
-
152
- @property
153
- def LonLat(self) -> 'tuple[NFloat, NFloat]':
154
- return self.Lon, self.Lat
142
+ f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
155
143
 
156
144
  @staticmethod
157
- def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
145
+ def fromXML(node: Element, Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Bus':
158
146
  id = node.attrib["ID"]
159
147
  p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
160
148
  q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
161
- lat = node.attrib.get("Lat", None)
162
- if lat is not None: lat = float(lat)
163
- lon = node.attrib.get("Lon", None)
164
- if lon is not None: lon = float(lon)
149
+ x, y = PositionBase.load_pos_from_xml(node, proj)
165
150
  if "V" in node.attrib:
166
151
  v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
167
152
  minv = maxv = v
@@ -169,13 +154,13 @@ class Bus:
169
154
  minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
170
155
  maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
171
156
  v = None
172
- return Bus(id, p, q, lat, lon, v, minv, maxv)
157
+ return Bus(id, p, q, x, y, proj, v, minv, maxv)
173
158
 
174
159
  def toXMLNode(self, Ub_kV:Optional[float] = None,
175
160
  Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
176
161
  e = Element("bus", {"ID": self.ID})
177
- if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
178
- if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
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}"
179
164
  if self.V is not None and self.FixedV:
180
165
  e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
181
166
  else:
@@ -1,3 +1,4 @@
1
+ from typing import List, Tuple
1
2
  from feasytools import SegFunc, ConstFunc
2
3
  from .grid import GeneratorModel, Grid, Bus, Line
3
4
 
@@ -274,22 +275,44 @@ def _get_buses(
274
275
  for j in range(24):
275
276
  load_fluc.append((ls[j][0], ls[j][1]))
276
277
  if grid_repeat == 1:
277
- B = [Bus("b"+str(p[0]), _create_load(p[1]/Sb_KVA,load_fluc).repeat(load_repeat, load_period),
278
- _create_load(p[2]/Sb_KVA,load_fluc).repeat(load_repeat,load_period),
279
- min_v_pu=0.9,max_v_pu=1.1) for p in LOAD]
278
+ B = [Bus(
279
+ "b" + str(p[0]),
280
+ _create_load(p[1] / Sb_KVA, load_fluc).repeat(load_repeat, load_period),
281
+ _create_load(p[2] / Sb_KVA, load_fluc).repeat(load_repeat, load_period),
282
+ (i % 10) * 50, (i // 10) * 50,
283
+ min_v_pu=0.9, max_v_pu=1.1
284
+ ) for i, p in enumerate(LOAD)]
280
285
  else:
281
286
  B = []
282
287
  for i in range(grid_repeat):
283
- B.extend([Bus(f"b{i}_{p[0]}", _create_load(p[1]/Sb_KVA,load_fluc).repeat(load_repeat, load_period),
284
- _create_load(p[2]/Sb_KVA,load_fluc).repeat(load_repeat, load_period),
285
- min_v_pu=0.9,max_v_pu=1.1) for p in LOAD])
288
+ pre = len(LOAD) * i
289
+ B.extend([Bus(
290
+ f"b{i}_{p[0]}",
291
+ _create_load(p[1] / Sb_KVA, load_fluc).repeat(load_repeat, load_period),
292
+ _create_load(p[2] / Sb_KVA, load_fluc).repeat(load_repeat, load_period),
293
+ ((pre + j) % 10) * 50, ((pre + j) // 10) * 50,
294
+ min_v_pu=0.9, max_v_pu=1.1
295
+ ) for j, p in enumerate(LOAD)])
286
296
  else:
287
297
  if grid_repeat == 1:
288
- B = [Bus("b"+str(p[0]), p[1]/Sb_KVA, p[2]/Sb_KVA,min_v_pu=0.9,max_v_pu=1.1) for p in LOAD]
298
+ B = [Bus(
299
+ f"b{p[0]}",
300
+ p[1] / Sb_KVA,
301
+ p[2] / Sb_KVA,
302
+ (i % 10) * 50, (i // 10) * 50,
303
+ min_v_pu=0.9, max_v_pu=1.1
304
+ ) for i, p in enumerate(LOAD)]
289
305
  else:
290
306
  B = []
291
307
  for i in range(grid_repeat):
292
- B.extend([Bus(f"b{i}_{p[0]}", p[1]/Sb_KVA, p[2]/Sb_KVA, min_v_pu=0.9,max_v_pu=1.1) for p in LOAD])
308
+ pre = len(LOAD) * i
309
+ B.extend([Bus(
310
+ f"b{i}_{p[0]}",
311
+ p[1] / Sb_KVA,
312
+ p[2] / Sb_KVA,
313
+ ((pre + j) % 10) * 50, ((pre + j) // 10) * 50,
314
+ min_v_pu=0.9, max_v_pu=1.1
315
+ ) for j, p in enumerate(LOAD)])
293
316
  B[0].fixV(1.0)
294
317
  B[0].Pd = ConstFunc(0)
295
318
  B[0].Qd = ConstFunc(0)
@@ -297,7 +320,7 @@ def _get_buses(
297
320
  B[0].MinV = 0
298
321
  return B
299
322
 
300
- def _get_lines(Zb:float, LINE:'list[tuple[int,int,int,float,float]]', grid_repeat:int):
323
+ def _get_lines(Zb:float, LINE:List[Tuple[int, int, int, float, float]], grid_repeat:int):
301
324
  if grid_repeat == 1:
302
325
  L = [Line("l"+str(p[0]), "b"+str(p[1]), "b"+str(p[2]), p[3]/Zb, p[4]/Zb) for p in LINE]
303
326
  else:
@@ -308,11 +331,18 @@ def _get_lines(Zb:float, LINE:'list[tuple[int,int,int,float,float]]', grid_repea
308
331
 
309
332
  def _get_gens(default_gen:GeneratorModel, gen_pos:'list[int]', grid_repeat:int):
310
333
  if grid_repeat == 1:
311
- G = [default_gen.toGenerator("g"+p, "b"+p) for p in map(str,gen_pos)]
334
+ G = [default_gen.toGenerator(
335
+ "g" + p, "b" + p, (i % 10) * 50, (i // 10) * 50
336
+ ) for i, p in enumerate(map(str, gen_pos))]
312
337
  else:
313
338
  G = []
314
339
  for i in range(grid_repeat):
315
- G.extend([default_gen.toGenerator(f"g{i}_{p}", f"b{i}_{p}") for p in gen_pos])
340
+ pre = len(gen_pos) * i
341
+ G.extend([
342
+ default_gen.toGenerator(
343
+ f"g{i}_{p}", f"b{i}_{p}", ((pre + j) % 10) * 50, ((pre + j) // 10) * 50
344
+ ) for j, p in enumerate(gen_pos)
345
+ ])
316
346
  return G
317
347
 
318
348
  class PDNCases:
@@ -353,7 +383,7 @@ class PDNCases:
353
383
  _get_buses(Sb_MVA*1000, grid_repeat, _IEEE69_LOAD, changeable_load, load_fluc, load_repeat, load_period),
354
384
  _get_lines(Ub_kV**2/Sb_MVA, _IEEE69_LINE, grid_repeat),
355
385
  _get_gens(default_gen, gen_pos, grid_repeat),
356
- [],[]
386
+ [], []
357
387
  )
358
388
 
359
389
  __all__ = ["PDNCases"]
@@ -1,26 +1,29 @@
1
1
  import math
2
- from typing import Optional
2
+ from typing import Any, Optional
3
3
  from enum import IntEnum, Enum
4
4
  from xml.etree.ElementTree import Element
5
5
  from feasytools import RangeList
6
6
  from .utils import *
7
7
 
8
+
8
9
  class ESSPolicy(Enum):
9
10
  Manual = "Manual" # Charging/discharging manually
10
11
  Time = "Time" # Charging/discharging at given period
11
12
  Price = "Price" # Charging at low price, discharging at high price
12
13
  ByOptim = "Optim" # Charging according to solver optimization
13
14
 
15
+
14
16
  class ESSManualState(IntEnum):
15
17
  Idle = 0
16
18
  Charge = 1
17
19
  Discharge = 2
18
20
 
19
- class ESS:
21
+
22
+ class ESS(PositionBase):
20
23
  '''Model of an Energy Storage System'''
21
24
  def __init__(self, id: str, busid: str, cap_puh: float, ec:float, ed:float, pc_max:float, pd_max:float,
22
- pf:float, policy:ESSPolicy, ctime:Optional[RangeList]=None, dtime:Optional[RangeList]=None,
23
- cprice:NFloat=None, dprice:NFloat=None, Lat: NFloat=None, Lon: NFloat=None, init_elec_puh: float=0.0):
25
+ pf:float, policy:ESSPolicy, x:float, y:float, proj:Optional[Any] = None,ctime:Optional[RangeList]=None,
26
+ dtime:Optional[RangeList]=None, cprice:NFloat=None, dprice:NFloat=None, init_elec_puh: float=0.0):
24
27
  '''
25
28
  Initialize
26
29
  id: ESS ID
@@ -34,9 +37,8 @@ class ESS:
34
37
  policy: ESSPolicy
35
38
  c_cond: Charging condition
36
39
  d_cond: Discharging condition
37
- Lat: Latitude of the ESS
38
- Lon: Longitude of the ESS
39
40
  '''
41
+ super().__init__(x, y, proj)
40
42
  self._id = id
41
43
  self._bus = busid
42
44
  self._cap = cap_puh
@@ -45,8 +47,6 @@ class ESS:
45
47
  self._pc_max = pc_max
46
48
  self._pd_max = pd_max
47
49
  self._pf = pf
48
- self.Lat = Lat
49
- self.Lon = Lon
50
50
  self._elec = init_elec_puh
51
51
  self._policy = policy
52
52
  self._ctime = ctime
@@ -223,19 +223,11 @@ class ESS:
223
223
  def PF(self, pf: float):
224
224
  assert -1 <= pf <= 1, "Power factor must be in [-1, 1]"
225
225
  self._pf = pf
226
-
227
- def position(self):
228
- '''Return the position of the ESS'''
229
- return (self.Lat, self.Lon)
230
-
231
- def LonLat(self):
232
- '''Return the position of the ESS'''
233
- return (self.Lon, self.Lat)
234
226
 
235
227
  def __repr__(self) -> str:
236
228
  return (f"ESS(id='{self.ID}', busid='{self.BusID}', "+
237
229
  f"pc_max={self.MaxPc:.6f}, pd_max={self.MaxPd:.6f}, pf={self.PF:.6f}, "+
238
- f"ec={self.EC:.6f}, ed={self.ED:.6f}, Lat={self.Lat:.6f}, Lon={self.Lon:.6f})")
230
+ f"ec={self.EC:.6f}, ed={self.ED:.6f}, x={self.x:.6f}, y={self.y:.6f})")
239
231
 
240
232
  def __str__(self) -> str:
241
233
  return repr(self)
@@ -244,7 +236,7 @@ class ESS:
244
236
  return repr(self)
245
237
 
246
238
  @staticmethod
247
- def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float) -> 'ESS':
239
+ def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'ESS':
248
240
  '''
249
241
  Load ESS from XML node
250
242
  node: XML node
@@ -270,11 +262,10 @@ class ESS:
270
262
  dtime = None
271
263
  cprice = ReadConst(node.attrib["cprice"], Sb_MVA, Ub_kV) if "cprice" in node.attrib else None
272
264
  dprice = ReadConst(node.attrib["dprice"], Sb_MVA, Ub_kV) if "dprice" in node.attrib else None
273
- lat = float(node.attrib["Lat"]) if "Lat" in node.attrib else None
274
- lon = float(node.attrib["Lon"]) if "Lon" in node.attrib else None
265
+ x, y = PositionBase.load_pos_from_xml(node, proj)
275
266
  init = ReadConst(node.attrib["init_elec"], Sb_MVA, Ub_kV) if "init_elec" in node.attrib else 0.0
276
267
  return ESS(id, busid, cap, ec, ed, pc_max, pd_max, pf, policy,
277
- ctime, dtime, cprice, dprice, lat, lon, init)
268
+ x, y, proj, ctime, dtime, cprice, dprice, init)
278
269
 
279
270
  def toXMLNode(self, Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
280
271
  '''Convert to XML node'''
@@ -284,10 +275,10 @@ class ESS:
284
275
  "ec": str(self.EC),
285
276
  "ed": str(self.ED),
286
277
  "pf": str(self.PF),
287
- "policy": self._policy.value
278
+ "policy": self._policy.value,
279
+ "x": f"{self.x:.6f}",
280
+ "y": f"{self.y:.6f}",
288
281
  })
289
- if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
290
- if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
291
282
  if self._ctime is not None:
292
283
  e.append(self._ctime.toXMLNode("ctime"))
293
284
  if self._dtime is not None:
@@ -1,12 +1,12 @@
1
1
  from copy import deepcopy
2
- from typing import Optional, Union
2
+ from typing import Any, Optional, Union
3
3
  from xml.etree.ElementTree import Element
4
4
  from feasytools import TimeFunc
5
5
  from .utils import *
6
6
 
7
7
  NFloatOrFunc = Union[None, float, TimeFunc]
8
8
 
9
- class Generator:
9
+ class Generator(PositionBase):
10
10
  Pmin: Optional[TimeFunc] #pu
11
11
  Pmax: Optional[TimeFunc] #pu
12
12
  Qmin: Optional[TimeFunc] #pu
@@ -17,9 +17,9 @@ class Generator:
17
17
 
18
18
  def __init__(self, id: str, busid: str,
19
19
  costA: FloatLike, costB: FloatLike, costC: FloatLike,
20
+ x: float, y: float, proj:Optional[Any] = None,
20
21
  pmin_pu: NFloatLike = None, pmax_pu: NFloatLike = None,
21
22
  qmin_pu: NFloatLike = None, qmax_pu: NFloatLike = None,
22
- Lat: NFloat = None, Lon: NFloat = None,
23
23
  P: NFloatLike = None, Q: NFloatLike = None, active: bool = True
24
24
  ):
25
25
  '''
@@ -42,10 +42,9 @@ class Generator:
42
42
  Or:
43
43
  Q: Reactive power output, pu. None for unfixed power
44
44
  '''
45
+ super().__init__(x, y, proj)
45
46
  self._id = id
46
47
  self._bus = busid
47
- self.Lat = Lat
48
- self.Lon = Lon
49
48
  if P is not None:
50
49
  self._p = Float2Func(P)
51
50
  self._fixed_p = True
@@ -57,7 +56,7 @@ class Generator:
57
56
  self.Pmin = Float2Func(pmin_pu)
58
57
  self.Pmax = Float2Func(pmax_pu)
59
58
  else:
60
- raise ValueError("Either P or (pmin, pmax) should be provided.")
59
+ raise ValueError(f"Either P or (pmin, pmax) should be provided for {id}.")
61
60
  if Q is not None:
62
61
  self._q = Float2Func(Q)
63
62
  self._fixed_q = True
@@ -69,7 +68,7 @@ class Generator:
69
68
  self.Qmin = Float2Func(qmin_pu)
70
69
  self.Qmax = Float2Func(qmax_pu)
71
70
  else:
72
- raise ValueError("Either Q or (qmin, qmax) should be provided.")
71
+ raise ValueError(f"Either Q or (qmin, qmax) should be provided for {id}.")
73
72
  self.CostA = Float2Func(costA)
74
73
  self.CostB = Float2Func(costB)
75
74
  self.CostC = Float2Func(costC)
@@ -140,15 +139,6 @@ class Generator:
140
139
  self._q = None
141
140
  self._fixed_q = False
142
141
 
143
- @property
144
- def position(self) -> 'tuple[NFloat, NFloat]':
145
- '''Position of the generator, (Lat, Lon)'''
146
- return (self.Lat, self.Lon)
147
-
148
- @property
149
- def LonLat(self) -> 'tuple[NFloat, NFloat]':
150
- return self.Lon, self.Lat
151
-
152
142
  @property
153
143
  def ID(self) -> str:
154
144
  '''Name of the generator'''
@@ -162,7 +152,7 @@ class Generator:
162
152
  def __repr__(self) -> str:
163
153
  return (f"Generator(id='{self.ID}', busid='{self.BusID}', P={self.P}, Q={self.Q}, " +
164
154
  f"pmin_pu={self.Pmin}, pmax_pu={self.Pmax}, qmin_pu={self.Qmin}, qmax_pu={self.Qmax}, " +
165
- f"costA={self.CostA}, costB={self.CostB}, costC={self.CostC}, Lat={self.Lat}, Lon={self.Lon})")
155
+ f"costA={self.CostA}, costB={self.CostB}, costC={self.CostC}, x={self.x}, y={self.y})")
166
156
 
167
157
  def __str__(self) -> str:
168
158
  return repr(self)
@@ -176,7 +166,8 @@ class Generator:
176
166
  qmax = self.Qmax(_t) if isinstance(self.Qmax, TimeFunc) else None
177
167
  return (f"Generator(id='{self.ID}', busid='{self.BusID}', P={p}, Q={q}, " +
178
168
  f"pmin_pu={pmin}, pmax_pu={pmax}, qmin_pu={qmin}, qmax_pu={qmax}, " +
179
- f"costA={self.CostA(_t)}, costB={self.CostB(_t)}, costC={self.CostC(_t)}, Lat={self.Lat}, Lon={self.Lon})")
169
+ f"costA={self.CostA(_t)}, costB={self.CostB(_t)}, costC={self.CostC(_t)}, " +
170
+ f"x={self.x}, y={self.y})")
180
171
 
181
172
  def Cost(self, _t: int, /, secondary: bool = True) -> FloatVar:
182
173
  '''
@@ -204,7 +195,7 @@ class Generator:
204
195
  return ret / p
205
196
 
206
197
  @staticmethod
207
- def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
198
+ def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Generator':
208
199
  id = node.attrib["ID"]
209
200
  busid = node.attrib["Bus"]
210
201
  pmin = ReadNFloatLike(node.find("Pmin"), Sb_MVA, Ub_kV)
@@ -216,19 +207,16 @@ class Generator:
216
207
  cc = ReadFloatLike(node.find("CostC"), Sb_MVA, Ub_kV)
217
208
  p = ReadNFloatLike(node.find("P"), Sb_MVA, Ub_kV)
218
209
  q = ReadNFloatLike(node.find("Q"), Sb_MVA, Ub_kV)
219
- lat = node.attrib.get("Lat", None)
220
- if lat is not None: lat = float(lat)
221
- lon = node.attrib.get("Lon", None)
222
- if lon is not None: lon = float(lon)
223
- return Generator(id, busid, ca, cb, cc, pmin, pmax, qmin, qmax, lat, lon, p, q)
210
+ x, y = PositionBase.load_pos_from_xml(node, proj)
211
+ return Generator(id, busid, ca, cb, cc, x, y, proj, pmin, pmax, qmin, qmax, p, q)
224
212
 
225
213
  def toXMLNode(self, Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
226
214
  e = Element("gen", {
227
215
  "ID": self.ID,
228
216
  "Bus": self.BusID,
217
+ "x": f"{self.x:.6f}",
218
+ "y": f"{self.y:.6f}",
229
219
  })
230
- if self.Lat is not None: e.attrib["Lat"] = f"{self.Lat:.6f}"
231
- if self.Lon is not None: e.attrib["Lon"] = f"{self.Lon:.6f}"
232
220
  if Sb_MVA is not None and Sb_kVA is not None:
233
221
  raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
234
222
  if Sb_MVA is not None:
@@ -278,13 +266,13 @@ class GeneratorModel:
278
266
  self.CostB = Float2Func(costB)
279
267
  self.CostC = Float2Func(costC)
280
268
 
281
- def toGenerator(self, id:str, busid:str):
269
+ def toGenerator(self, id:str, busid:str, x:float, y:float, proj:Optional[Any] = None) -> Generator:
282
270
  return Generator(id, busid, deepcopy(self.CostA), deepcopy(self.CostB),
283
- deepcopy(self.CostC), deepcopy(self.Pmin), deepcopy(self.Pmax),
271
+ deepcopy(self.CostC), x, y, proj, deepcopy(self.Pmin), deepcopy(self.Pmax),
284
272
  deepcopy(self.Qmin), deepcopy(self.Qmax))
285
273
 
286
274
  @staticmethod
287
- def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
275
+ def fromXML(node: Element, Sb_MVA: float, Ub_kV: float):
288
276
  pmin = ReadFloatLike(node.find("Pmin"), Sb_MVA, Ub_kV)
289
277
  pmax = ReadFloatLike(node.find("Pmax"), Sb_MVA, Ub_kV)
290
278
  qmin = ReadFloatLike(node.find("Qmin"), Sb_MVA, Ub_kV)