modelicaconnectoropenmodelicadymolaexpandable

Connecting vector of an expandable connector in Dymola and OpenModelica


I'm trying to connect a vector of connector to a vector of expandable connector. Here is the sample code to reproduce the issues. I explore 3 ways to do the connections, through blocks Adapter One to Three.

  1. First one connects the vectors of variables, works fine under Dymola, fails under OME (AdapterOne failed with no error message)
  2. Second one connects manually each element of each vector, works fine.
  3. Third one connects with a loop each element of each vector, check fails under Dymola (Failed to expand connect) and OME (Error: Internal error NFSubscript.toDAE failed on unknown subscript 1).

What am I doing wrong ?

Tested with OME v1.23.1 (64bits) and Dymola 2024 refresh1 (windows 64bits)

package Test
  expandable connector Bus
  end Bus;

  connector IntegerOutput = output Integer;

  block Source
    IntegerOutput y=1;
  end Source;

  block AdapterOne
    parameter Integer numberOfItems = 2;
    Bus engineBus[numberOfItems];
    Source source[numberOfItems](each y=3);
  equation 
  connect(source.y, engineBus.value);
  end AdapterOne;

  block AdapterTwo
    parameter Integer numberOfItems = 2;
    Bus engineBus[numberOfItems];
    Source source[numberOfItems](each y=3);
  equation 
      connect(source[1].y, engineBus[1].level);
      connect(source[2].y, engineBus[2].level);
  end AdapterTwo;

  model AdapterThree
    parameter Integer numberOfItems = 2;
    Bus engineBus[numberOfItems];
    Source source[numberOfItems](each y=3);
  equation 
    for i in 1:numberOfItems loop
        connect(source[i].y, engineBus[i].level);
    end for;
  end AdapterThree;

end Test;


Solution

  • The code is correct (unless I missed something), and all cases will work in the next release of Dymola. A work-around for Dymola is to use the following:

    block AdapterTwoAndHalf
      parameter Integer numberOfItems = 2;
      Bus engineBus[numberOfItems];
      Source source[numberOfItems](each y=3);
    equation 
      connect(source[1:numberOfItems].y, engineBus[1:numberOfItems].level);
    end AdapterTwoAndHalf;