Skip to content

Commit c3812c3

Browse files
committed
Migrate to the Global Result API for most functions.
Exceptions are IMonitors, IYMatrix and ICircuit.SystemY, functions which can consume a high volume of memory.
1 parent 5f13eae commit c3812c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1055
-467
lines changed

+DSS_MATLAB/APIUtil.m

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
classdef APIUtil < handle
2+
properties (Access = protected)
3+
libraryWasLoaded = 0
4+
end
5+
properties
6+
%DataPtr_PDouble
7+
%DataPtr_PInteger
8+
%DataPtr_PByte
9+
CountPtr_PDouble
10+
CountPtr_PInteger
11+
CountPtr_PByte
12+
end
13+
methods
14+
function obj = APIUtil()
15+
MfilePath = fileparts(mfilename('fullpath'));
16+
DLLfilePath = fullfile(MfilePath, 'dss_capi_v7');
17+
if libisloaded('dss_capi_v7')
18+
return
19+
else
20+
orig_state = warning;
21+
warning('off','all')
22+
try
23+
% Try loading using the thunk file, if available
24+
loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_v7);
25+
catch
26+
% Try loading using the thunk file, otherwise use the dynamic version
27+
loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_v7_no_thunk);
28+
end
29+
obj.libraryWasLoaded = 1;
30+
warning(orig_state);
31+
end
32+
end
33+
34+
function delete(obj)
35+
% Don't unload the library anymore for better compatibility with
36+
% the COM behavior
37+
38+
% if (obj.libraryWasLoaded ~= 0)
39+
% unloadlibrary('dss_capi_v7');
40+
% end
41+
end
42+
43+
function obj = InitBuffers(obj)
44+
% obj.DataPtr_PDouble = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PDouble');
45+
% obj.DataPtr_PInteger = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PInteger');
46+
% obj.DataPtr_PByte = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PByte');
47+
obj.CountPtr_PDouble = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PDouble');
48+
obj.CountPtr_PInteger = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PInteger');
49+
obj.CountPtr_PByte = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PByte');
50+
51+
% if (obj.DataPtr_PDouble.isNull || obj.DataPtr_PDouble.isNull || obj.DataPtr_PByte.isNull)
52+
% disp('Null-pointer return from the API! Cannot continue!');
53+
% return
54+
% % error('Null-pointer return from the API! Cannot continue!');
55+
% end
56+
57+
% setdatatype(obj.DataPtr_PDouble, 'doublePtrPtr', 1);
58+
% setdatatype(obj.DataPtr_PInteger, 'int32PtrPtr', 1);
59+
% setdatatype(obj.DataPtr_PByte, 'int8PtrPtr', 1);
60+
61+
setdatatype(obj.CountPtr_PDouble, 'int32Ptr', 2);
62+
setdatatype(obj.CountPtr_PInteger, 'int32Ptr', 2);
63+
setdatatype(obj.CountPtr_PByte, 'int32Ptr', 2);
64+
end
65+
66+
67+
function result = get_float64_gr_array(obj)
68+
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PDouble');
69+
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
70+
result = data.Value;
71+
end
72+
73+
function result = get_int32_gr_array(obj)
74+
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PInteger');
75+
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
76+
result = data.Value;
77+
end
78+
79+
function result = get_int8_gr_array(obj)
80+
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PByte');
81+
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
82+
result = data.Value;
83+
end
84+
85+
end
86+
end

+DSS_MATLAB/Base.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
methods
2323

2424
function obj = CheckForError(obj)
25-
error = calllib('dss_capi_v7', 'Error_Get_Number');
26-
if error ~= 0
27-
ME = MException(['DSS_MATLAB:Error' int2str(error)], calllib('dss_capi_v7', 'Error_Get_Description'));
28-
throw(ME);
29-
end
25+
% error = calllib('dss_capi_v7', 'Error_Get_Number');
26+
% if error ~= 0
27+
% ME = MException(['DSS_MATLAB:Error' int2str(error)], calllib('dss_capi_v7', 'Error_Get_Description'));
28+
% throw(ME);
29+
% end
3030
end
3131
end
3232
end

