1
1
# Copyright (c) 2023-2024 Paulo Meira
2
2
# Copyright (c) 2023-2024 DSS-Extensions contributors
3
- from typing import Union , Iterator
3
+ from typing import Union , Iterator , List
4
4
from dss .enums import DSSJSONFlags
5
5
from .types import Float64Array , Int32Array , ComplexArray
6
6
from .common import Base , InvalidatedBus
@@ -417,17 +417,29 @@ def to_json(self, options: Union[int, DSSJSONFlags] = 0):
417
417
418
418
419
419
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
+
420
427
def ZSCRefresh (self ) -> bool :
421
428
'''
422
429
Refreshes the Zsc matrix for all buses in the batch
423
430
'''
424
- ptrList , cnt = self ._get_ptr_cnt ()
425
431
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 )
428
434
429
435
return res
430
436
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
+
431
443
def _busbatch_float64 (self , fname : str ):
432
444
return self ._get_float64_array (
433
445
self ._lib .Alt_BusBatch_GetFloat64FromFunc ,
@@ -515,9 +527,8 @@ def __len__(self) -> int:
515
527
return self ._cnt
516
528
517
529
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 )
521
532
522
533
def to_json (self , options : Union [int , DSSJSONFlags ] = 0 ):
523
534
'''
@@ -560,3 +571,8 @@ def find(self, index_or_name: Union[int, str]) -> Bus:
560
571
'''
561
572
return self [index_or_name ]
562
573
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 ))
0 commit comments