Skip to content

Commit f7e9c75

Browse files
committed
YMatrix: adapt GetIPointer/GetVPointer to return the actual pointer, add getI and getV for compatibility with ODDPY
1 parent 5fb69b9 commit f7e9c75

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

dss/v7/dss_capi.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5231,7 +5231,8 @@ def YNodeVarray(self):
52315231
class IYMatrix(FrozenClass):
52325232
_isfrozen = freeze
52335233

5234-
def GetCompressedYMatrix(self, factor=False):
5234+
def GetCompressedYMatrix(self, factor=True):
5235+
'''Return as (data, indices, indptr) that can fed into scipy.sparse.csc_matrix'''
52355236
nBus = ffi.new('uint32_t*')
52365237
nBus[0] = 0
52375238
nNz = ffi.new('uint32_t*')
@@ -5275,14 +5276,16 @@ def AddInAuxCurrents(self, SType):
52755276
lib.YMatrix_AddInAuxCurrents(SType)
52765277

52775278
def GetIPointer(self):
5279+
'''Get access to the internal Current pointer'''
52785280
IvectorPtr = ffi.new('double**')
52795281
lib.YMatrix_getIpointer(IvectorPtr)
5280-
return IvectorPtr
5282+
return IvectorPtr[0]
52815283

52825284
def GetVPointer(self):
5285+
'''Get access to the internal Voltage pointer'''
52835286
VvectorPtr = ffi.new('double**')
52845287
lib.YMatrix_getVpointer(VvectorPtr)
5285-
return VvectorPtr
5288+
return VvectorPtr[0]
52865289

52875290
def SolveSystem(self, NodeV):
52885291
if type(NodeV) is not np.ndarray:
@@ -5310,7 +5313,20 @@ def UseAuxCurrents(self):
53105313
def UseAuxCurrents(self, value):
53115314
lib.YMatrix_Set_UseAuxCurrents(value)
53125315

5316+
# for better compatibility with OpenDSSDirect.py
5317+
getYSparse = GetCompressedYMatrix
5318+
5319+
def getI(self):
5320+
'''Get the data from the internal Current pointer'''
5321+
IvectorPtr = self.IVector()
5322+
return ffi.unpack(IvectorPtr, lib.Circuit_Get_NumNodes() + 1)
53135323

5324+
def getV(self):
5325+
'''Get the data from the internal Voltage pointer'''
5326+
VvectorPtr = self.VVector()
5327+
return ffi.unpack(VvectorPtr, lib.Circuit_Get_NumNodes() + 1)
5328+
5329+
53145330
class IDSS(FrozenClass):
53155331
_isfrozen = freeze
53165332
ActiveCircuit = ICircuit()

dss/v8/dss_capi.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5318,7 +5318,8 @@ def YNodeVarray(self):
53185318
class IYMatrix(FrozenClass):
53195319
_isfrozen = freeze
53205320

5321-
def GetCompressedYMatrix(self, factor=False):
5321+
def GetCompressedYMatrix(self, factor=True):
5322+
'''Return as (data, indices, indptr) that can fed into scipy.sparse.csc_matrix'''
53225323
nBus = ffi.new('uint32_t*')
53235324
nBus[0] = 0
53245325
nNz = ffi.new('uint32_t*')
@@ -5362,14 +5363,16 @@ def AddInAuxCurrents(self, SType):
53625363
lib.YMatrix_AddInAuxCurrents(SType)
53635364

53645365
def GetIPointer(self):
5366+
'''Get access to the internal Current pointer'''
53655367
IvectorPtr = ffi.new('double**')
53665368
lib.YMatrix_getIpointer(IvectorPtr)
5367-
return IvectorPtr
5369+
return IvectorPtr[0]
53685370

53695371
def GetVPointer(self):
5372+
'''Get access to the internal Voltage pointer'''
53705373
VvectorPtr = ffi.new('double**')
53715374
lib.YMatrix_getVpointer(VvectorPtr)
5372-
return VvectorPtr
5375+
return VvectorPtr[0]
53735376

53745377
def SolveSystem(self, NodeV):
53755378
if type(NodeV) is not np.ndarray:
@@ -5396,8 +5399,21 @@ def UseAuxCurrents(self):
53965399
@UseAuxCurrents.setter
53975400
def UseAuxCurrents(self, value):
53985401
lib.YMatrix_Set_UseAuxCurrents(value)
5402+
5403+
# for better compatibility with OpenDSSDirect.py
5404+
getYSparse = GetCompressedYMatrix
53995405

5406+
def getI(self):
5407+
'''Get the data from the internal Current pointer'''
5408+
IvectorPtr = self.IVector()
5409+
return ffi.unpack(IvectorPtr, lib.Circuit_Get_NumNodes() + 1)
54005410

5411+
def getV(self):
5412+
'''Get the data from the internal Voltage pointer'''
5413+
VvectorPtr = self.VVector()
5414+
return ffi.unpack(VvectorPtr, lib.Circuit_Get_NumNodes() + 1)
5415+
5416+
54015417
class IDSS(FrozenClass):
54025418
_isfrozen = freeze
54035419
ActiveCircuit = ICircuit()

0 commit comments

Comments
 (0)