+DSS_MATLAB/IActiveClass.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
% IActiveClass: DSS MATLAB interface class to DSS C-API
33
%
44
% Properties:
5-
% ActiveClassName - (read-only) Returns name of active class.
6-
% AllNames - (read-only) Array of strings consisting of all element names in the active class.
7-
% Count - (read-only) Number of elements in Active Class. Same as NumElements Property.
8-
% First - (read-only) Sets first element in the active class to be the active DSS object. If object is a CktElement, ActiveCktELment also points to this element. Returns 0 if none.
5+
% ActiveClassName - Returns name of active class.
6+
% AllNames - Array of strings consisting of all element names in the active class.
7+
% Count - Number of elements in Active Class. Same as NumElements Property.
8+
% First - Sets first element in the active class to be the active DSS object. If object is a CktElement, ActiveCktELment also points to this element. Returns 0 if none.
99
% Name - Name of the Active Element of the Active Class
10-
% Next - (read-only) Sets next element in active class to be the active DSS object. If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if no more.
11-
% NumElements - (read-only) Number of elements in this class. Same as Count property.
10+
% Next - Sets next element in active class to be the active DSS object. If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if no more.
11+
% NumElements - Number of elements in this class. Same as Count property.
12+
13+
properties (Access = protected)
14+
apiutil
15+
end
1216

1317
properties
1418
ActiveClassName
@@ -21,6 +25,9 @@
2125
end
2226

2327
methods (Access = public)
28+
function obj = IActiveClass(apiutil)
29+
obj.apiutil = apiutil;
30+
end
2431

2532
end
2633
methods

