Menu

COM Interfacing With MATLAB: Extracting Element Properties

Beginners
Dennis
2015-07-29
2015-11-29
  • Dennis

    Dennis - 2015-07-29

    Hello All,

    I am relatively new in COM interfacing with MATLAB and I wanted to know if there was an "elegant" way of extracting all element properties in the active circuit without using DSSText.Command. In other words, is there a single line of code I can type in MATLAB using the COM objects available? If not, I I would assume I would have to loop through each individual element and then extract the properties.

    Thanks.

     
  • Davis Montenegro

    Hi,

    Yes, there is an instruction in MATLAB to explore all the properties and methods available for the existing clases of an Object (in this case OpenDSS). Try the following script:

    Obj = actxserver('OpenDSSEngine.DSS');
    get(Obj)
    inspect(Obj)
    methodsview(Obj)

    This will display all the methods and properties within OpenDSS.

    Best regards

    Davis

     
  • Dennis

    Dennis - 2015-07-29

    Davis,

    What I get is very much like the object browser for the OpenDSS engine in VBA and it provided more insight on how I can utilize the objects available with MATLAB. However, I'm finding myself building my own circuit element specifications table with a while loop, rather than assigning all the properties of the circuit element of interest with a single line of code.

    For example, I want to grab all the transformer properties defined in the system

    Ideally, here's what I would have to type as pseudocode

    DSSCircuit.Transformers.AllProperties ! all the Transformers properties
    

    What I'm actually doing:

    transformer=DSSCircuit.Transformers;
    transCount=transformer.First;
    x=[];
    while transCount>0
       x=[x [{transformer.Name};transformer.kV; transformer.kva ... OTHER SPECS]]
       transCount=transformer.Next;
    end
    

    Is there a way I can do the pseudocode written above?

     
  • Davis Montenegro

    Hi,

    You can do also that by using the activecktelement reference,for example, consider the code that you proposed above:

    transformer=DSSCircuit.Transformers;
    ActiveElement=DSSCircuit.ActiveCktElement;
    transCount=transformer.First;
    properties=ActiveElement.AllPropertyNames;

    In this case, you will obtain the name of all the properties of the active element in a variant which must be transformed to an array of strings. Then you will be able to ask for each property using a for or while loop to sweep the array.

    I hope this helps

    Best regards

    Davis

     

    Last edit: Davis Montenegro 2015-07-30
  • Davis Montenegro

    You can also try with the following properties for the ActiveCktElement class:

    ActiveElement.AllVariableNames
    ActiveElement.AllVariableValues

    Best regards

    Davis

     
  • Roger Dugan

    Roger Dugan - 2015-07-30

    Unfortunately, that only applies to PCelements and "Variable" refers to whatever state variables the programmer chose to expose.

    You can do as Davis said in his previous post and loop through the properties for each circuit element. I'm not sure what you are using this for, but when I did this for EPRI's DG Screener program I needed to do it to populate edit boxes on a form. I simply did it with a series of text commands. Here is the actual code (in Delphi) from one of these routines:

      QueryBase := '? ' + Caption ; // regctrl name is in the caption
      With DSSExecutive Do Begin
          Command := 'Select ' + Caption;  // set it active
          With  DSSCircuit.ActiveCktElement Do
            Begin
              If Numphases=1 Then SinglePhase := True Else SinglePhase := False;
              If Enabled Then  CheckBox1.Checked := True Else Checkbox1.Checked := False;
            End;
          Command := QueryBase + '.vreg';      E_SetVoltage.Text := GlobalResult;
          Command := QueryBase + '.band';      E_Bandwidth.Text := GlobalResult;
          Command := QueryBase + '.ptratio';   E_PTRatio.Text := GlobalResult;
          Command := QueryBase + '.delay';     E_Delay.Text := GlobalResult;
          Command := QueryBase + '.TapDelay';  E_TapDelay.Text := GlobalResult;
          Command := QueryBase + '.R';         E_LDC_R.Text := GlobalResult;
          Command := QueryBase + '.X';         E_LDC_X.Text := GlobalResult;
          Command := QueryBase + '.CTPRIM';    E_LDC_CT.Text := GlobalResult;
      End;
    

    So it uses the query command, "?", and constructs a command from the device name and the property name. Then it picks up the result and puts it in the property text box. "GlobalResult" is a function that calls the Result property of the Text interface.

     
  • Dennis

    Dennis - 2015-07-31

    Thank you for the input/suggestions. I'm extract all the element properties just fine until I try to extract bus voltages.

    For reference purposes I am using the EPRI Test Circuit ckt 5.

    First, I solve the circuit. Then, I extract the bus names.

      BusNames=DSSCircuit.AllBusNames;
    

    BusNames is a 2998 x1 cell

    Finally, I extract the bus voltage magnitudes

    BusVMag=DSSCircuit.AllBusVmag;
    

    BusVMag is a vector, 1 x 3437

    I expected BusVMag to be the same size as BusNames because each bus is unqiue, therefore having equal dimensions as BusVMag. Why is it that there are 439 additional voltages in BusVMag? I am assuming the discrepancy is due to the nodes per individual bus.

    If that is the case, do I assume the first 3 voltages of a 3 node bus are respectively, nodes 1, nodes 2, and nodes 3?

     

    Last edit: Dennis 2015-07-31
  • Davis Montenegro

    Hi,

    What you are getting are the voltages in all the nodes, so, to get the names of the nodes use the property AllNodeNames instead of AllBusNames. This way the number of elements is going to match. Remember, a bus can have several nodes.

    Best regards

    Davis

     
  • Shiva

    Shiva - 2015-11-25

    Hi,

    I want to extract the losses incur in the transformer and I wrote a snippet below.

    transformer=DSSCircuit.Transformers;
    ActiveElement=DSSCircuit.ActiveCktElement;
    transCount=transformer.First;
    properties=ActiveElement.AllPropertyNames;

    From here how to get the % loadlosses of the transformer?

    Thanks

     
  • Roger Dugan

    Roger Dugan - 2015-11-25

    Here's what I would do, using your notation:

    transformer=DSSCircuit.Transformers;
    ActiveElement=DSSCircuit.ActiveCktElement;
    transCount=transformer.First;
    MyTranLossesArray = ActiveElement.Losses;
    
    kW = MyTranLossesArray(1);
    kvar = MyTranLossesArray(2);
    
     
  • Shiva

    Shiva - 2015-11-25

    Thansk Mr. Roger!

    I tried to get the looses value of watt and vars for two condition.

    1. with XHL =10% and %Rs=[0.4, 0.4] or %loadloss = 0.8 ( % noloadloss = 0)
    2. with XHL =10% and %loadloss = 0 ( % noloadloss = 0)

    In both conditions the var values are same but the watt values are different. Watt value is significant for condition 1 and insignificant for condition 2.

    Now the question is how do I vailid such results??

    Thanks

     
  • Roger Dugan

    Roger Dugan - 2015-11-26

    It makes sense to me.

    This is a simple enough problem that you can confirm the losses by hand calculations. Take the currents openDSS computes and compute the active and reactive power losses by hand or better yet use a spreadsheet.

     
  • Shiva

    Shiva - 2015-11-26

    Thanks Roger!

    Basically I used the below snippet to compute the total line losses but I am interested in computing a single line.

        LineLosses = DSSCircuit.LineLosses;
        Losses1= reshape(LineLosses,2,[]);
        Line1(:,i)=Losses1; 
        LineLosses = Line1'
    

    Could you please check whether the snippet below in getting the line losses is appropriate for a single line and if yes how do I compute the next line?

        line=DSSCircuit.Lines;
        ActiveElement=DSSCircuit.ActiveCktElement;
        LineCount=line.First;
        MyLineLossesArray = ActiveElement.Losses;
        P(i) = MyLineLossesArray(1);
        W = P';
        Q(i) = MyLineLossesArray(2);
        Va = Q';
    

    Thanks!

     

    Last edit: Shiva 2015-11-26
  • Roger Dugan

    Roger Dugan - 2015-11-28

    Using your notation:

    LineCount=line.First;
    While LineCount > 0
    MyLineLossesArray = ActiveElement.Losses;
    P(i) = MyLineLossesArray(1);
    W = P';
    Q(i) = MyLineLossesArray(2);
    Va = Q';
    ...
       Do something with W and Va
       ...
    LineCount=line.Next;
    End
    
     
  • Shiva

    Shiva - 2015-11-29

    Thanks Roger it works and now I am able to find the losses in each line and is consistent with the hand calculation.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.