1

The following package 'RecordTest' (example to reproduce an error of a bigger model) contains a Record to define the structure of some data. Further in package 'DataDefintion' two sets of data are defined. Finally this data should be used in package 'UseOfData'. Herein the data sets are read and the sum of all arrays A is evaluated in the function 'FunctionWithData'.

The simulation of model 'FunctionCall' works fine in OpenModelica. In Dymola I get the error: 'For variable package constant RecordTest.UseOfData.ReadData[1].A the subscript RecordTest.UseOfData.ReadData.Index of an array variable is not an integer.'

Do I miss anything? The constant 'Index' is defined as an integer in record 'DataStructure'. Further the model runs in OpenModelica. I don't understand the error of Dymola.

Thanks in advance.

package RecordTest

record DataStructure
  constant Integer Index;
  Real A[Index];
end DataStructure;

package DataDefinition
  constant DataStructure Set1(Index=2, A={1,2});
  constant DataStructure Set2(Index=2, A={3,4});
end DataDefinition;

package UseOfData
  constant Integer N=2;
  constant DataStructure ReadData[N]={DataDefinition.Set1, DataDefinition.Set2};

  function FunctionWithData
    input Real b;
    output Real Result;
  protected
    Real Array[2];
  algorithm
    Array := {sum(ReadData[1].A), sum(ReadData[2].A)};
    Result := b*sum(Array);
  end FunctionWithData;

  model FunctionCall
    parameter Real b=2;
    Real FunctionResult;
  equation
    FunctionResult = FunctionWithData(b);
  end FunctionCall;
end UseOfData;

end RecordTest;
Florian
  • 55
  • 5

1 Answers1

0

A work-around is to rewrite the package as follows:

package RecordTest

record DataStructure
  constant Integer Index;
  Real A[:];
end DataStructure;

package DataDefinition
  constant DataStructure Set1=DataStructure(Index=2, A={1.0,2.0});
  constant DataStructure Set2=DataStructure(Index=2, A={3.0,4.0});
end DataDefinition;

package UseOfData
  constant Integer N=2;
  constant DataStructure ReadData[N]={DataDefinition.Set1, DataDefinition.Set2};

  function FunctionWithData
    input Real b;
    output Real Result;
    protected 
    Real Array[2];
  algorithm 
    Array := {sum(ReadData[1].A), sum(ReadData[2].A)};
    Result := b*sum(Array);
  end FunctionWithData;

  model FunctionCall
    parameter Real b=2;
    Real FunctionResult;
  equation 
    FunctionResult = FunctionWithData(b);
  end FunctionCall;
end UseOfData;

end RecordTest;

The issues are the "Index" used in A inside a package-constant array of records, and the modifiers instead of binding equation for the package-constant records Set1 and Set2. (It will also be handled in a future version of Dymola, and I understand the answer is a bit late.)

Hans Olsson
  • 11,123
  • 15
  • 38