+DSS_MATLAB/IBus.m

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,45 @@
22
% IBus: DSS MATLAB interface class to DSS C-API
33
%
44
% Properties:
5-
% Coorddefined - (read-only) False=0 else True. Indicates whether a coordinate has been defined for this bus
6-
% CplxSeqVoltages - (read-only) Complex Double array of Sequence Voltages (0, 1, 2) at this Bus.
7-
% Cust_Duration - (read-only) Accumulated customer outage durations
8-
% Cust_Interrupts - (read-only) Annual number of customer-interruptions from this bus
9-
% Distance - (read-only) Distance from energymeter (if non-zero)
10-
% Int_Duration - (read-only) Average interruption duration, hr.
11-
% Isc - (read-only) Short circuit currents at bus; Complex Array.
12-
% Lambda - (read-only) Accumulated failure rate downstream from this bus; faults per year
13-
% N_Customers - (read-only) Total numbers of customers served downline from this bus
14-
% N_interrupts - (read-only) Number of interruptions this bus per year
15-
% Name - (read-only) Name of Bus
16-
% Nodes - (read-only) Integer Array of Node Numbers defined at the bus in same order as the voltages.
17-
% NumNodes - (read-only) Number of Nodes this bus.
18-
% SectionID - (read-only) Integer ID of the feeder section in which this bus is located.
19-
% SeqVoltages - (read-only) Double Array of sequence voltages at this bus.
20-
% TotalMiles - (read-only) Total length of line downline from this bus, in miles. For recloser siting algorithm.
21-
% VLL - (read-only) For 2- and 3-phase buses, returns array of complex numbers represetin L-L voltages in volts. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only first 3.
22-
% VMagAngle - (read-only) Variant Array of doubles containing voltages in Magnitude (VLN), angle (deg)
23-
% Voc - (read-only) Open circuit voltage; Complex array.
24-
% Voltages - (read-only) Complex array of voltages at this bus.
25-
% YscMatrix - (read-only) Complex array of Ysc matrix at bus. Column by column.
26-
% Zsc0 - (read-only) Complex Zero-Sequence short circuit impedance at bus.
27-
% Zsc1 - (read-only) Complex Positive-Sequence short circuit impedance at bus..
28-
% ZscMatrix - (read-only) Complex array of Zsc matrix at bus. Column by column.
29-
% kVBase - (read-only) Base voltage at bus in kV
30-
% puVLL - (read-only) Returns Complex array of pu L-L voltages for 2- and 3-phase buses. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only 3 phases.
31-
% puVmagAngle - (read-only) Array of doubles containig voltage magnitude, angle pairs in per unit
32-
% puVoltages - (read-only) Complex Array of pu voltages at the bus.
5+
% Coorddefined - False=0 else True. Indicates whether a coordinate has been defined for this bus
6+
% CplxSeqVoltages - Complex Double array of Sequence Voltages (0, 1, 2) at this Bus.
7+
% Cust_Duration - Accumulated customer outage durations
8+
% Cust_Interrupts - Annual number of customer-interruptions from this bus
9+
% Distance - Distance from energymeter (if non-zero)
10+
% Int_Duration - Average interruption duration, hr.
11+
% Isc - Short circuit currents at bus; Complex Array.
12+
% Lambda - Accumulated failure rate downstream from this bus; faults per year
13+
% N_Customers - Total numbers of customers served downline from this bus
14+
% N_interrupts - Number of interruptions this bus per year
15+
% Name - Name of Bus
16+
% Nodes - Integer Array of Node Numbers defined at the bus in same order as the voltages.
17+
% NumNodes - Number of Nodes this bus.
18+
% SectionID - Integer ID of the feeder section in which this bus is located.
19+
% SeqVoltages - Double Array of sequence voltages at this bus.
20+
% TotalMiles - Total length of line downline from this bus, in miles. For recloser siting algorithm.
21+
% VLL - For 2- and 3-phase buses, returns array of complex numbers represetin L-L voltages in volts. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only first 3.
22+
% VMagAngle - Variant Array of doubles containing voltages in Magnitude (VLN), angle (deg)
23+
% Voc - Open circuit voltage; Complex array.
24+
% Voltages - Complex array of voltages at this bus.
25+
% YscMatrix - Complex array of Ysc matrix at bus. Column by column.
26+
% Zsc0 - Complex Zero-Sequence short circuit impedance at bus.
27+
% Zsc1 - Complex Positive-Sequence short circuit impedance at bus..
28+
% ZscMatrix - Complex array of Zsc matrix at bus. Column by column.
29+
% kVBase - Base voltage at bus in kV
30+
% puVLL - Returns Complex array of pu L-L voltages for 2- and 3-phase buses. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only 3 phases.
31+
% puVmagAngle - Array of doubles containig voltage magnitude, angle pairs in per unit
32+
% puVoltages - Complex Array of pu voltages at the bus.
3333
% x - X Coordinate for bus (double)
3434
% y - Y coordinate for bus(double)
3535
%
3636
% Methods:
3737
% GetUniqueNodeNumber -
3838
% ZscRefresh -
3939

40+
properties (Access = protected)
41+
apiutil
42+
end
43+
4044
properties
4145
Coorddefined
4246
CplxSeqVoltages
@@ -71,6 +75,9 @@
7175
end
7276

7377
methods (Access = public)
78+
function obj = IBus(apiutil)
79+
obj.apiutil = apiutil;
80+
end
7481

7582
function result = GetUniqueNodeNumber(obj, StartNumber)
7683
result = calllib('dss_capi_v7', 'Bus_GetUniqueNodeNumber', StartNumber);
@@ -90,7 +97,8 @@
9097

9198
function result = get.CplxSeqVoltages(obj)
9299
% (read-only) Complex Double array of Sequence Voltages (0, 1, 2) at this Bus.
93-
result = DSS_MATLAB.get_float64_array('Bus_Get_CplxSeqVoltages');
100+
calllib('dss_capi_v7', 'Bus_Get_CplxSeqVoltages_GR');
101+
result = obj.apiutil.get_float64_gr_array();
94102
end
95103

