Skip to content

Commit

Permalink
Fix missing calllib arguments in: Monitors.Channel, `Monitors.AsM…
Browse files Browse the repository at this point in the history
…atrix`, `Monitors.dblFreq`, `Monitors.dblHour`, `ActiveCktElement.Properties`

`Monitors.AsMatrix` also had a separate issue. Example updated to test the affected functions.

Closes #20
  • Loading branch information
PMeira committed Oct 30, 2024
1 parent 9dc0159 commit 78d8137
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
4 changes: 2 additions & 2 deletions +DSS_MATLAB/ICktElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@

function result = Properties(obj, NameOrIdx)
if ischar(NameOrIdx) || isstring(NameOrIdx)
calllib('dss_capi', 'ctx_DSSProperty_Set_Name', obj.dssctx, NameOrIdx);
calllib(obj.libname, 'ctx_DSSProperty_Set_Name', obj.dssctx, NameOrIdx);
elseif isinteger(NameOrIdx)
calllib('dss_capi', 'ctx_DSSProperty_Set_Index', obj.dssctx, NameOrIdx);
calllib(obj.libname, 'ctx_DSSProperty_Set_Index', obj.dssctx, NameOrIdx);
else
ME = MException(['DSS_MATLAB:Error'], 'Expected char, string or integer');
throw(ME);
Expand Down
10 changes: 5 additions & 5 deletions +DSS_MATLAB/IMonitors.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@
result = 0;
return
end
calllib('ctx_Monitors_Get_Channel_GR', obj.dssctx, Index);
calllib(obj.libname, 'ctx_Monitors_Get_Channel_GR', obj.dssctx, Index);
obj.CheckForError();
result = obj.apiutil.get_float64_gr_array();
end

function result = AsMatrix(obj)
% Matrix of the active monitor, containing the hour vector, seconds vector, and all channels (index 3 = channel 1)
calllib('ctx_Monitors_Get_ByteStream_GR', obj.dssctx);
calllib(obj.libname, 'ctx_Monitors_Get_ByteStream_GR', obj.dssctx);
obj.CheckForError();
buffer = obj.apiutil.get_int8_gr_array();
if (numel(buffer) <= 1)
Expand All @@ -80,7 +80,7 @@
record_size = typecast(buffer, 'int32');
record_size = record_size(3) + 2;
data = typecast(buffer(273:end), 'single');
data = reshape(data, [int32(data.size() / record_size), record_size]);
data = reshape(data, [record_size, size(data, 2) / record_size]);
result = data;
end

Expand Down Expand Up @@ -227,14 +227,14 @@

function result = get.dblFreq(obj)
% (read-only) Array of doubles containing frequency values for harmonics mode solutions; Empty for time mode solutions (use dblHour)
calllib('ctx_Monitors_Get_dblFreq_GR', obj.dssctx);
calllib(obj.libname, 'ctx_Monitors_Get_dblFreq_GR', obj.dssctx);
obj.CheckForError();
result = obj.apiutil.get_float64_gr_array();
end

function result = get.dblHour(obj)
% (read-only) Array of doubles containgin time value in hours for time-sampled monitor values; Empty if frequency-sampled values for harmonics solution (see dblFreq)
calllib('ctx_Monitors_Get_dblHour_GR', obj.dssctx);
calllib(obj.libname, 'ctx_Monitors_Get_dblHour_GR', obj.dssctx);
obj.CheckForError();
result = obj.apiutil.get_float64_gr_array();
end
Expand Down
Binary file modified examples/13Bus.zip
Binary file not shown.
43 changes: 40 additions & 3 deletions examples/13Bus/run.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
Solution = DSS.ActiveCircuit.Solution;
Bus = DSS.ActiveCircuit.ActiveBus;
Load = DSS.ActiveCircuit.Loads;
Monitors = DSS.ActiveCircuit.Monitors;
CE = DSS.ActiveCircuit.ActiveCktElement;

% You can get some very basic description of the properties for most of the
% objects:
Expand Down Expand Up @@ -115,20 +117,55 @@
ylabel('Bus Y coordinate');
ylabel(handle, 'Voltage (pu)');

%% Monitors, including the AsMatrix function (API extension)

% Let's edit the circuit to add some variation, add a monitor, and solve
Text.Command = 'BatchEdit Load..* Daily=default';
Text.Command = 'New Monitor.test Element=Transformer.Sub Mode=1';
Solution.Mode = int32(DSS_MATLAB.SolveModes.Daily);
Solution.Solve();

% Now plot the first channel of the monitor
figure;
Monitors.Name = 'test';
plot(Monitors.dblHour, Monitors.Channel(1));
Monitors.dblHour
xlabel('Time (h)');
header = Monitors.Header();
ylabel(header(1));

% We can also get all data as a matrix; the first two columns are the
% integer hours and seconds (for a time solution)
figure;
mon_mat = Monitors.AsMatrix();
h = mon_mat(1, :) + mon_mat(2, :) / 3600;
plot(h, mon_mat(3:end, :));
xlabel('Time (h)');
legend(header);

%% Raw DSS properties

% Although the Text interface can be convenient to read properties not
% exposed by the API, OpenDSS also provides a dedicated Properties API
% that can be useful for elements that don't have dedicated APIs.
Circuit.SetActiveElement('Transformer.Sub')
Prop = CE.Properties('Windings');
fprintf('Property Name: %s, Value: %s', Prop.Name, Prop.Val);

%% Loading circuits from ZIP files (API extension, not available in the official OpenDSS)

DSS.ClearAll();
ZIP = DSS.ZIP;
ZIP.Open('../13Bus.zip')
ZIP.Open('../13Bus.zip');

ZIP.List()

% Running the DSS script directly from the ZIP.
% This also restricts loading most files only from the ZIP archive,
% so you have to use relative paths.
ZIP.Redirect('13Bus/IEEE13Nodeckt.dss')
ZIP.Redirect('13Bus/IEEE13Nodeckt.dss');

ZIP.Close()
ZIP.Close();

DSS.ActiveCircuit.NumBuses

Expand Down

0 comments on commit 78d8137

Please sign in to comment.