2

Using unspecified array dimensions (:) is an essential feature to design flexible components for reuse. I am well aware that the actual dimension has to be fixed when the model is compiled. To my knowledge binding a variable with unspecified array dimensions to one that has clearly defined dimensions should suffice.

So I am a bit confused why the following model Test will not validate in either OpenModelica or the Wolfram System Modeler:

package VectorFunctions

  model Test
      VectorSum converter "Component taking the sum of a vector input";
      InformationSource source "Vector input";
    equation
      connect( source.y, converter.u );
  end Test;

  block VectorSum "Take the sum of an input with unspecified dimension"
      Modelica.Blocks.Interfaces.RealInput u[:];
      Modelica.Blocks.Interfaces.RealOutput y;
    equation
      y = sum(u);
  end VectorSum;

  block InformationSource "Provide some vector output"
      Modelica.Blocks.Interfaces.RealOutput y[3];
    equation
      y = ones( 3 );
  end InformationSource;

end VectorFunctions;

How can something like this be done then?

gwr
  • 465
  • 6
  • 17
  • Note, that I cross-posted a similiar question on [Wolfram Community](https://community.wolfram.com/groups/-/m/t/1706682). – gwr Jun 18 '19 at 14:14
  • I updated my code to provide `connectors` for a clean `connect` statement. – gwr Jun 18 '19 at 16:10

2 Answers2

1

My guess would be that the Modelica Spec does not specify, that vector sizes can be automatically detected from connections, so the tools don't support that.

I think you have to set the vector size somehow by yourself, e.g. with a parameter which is set in your Test model as follows:

  model Test
      VectorSum converter(nu=size(source.y, 1)) "Pass in the vector size";
      InformationSource source "Vector input";
  equation 
      connect(source.y, converter.u);
  end Test;

  block VectorSum "Take the sum of an input with unspecified dimension"
      Modelica.Blocks.Interfaces.RealInput u[nu];
      parameter Integer nu(min=0)=0;
      output Real y;
  equation 
      y = sum(u);
  end VectorSum;

Note that Dymola complains in your example code that connect statements can only be applied to connectors. Therefore I changed input Real to Modelica.Blocks.Interfaces.RealInput(and similar in InformationSource)

marco
  • 5,944
  • 10
  • 22
  • Actually the [Modelica specs](https://www.modelica.org/documents/ModelicaSpec33.pdf) in my opinion are not clear about this: *Section 10.2 Flexible Array Sizes* simply points at *Section 12.4.5* where this is discussed for `functions` (which allow the use as presented here for inputs). Since `blocks` share some familiarity with `functions` as is pointed out in the specs I am still not seeing a good reason why this should not work out. – gwr Jun 18 '19 at 16:07
1

I have been given (inofficial) feedback on Wolfram Community by someone from Wolfram MathCore (e.g. the developers of the System Modeler):

Hi, I agree with your interpretation, I think we should support it. I have filed a bug to keep track of this issue internally, unfortunately I do not see any work around. We will come back to you when we have fixed this problem.

So, hopefully flexbile array sizes will be supported for blocks as they are for functions.

gwr
  • 465
  • 6
  • 17