diff --git a/+DSS_MATLAB/ICktElement.m b/+DSS_MATLAB/ICktElement.m index 79d7092..7da0b49 100644 --- a/+DSS_MATLAB/ICktElement.m +++ b/+DSS_MATLAB/ICktElement.m @@ -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); diff --git a/+DSS_MATLAB/IMonitors.m b/+DSS_MATLAB/IMonitors.m index 1ca3619..2de916a 100644 --- a/+DSS_MATLAB/IMonitors.m +++ b/+DSS_MATLAB/IMonitors.m @@ -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) @@ -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 @@ -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 diff --git a/examples/13Bus.zip b/examples/13Bus.zip index 9cd28f3..13b011b 100644 Binary files a/examples/13Bus.zip and b/examples/13Bus.zip differ diff --git a/examples/13Bus/run.m b/examples/13Bus/run.m index 18885e0..da0eabf 100644 --- a/examples/13Bus/run.m +++ b/examples/13Bus/run.m @@ -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: @@ -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