96104
function result = get.Cust_Duration(obj)
@@ -115,7 +123,8 @@
115123

116124
function result = get.Isc(obj)
117125
% (read-only) Short circuit currents at bus; Complex Array.
118-
result = DSS_MATLAB.get_float64_array('Bus_Get_Isc');
126+
calllib('dss_capi_v7', 'Bus_Get_Isc_GR');
127+
result = obj.apiutil.get_float64_gr_array();
119128
end
120129

121130
function result = get.Lambda(obj)
@@ -140,7 +149,8 @@
140149

141150
function result = get.Nodes(obj)
142151
% (read-only) Integer Array of Node Numbers defined at the bus in same order as the voltages.
143-
result = DSS_MATLAB.get_int32_array('Bus_Get_Nodes');
152+
calllib('dss_capi_v7', 'Bus_Get_Nodes_GR');
153+
result = obj.apiutil.get_int32_gr_array();
144154
end
145155

146156
function result = get.NumNodes(obj)
@@ -155,7 +165,8 @@
155165

156166
function result = get.SeqVoltages(obj)
157167
% (read-only) Double Array of sequence voltages at this bus.
158-
result = DSS_MATLAB.get_float64_array('Bus_Get_SeqVoltages');
168+
calllib('dss_capi_v7', 'Bus_Get_SeqVoltages_GR');
169+
result = obj.apiutil.get_float64_gr_array();
159170
end
160171

161172
function result = get.TotalMiles(obj)
@@ -165,42 +176,50 @@
165176

166177
function result = get.VLL(obj)
167178
% (read-only) For 2- and 3-phase buses, returns array of complex numbers represetin L-L voltages in volts. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only first 3.
168-
result = DSS_MATLAB.get_float64_array('Bus_Get_VLL');
179+
calllib('dss_capi_v7', 'Bus_Get_VLL_GR');
180+
result = obj.apiutil.get_float64_gr_array();
169181
end
170182

171183
function result = get.VMagAngle(obj)
172184
% (read-only) Variant Array of doubles containing voltages in Magnitude (VLN), angle (deg)
173-
result = DSS_MATLAB.get_float64_array('Bus_Get_VMagAngle');
185+
calllib('dss_capi_v7', 'Bus_Get_VMagAngle_GR');
186+
result = obj.apiutil.get_float64_gr_array();
174187
end
175188

176189
function result = get.Voc(obj)
177190
% (read-only) Open circuit voltage; Complex array.
178-
result = DSS_MATLAB.get_float64_array('Bus_Get_Voc');
191+
calllib('dss_capi_v7', 'Bus_Get_Voc_GR');
192+
result = obj.apiutil.get_float64_gr_array();
179193
end
180194

181195
function result = get.Voltages(obj)
182196
% (read-only) Complex array of voltages at this bus.
183-
result = DSS_MATLAB.get_float64_array('Bus_Get_Voltages');
197+
calllib('dss_capi_v7', 'Bus_Get_Voltages_GR');
198+
result = obj.apiutil.get_float64_gr_array();
184199
end
185200

186201
function result = get.YscMatrix(obj)
187202
% (read-only) Complex array of Ysc matrix at bus. Column by column.
188-
result = DSS_MATLAB.get_float64_array('Bus_Get_YscMatrix');
203+
calllib('dss_capi_v7', 'Bus_Get_YscMatrix_GR');
204+
result = obj.apiutil.get_float64_gr_array();
189205
end
190206

191207
function result = get.Zsc0(obj)
192208
% (read-only) Complex Zero-Sequence short circuit impedance at bus.
193-
result = DSS_MATLAB.get_float64_array('Bus_Get_Zsc0');
209+
calllib('dss_capi_v7', 'Bus_Get_Zsc0_GR');
210+
result = obj.apiutil.get_float64_gr_array();
194211
end
195212

