Skip to content

Commit 00a64c6

Browse files
committed
BusBatch: Add missing Name function.
1 parent fb8f418 commit 00a64c6

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

altdss/Bus.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) 2023-2024 Paulo Meira
22
# Copyright (c) 2023-2024 DSS-Extensions contributors
3-
from typing import Union, Iterator
3+
from typing import Union, Iterator, List
44
from dss.enums import DSSJSONFlags
55
from .types import Float64Array, Int32Array, ComplexArray
66
from .common import Base, InvalidatedBus
@@ -417,17 +417,29 @@ def to_json(self, options: Union[int, DSSJSONFlags] = 0):
417417

418418

419419
class BusBatch(Base):
420+
def _unpack(self):
421+
ptr, cnt = self._get_ptr_cnt()
422+
if cnt == 0:
423+
return []
424+
425+
return self._api_util.ffi.unpack(ptr, cnt)
426+
420427
def ZSCRefresh(self) -> bool:
421428
'''
422429
Refreshes the Zsc matrix for all buses in the batch
423430
'''
424-
ptrList, cnt = self._get_ptr_cnt()
425431
res = True
426-
for n in range(cnt):
427-
res = res and (self._lib.Alt_Bus_ZscRefresh(ptrList[n]) != 0)
432+
for ptr in self._unpack():
433+
res = res and (self._lib.Alt_Bus_ZscRefresh(ptr) != 0)
428434

429435
return res
430436

437+
def Name(self) -> List[str]:
438+
'''
439+
Array of strings containing names of all buses in circuit.
440+
'''
441+
return [self._get_string(self._lib.Alt_Bus_Get_Name(ptr)) for ptr in self._unpack()]
442+
431443
def _busbatch_float64(self, fname: str):
432444
return self._get_float64_array(
433445
self._lib.Alt_BusBatch_GetFloat64FromFunc,
@@ -515,9 +527,8 @@ def __len__(self) -> int:
515527
return self._cnt
516528

517529
def __iter__(self) -> Iterator[Bus]:
518-
ptrList, cnt = self._get_ptr_cnt()
519-
for n in range(cnt):
520-
yield Bus(self._api_util, ptrList[n])
530+
for ptr in self._unpack():
531+
yield Bus(self._api_util, ptr)
521532

522533
def to_json(self, options: Union[int, DSSJSONFlags] = 0):
523534
'''
@@ -560,3 +571,8 @@ def find(self, index_or_name: Union[int, str]) -> Bus:
560571
'''
561572
return self[index_or_name]
562573

574+
def Name(self) -> List[str]:
575+
'''
576+
Array of strings containing names of all buses in circuit.
577+
'''
578+
return self._check_for_error(self._get_string_array(self._lib.Circuit_Get_AllBusNames))

altdss/PDElement.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ def TotalMiles(self) -> Float64Array:
240240
'''
241241
return self._get_batch_float64_func("Alt_PDE_Get_TotalMiles")
242242

243+
def TotalKilometers(self) -> Float64Array:
244+
'''
245+
Total kilometers of line from this element to the end of the zone. For recloser siting algorithm.
246+
247+
*Requires a previous call to `RelCalc` command*
248+
249+
Original COM help: https://opendss.epri.com/TotalMiles1.html
250+
'''
251+
return self._get_batch_float64_func("Alt_PDE_Get_TotalMiles") * 1.609344
252+
243253
def SectionID(self) -> Int32Array:
244254
'''
245255
Integer ID of the feeder section that each PDElement branch in this batch is part of.

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ relevant. See [DSS C-API's repository](https://github.com/dss-extensions/dss_cap
66
## 0.2.2
77

88
- SystemY: in `AltDSS.SystemY`, return the matrix as a SciPy sparse matrix directly.
9+
- BusBatch: Add missing `Name` function (the bus names were already exposed in the individual objects and at circuit level in `AltDSS.BusNames`).
910
- CircuitElement/CircuitElementBatch: Complement doc strings; fix some type hints.
1011
- CircuitElementBatch:
1112
- Fix `MaxCurrent`. This will require the backend to be updated to v0.14.3.
1213
- Implement `OCPDevice`
13-
1414
- NonUniformBatch: allow `batch[idx]` to get a single element by index.
1515
- Setters:
1616
- Allow using `None` to clear object references (e.g. `altdss.Load[0].Daily = None`)

0 commit comments

Comments
 (0)