196213
function result = get.Zsc1(obj)
197214
% (read-only) Complex Positive-Sequence short circuit impedance at bus..
198-
result = DSS_MATLAB.get_float64_array('Bus_Get_Zsc1');
215+
calllib('dss_capi_v7', 'Bus_Get_Zsc1_GR');
216+
result = obj.apiutil.get_float64_gr_array();
199217
end
200218

201219
function result = get.ZscMatrix(obj)
202220
% (read-only) Complex array of Zsc matrix at bus. Column by column.
203-
result = DSS_MATLAB.get_float64_array('Bus_Get_ZscMatrix');
221+
calllib('dss_capi_v7', 'Bus_Get_ZscMatrix_GR');
222+
result = obj.apiutil.get_float64_gr_array();
204223
end
205224

206225
function result = get.kVBase(obj)
@@ -210,17 +229,20 @@
210229

211230
function result = get.puVLL(obj)
212231
% (read-only) Returns Complex array of pu L-L voltages for 2- and 3-phase buses. Returns -1.0 for 1-phase bus. If more than 3 phases, returns only 3 phases.
213-
result = DSS_MATLAB.get_float64_array('Bus_Get_puVLL');
232+
calllib('dss_capi_v7', 'Bus_Get_puVLL_GR');
233+
result = obj.apiutil.get_float64_gr_array();
214234
end
215235

216236
function result = get.puVmagAngle(obj)
217237
% (read-only) Array of doubles containig voltage magnitude, angle pairs in per unit
218-
result = DSS_MATLAB.get_float64_array('Bus_Get_puVmagAngle');
238+
calllib('dss_capi_v7', 'Bus_Get_puVmagAngle_GR');
239+
result = obj.apiutil.get_float64_gr_array();
219240
end
220241

221242
function result = get.puVoltages(obj)
222243
% (read-only) Complex Array of pu voltages at the bus.
223-
result = DSS_MATLAB.get_float64_array('Bus_Get_puVoltages');
244+
calllib('dss_capi_v7', 'Bus_Get_puVoltages_GR');
245+
result = obj.apiutil.get_float64_gr_array();
224246
end
225247

226248
function result = get.x(obj)

+DSS_MATLAB/ICNData.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
% Name - Get/sets the name of the current active CNData
99
% Next - Sets next CNData active; returns 0 if no more.
1010
% idx - Sets next CNData active; returns 0 if no more.
11-
% Conductors - (read-only) Array of strings with names of all conductors in the active CNData object
1211
% EmergAmps - Emergency ampere rating
1312
% NormAmps - Normal Ampere rating
1413
% Rdc -
@@ -28,14 +27,17 @@
2827
% GmrStrand -
2928
% RStrand -
3029

30+
properties (Access = protected)
31+
apiutil
32+
end
33+
3134
properties
3235
AllNames
3336
Count
3437
First
3538
Name
3639
Next
3740
idx
38-
Conductors
3941
EmergAmps
4042
NormAmps
4143
Rdc
@@ -57,6 +59,9 @@
5759
end
5860

5961
methods (Access = public)
62+
function obj = ICNData(apiutil)
63+
obj.apiutil = apiutil;
64+
end
6065

6166
end
6267
methods
@@ -99,12 +104,6 @@
99104
obj.CheckForError();
100105
end
101106

102-
103-
function result = get.Conductors(obj)
104-
% (read-only) Array of strings with names of all conductors in the active CNData object
105-
result = DSS_MATLAB.get_string_array('CNData_Get_Conductors');
106-
end
107-
108107
function result = get.EmergAmps(obj)
109108
% Emergency ampere rating
110109
result = calllib('dss_capi_v7', 'CNData_Get_EmergAmps');

0 commit comments

Comments
 (0)